From: Michael Tremer Date: Tue, 16 Aug 2022 15:35:23 +0000 (+0000) Subject: build: Move ccache setup here X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5a06668c439ecbd4aa746d375b1c7403ca8b20f7;p=people%2Fstevee%2Fpakfire.git build: Move ccache setup here Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/pakfire.c b/src/_pakfire/pakfire.c index a7151290..22eda846 100644 --- a/src/_pakfire/pakfire.c +++ b/src/_pakfire/pakfire.c @@ -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); diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 4e5f2eba..a1a1d461 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -41,6 +41,8 @@ #include #include +#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; diff --git a/src/libpakfire/include/pakfire/build.h b/src/libpakfire/include/pakfire/build.h index 3b1c9684..55ef5bdc 100644 --- a/src/libpakfire/include/pakfire/build.h +++ b/src/libpakfire/include/pakfire/build.h @@ -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, diff --git a/src/libpakfire/include/pakfire/pakfire.h b/src/libpakfire/include/pakfire/pakfire.h index 5c3433bc..de3d403a 100644 --- a/src/libpakfire/include/pakfire/pakfire.h +++ b/src/libpakfire/include/pakfire/pakfire.h @@ -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 diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 743cb457..8151a0bc 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -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; diff --git a/src/pakfire/daemon.py b/src/pakfire/daemon.py index 961ccd94..9cc1bc6e 100644 --- a/src/pakfire/daemon.py +++ b/src/pakfire/daemon.py @@ -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)