]> git.ipfire.org Git - pakfire.git/commitdiff
builder: Add function to bind-mount ccache
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 21 Mar 2021 13:44:56 +0000 (13:44 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 21 Mar 2021 13:44:56 +0000 (13:44 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/pakfire.c
src/libpakfire/include/pakfire/pakfire.h
src/libpakfire/libpakfire.sym
src/libpakfire/pakfire.c
src/pakfire/base.py
src/pakfire/builder.py

index 13b83a24c75e040d183df46fabc41491ae22c391..e00bc66c0e3a0e57976595bb42196bd6989515dd 100644 (file)
@@ -694,7 +694,29 @@ static int Pakfire_set_offline(PakfireObject* self, PyObject* value) {
        return 0;
 }
 
+static PyObject* Pakfire_bind(PakfireObject* self, PyObject* args) {
+       const char* src = NULL;
+       const char* dst = NULL;
+
+       if (!PyArg_ParseTuple(args, "s|z", &src, &dst))
+               return NULL;
+
+       int r = pakfire_bind(self->pakfire, src, dst, 0);
+       if (r) {
+               PyErr_SetFromErrno(PyExc_OSError);
+               return NULL;
+       }
+
+       Py_RETURN_NONE;
+}
+
 static struct PyMethodDef Pakfire_methods[] = {
+       {
+               "bind",
+               (PyCFunction)Pakfire_bind,
+               METH_VARARGS,
+               NULL,
+       },
        {
                "dist",
                (PyCFunction)Pakfire_dist,
index 4468ae9c43a79d3a8a7aeb533399bc0ca976e9bf..091135c16456c6359f30351b53f463466b0be637 100644 (file)
@@ -39,6 +39,7 @@ char* pakfire_make_path(Pakfire pakfire, const char* path);
 
 int pakfire_activate(Pakfire pakfire);
 int pakfire_deactivate(Pakfire pakfire);
+int pakfire_bind(Pakfire pakfire, const char* src, const char* dst, int flags);
 
 const char* pakfire_get_arch(Pakfire pakfire);
 
index ff5208f1f8420bdf89e09ae6a80757169767a1e9..3bbd4cca76e424fa1ddc9351f8046a29a5d971bc 100644 (file)
@@ -22,6 +22,7 @@ LIBPAKFIRE_0 {
 global:
        # pakfire
        pakfire_activate;
+       pakfire_bind;
        pakfire_count_packages;
        pakfire_create;
        pakfire_deactivate;
index 1fc0f31e313f411ad5ab0be8f823302034e91a43..98edd75f832b605d0bb7ef7ac996f52488b73d35 100644 (file)
@@ -303,6 +303,29 @@ PAKFIRE_EXPORT char* pakfire_make_path(Pakfire pakfire, const char* path) {
        return pakfire_path_join(pakfire->path, path);
 }
 
+PAKFIRE_EXPORT int pakfire_bind(Pakfire pakfire, const char* src, const char* dst, int flags) {
+       if (!dst)
+               dst = src;
+
+       char* mountpoint = pakfire_make_path(pakfire, dst);
+       if (!mountpoint)
+               return 1;
+
+       DEBUG(pakfire, "Mounting %s to %s\n", src, mountpoint);
+
+       // Make sure the directory exists
+       int r = pakfire_mkdir(pakfire, mountpoint, 0);
+       if (r)
+               goto ERROR;
+
+       // Perform mount
+       r = mount(src, mountpoint, NULL, flags|MS_BIND, NULL);
+
+ERROR:
+       free(mountpoint);
+       return r;
+}
+
 static const struct pakfire_mountpoint {
        const char* source;
        const char* target;
index 095aa11a2451fec6e9478b9f1df18c1c56dd12c0..435dfe5690143fc1d15d8f5bac46fee794814f32 100644 (file)
@@ -40,7 +40,7 @@ from .i18n import _
 class Pakfire(_pakfire.Pakfire):
        __version__ = PAKFIRE_VERSION
 
-       def __init__(self, path="/", config=None, arch=None, distro=None, offline=False):
+       def __init__(self, path=None, config=None, arch=None, distro=None, offline=False):
                _pakfire.Pakfire.__init__(self, path, arch, offline=offline)
 
                # Initialise logging system
index 114550b22dc01c9fb731720d28d85133ce6de880..711c57561fdebd5a2ed42d724cfb57ad148b30e2 100644 (file)
@@ -93,9 +93,6 @@ class Builder(object):
                # Setup logging
                self.log = self.setup_logging(logfile)
 
-               # Path
-               self.path = os.path.join(BUILD_ROOT, self.build_id)
-
                # Architecture to build for
                self.arch = arch or _pakfire.native_arch()
 
@@ -107,18 +104,15 @@ class Builder(object):
                self.cgroup = self._make_cgroup()
 
        def __enter__(self):
-               self.log.debug("Entering %s" % self.path)
-
-               # Mount the build environment
-               self._mount()
+               self.log.debug("Entering %s" % self)
 
                # Setup domain name resolution in chroot
-               self.setup_dns()
+               #self.setup_dns()
 
                return BuilderContext(self)
 
        def __exit__(self, type, value, traceback):
-               self.log.debug("Leaving %s" % self.path)
+               self.log.debug("Leaving %s" % self)
 
                # Kill all remaining processes in the build environment
                self.cgroup.killall()
@@ -127,12 +121,6 @@ class Builder(object):
                self.cgroup.destroy()
                self.cgroup = None
 
-               # Umount the build environment
-               self._umount()
-
-               # Delete everything
-               self._destroy()
-
        def setup_logging(self, logfile):
                l = log.getChild(self.build_id)
                l.setLevel(logging.DEBUG)
@@ -171,39 +159,6 @@ class Builder(object):
 
                return cgroup
 
-       def _destroy(self):
-               self.log.debug("Destroying environment %s" % self.path)
-
-               if os.path.exists(self.path):
-                       util.rm(self.path)
-
-       def _mount(self):
-               """
-                       Mounts the build environment
-               """
-               os.makedirs(self.path)
-
-               # Bind-mount the ccache if enabled
-               if self.settings.get("enable_ccache"):
-                       if not os.path.exists(CCACHE_CACHE_DIR):
-                               os.makedirs(CCACHE_CACHE_DIR)
-
-                       os.makedirs("%s/var/cache/ccache" % self.path)
-
-                       _pakfire.mount(CCACHE_CACHE_DIR, "%s/var/cache/ccache" % self.path,
-                               flags=_pakfire.MS_BIND)
-
-       def _umount(self):
-               """
-                       Umounts the build environment
-               """
-               mountpoints = (
-                       "%s/var/cache/ccache" % self.path,
-               )
-
-               for mp in mountpoints:
-                       _pakfire.umount(mp)
-
        def copyin(self, file_out, file_in):
                if file_in.startswith("/"):
                        file_in = file_in[1:]
@@ -272,12 +227,14 @@ class BuilderContext(object):
 
                # Initialise Pakfire instance
                self.pakfire = base.Pakfire(
-                       path=self.builder.path,
                        config=self.builder.config,
                        distro=self.builder.config.distro,
                        arch=self.builder.arch,
                )
 
+               # Mount ccache
+               self.pakfire.bind(CCACHE_CACHE_DIR, "/var/cache/ccache")
+
        @property
        def environ(self):
                # Build a minimal environment for executing, but try to inherit TERM and LANG