]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
build: Move ccache setup here
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 16 Aug 2022 15:35:23 +0000 (15:35 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 16 Aug 2022 15:35:23 +0000 (15:35 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/pakfire.c
src/libpakfire/build.c
src/libpakfire/include/pakfire/build.h
src/libpakfire/include/pakfire/pakfire.h
src/libpakfire/pakfire.c
src/pakfire/daemon.py

index a715129075663072769521f8862f5c16938eb926..22eda846eb7eeb39fa2552e044408f7e37b81c1e 100644 (file)
@@ -142,7 +142,6 @@ static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) {
                "offline",
                "conf",
                "build",
-               "disable_ccache",
                "confirm_callback",
                NULL,
        };
@@ -152,11 +151,10 @@ static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) {
        int interactive = 0;
        int offline = 0;
        int build = 0;
-       int disable_ccache = 1;
 
-       if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zzOppzppO", kwlist,
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zzOppzpO", kwlist,
                        &path, &arch, &self->callbacks.log, &interactive, &offline, &conf, &build,
-                       &disable_ccache, &self->callbacks.confirm))
+                       &self->callbacks.confirm))
                return -1;
 
        // Check if log callback is callable
@@ -182,13 +180,9 @@ static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) {
                flags |= PAKFIRE_FLAGS_OFFLINE;
 
        // Enable build mode
-       if (build) {
+       if (build)
                flags |= PAKFIRE_FLAGS_BUILD;
 
-               if (disable_ccache)
-                       flags |= PAKFIRE_FLAGS_DISABLE_CCACHE;
-       }
-
        // Configure callbacks
        if (self->callbacks.log)
                Py_INCREF(self->callbacks.log);
@@ -1104,15 +1098,17 @@ static PyObject* Pakfire_build(PakfireObject* self, PyObject* args, PyObject* kw
                "path",
                "build_id",
                "disable_snapshot",
+               "disable_ccache",
                NULL,
        };
 
        const char* path = NULL;
        const char* build_id = NULL;
        int disable_snapshot = 0;
+       int disable_ccache = 0;
 
-       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|zp", kwlist, &path, &build_id,
-                       &disable_snapshot))
+       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|zpp", kwlist, &path, &build_id,
+                       &disable_snapshot, &disable_ccache))
                return NULL;
 
        int flags = 0;
@@ -1121,6 +1117,10 @@ static PyObject* Pakfire_build(PakfireObject* self, PyObject* args, PyObject* kw
        if (disable_snapshot)
                flags |= PAKFIRE_BUILD_DISABLE_SNAPSHOT;
 
+       // Disable ccache if requested
+       if (disable_ccache)
+               flags |= PAKFIRE_BUILD_DISABLE_CCACHE;
+
        // Run build
        int r = pakfire_build(self->pakfire, path, NULL, build_id, flags);
 
index 4e5f2eba429ca6a9c3c99c5acd8f7542a785c243..a1a1d46162f072eeb9c469fd04967d522b104d50 100644 (file)
@@ -41,6 +41,8 @@
 #include <pakfire/snapshot.h>
 #include <pakfire/util.h>
 
+#define CCACHE_DIR "/var/cache/ccache"
+
 // We guarantee 2 GiB of memory to every build container
 #define PAKFIRE_BUILD_GUARANTEED_MEMORY                (size_t)2 * 1024 * 1024 * 1024
 
@@ -863,6 +865,45 @@ static int pakfire_build_setup_jail(struct pakfire_build* build) {
        return 0;
 }
 
+/*
+       Sets up the ccache for this build
+*/
+static int pakfire_build_setup_ccache(struct pakfire_build* build) {
+       char path[PATH_MAX];
+       int r;
+
+       // Check if we want a ccache
+       if (pakfire_build_has_flag(build, PAKFIRE_BUILD_DISABLE_CCACHE)) {
+               DEBUG(build->pakfire, "ccache usage has been disabled for this build\n");
+               return 0;
+       }
+
+       // Compose path
+       r = pakfire_make_cache_path(build->pakfire, path, "%s", "ccache");
+       if (r < 0) {
+               ERROR(build->pakfire, "Could not compose ccache path: %m\n");
+               return 1;
+       }
+
+       DEBUG(build->pakfire, "Mounting ccache from %s\n", path);
+
+       // Ensure path exists
+       r = pakfire_mkdir(path, 0755);
+       if (r && errno != EEXIST) {
+               ERROR(build->pakfire, "Could not create ccache directory %s: %m\n", path);
+               return r;
+       }
+
+       // Bind-mount the directory
+       r = pakfire_jail_bind(build->jail, path, CCACHE_DIR, MS_NOSUID|MS_NOEXEC|MS_NODEV);
+       if (r) {
+               ERROR(build->pakfire, "Could not mount ccache: %m\n");
+               return r;
+       }
+
+       return 0;
+}
+
 PAKFIRE_EXPORT int pakfire_build_create(struct pakfire_build** build,
                struct pakfire* pakfire, const char* id, int flags) {
        int r;
@@ -901,6 +942,11 @@ PAKFIRE_EXPORT int pakfire_build_create(struct pakfire_build** build,
        if (r)
                goto ERROR;
 
+       // Setup ccache
+       r = pakfire_build_setup_ccache(b);
+       if (r)
+               goto ERROR;
+
        *build = b;
        return 0;
 
index 3b1c96844b0ba959c4a146f761cb8c48ec14f389..55ef5bdc6fcc20e1ca9840e5f1bbdff36a3c28c4 100644 (file)
@@ -27,6 +27,7 @@ struct pakfire_build;
 
 enum pakfire_build_flags {
        PAKFIRE_BUILD_DISABLE_SNAPSHOT = (1 << 0),
+       PAKFIRE_BUILD_DISABLE_CCACHE   = (1 << 1),
 };
 
 int pakfire_build_create(struct pakfire_build** build,
index 5c3433bc6d752b956bdb779f3bc5a341feb5ab88..de3d403ac772f4e0ec4bdab51e512744c9e72126 100644 (file)
@@ -46,7 +46,6 @@ enum pakfire_flags {
        PAKFIRE_FLAGS_INTERACTIVE               = (1 << 0),
        PAKFIRE_FLAGS_OFFLINE                   = (1 << 1),
        PAKFIRE_FLAGS_BUILD                             = (1 << 2),
-       PAKFIRE_FLAGS_DISABLE_CCACHE    = (1 << 3),
 };
 
 // Callbacks
index 743cb45708ce434baf75aadbf1c570da48b9178e..8151a0bc6204766f84b96e42a7dc46a0d9607567 100644 (file)
@@ -62,7 +62,6 @@
 
 #define KEYSTORE_DIR "/etc/pakfire/trusted.keys.d"
 #define LOCK_PATH PAKFIRE_PRIVATE_DIR "/.lock"
-#define CCACHE_DIR "/var/cache/ccache"
 
 struct pakfire {
        int nrefs;
@@ -1942,29 +1941,6 @@ int pakfire_build_setup(struct pakfire* pakfire) {
        if (pakfire->build_setup)
                return 0;
 
-       char path[PATH_MAX];
-       int r;
-
-       // Mount ccache
-       if (!pakfire_has_flag(pakfire, PAKFIRE_FLAGS_DISABLE_CCACHE)) {
-               r = pakfire_make_cache_path(pakfire, path, "%s", "ccache");
-               if (r < 0)
-                       return r;
-
-               // Ensure path exists
-               r = pakfire_mkdir(path, 0755);
-               if (r && errno != EEXIST) {
-                       ERROR(pakfire, "Could not create ccache directory %s: %m\n", path);
-                       return r;
-               }
-
-               r = pakfire_bind(pakfire, path, CCACHE_DIR, MS_NOSUID|MS_NOEXEC|MS_NODEV);
-               if (r) {
-                       ERROR(pakfire, "Could not mount ccache: %m\n");
-                       return r;
-               }
-       }
-
        // Build setup done
        pakfire->build_setup = 1;
 
index 961ccd94454ab928442389fc51bc60de50ea6c52..9cc1bc6e594439671ff0dd22a18d6392ca76ee86 100644 (file)
@@ -281,7 +281,8 @@ class Worker(multiprocessing.Process):
                        os.unlink(self.pakfire_conf)
 
                # Run the build in a new thread
-               thread = asyncio.to_thread(p.build, pkg, disable_snapshot=True, **kwargs)
+               thread = asyncio.to_thread(p.build, pkg,
+                       disable_ccache=True, disable_snapshot=True, **kwargs)
 
                # Return a task
                return asyncio.create_task(thread)