]> git.ipfire.org Git - pakfire.git/commitdiff
build: Avoid having to steps when not using the snapshot
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 28 Apr 2023 13:09:11 +0000 (13:09 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 28 Apr 2023 13:09:11 +0000 (13:09 +0000)
The build environment can be cached in a snapshot which allows much
faster builds. But sometimes, we don't want to use the snapshot.

In those cases, we will install the default set of packages first and
then we will install the source package. In order to find any dependency
problems quicker, this is now being done in just one step.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c

index 40464569ab3d4161d200e795ca0e3177cda5ca2d..dfa50e7d94935860d966ea9a6a966363a63b23c4 100644 (file)
 // We allow only up to 2048 processes/threads for every build container
 #define PAKFIRE_BUILD_PID_LIMIT                                (size_t)2048
 
+// A list of packages that is installed by default
+static const char* PAKFIRE_BUILD_PACKAGES[] = {
+       "build-essential",
+       NULL,
+};
+
 struct pakfire_build {
        struct pakfire* pakfire;
        int nrefs;
@@ -1622,15 +1628,10 @@ static int pakfire_build_install_packages(struct pakfire_build* build,
                int* snapshot_needs_update) {
        int r;
 
-       const char* packages[] = {
-               "build-essential",
-               NULL,
-       };
-
        int changed = 0;
 
        // Install everything
-       r = pakfire_install(build->pakfire, 0, 0, packages, NULL, 0,
+       r = pakfire_install(build->pakfire, 0, 0, PAKFIRE_BUILD_PACKAGES, NULL, 0,
                &changed, NULL, NULL);
        if (r) {
                ERROR(build->pakfire, "Could not install build dependencies: %m\n");
@@ -1658,7 +1659,7 @@ static int pakfire_build_install_packages(struct pakfire_build* build,
 /*
        Initializes the build environment
 */
-static int pakfire_build_init(struct pakfire_build* build) {
+static int pakfire_build_setup_snapshot(struct pakfire_build* build) {
        int r;
 
        // Don't do it again
@@ -1667,15 +1668,17 @@ static int pakfire_build_init(struct pakfire_build* build) {
                return 0;
        }
 
+       // Nothing to do if we don't use the snapshot
+       if (pakfire_build_has_flag(build, PAKFIRE_BUILD_DISABLE_SNAPSHOT))
+               return 0;
+
        // Tells us whether we need to (re-)create the snapshot
        int snapshot_needs_update = 0;
 
        // Extract snapshot
-       if (!pakfire_build_has_flag(build, PAKFIRE_BUILD_DISABLE_SNAPSHOT)) {
-               r = pakfire_snapshot_restore(build->pakfire);
-               if (r)
-                       return r;
-       }
+       r = pakfire_snapshot_restore(build->pakfire);
+       if (r)
+               return r;
 
        // Install or update any build dependencies
        r = pakfire_build_install_packages(build, &snapshot_needs_update);
@@ -1683,7 +1686,7 @@ static int pakfire_build_init(struct pakfire_build* build) {
                return r;
 
        // Update the snapshot if there were changes
-       if (!pakfire_build_has_flag(build, PAKFIRE_BUILD_DISABLE_SNAPSHOT) && snapshot_needs_update) {
+       if (snapshot_needs_update) {
                // Store the snapshot
                r = pakfire_snapshot_store(build->pakfire);
                if (r)
@@ -2030,6 +2033,13 @@ static int pakfire_build_install_source_package(
        if (r)
                goto ERROR;
 
+       // Install all essential packages
+       for (const char** p = PAKFIRE_BUILD_PACKAGES; *p; p++) {
+               r = pakfire_request_add(request, PAKFIRE_REQ_INSTALL, *p, PAKFIRE_REQUEST_ESSENTIAL);
+               if (r)
+                       goto ERROR;
+       }
+
        // Solve the request
        r = pakfire_request_solve(request);
        if (r)
@@ -2087,7 +2097,7 @@ PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* p
        INFO(build->pakfire, "Building %s...\n", nevra);
 
        // Initialize the build environment
-       r = pakfire_build_init(build);
+       r = pakfire_build_setup_snapshot(build);
        if (r)
                goto ERROR;
 
@@ -2230,7 +2240,7 @@ PAKFIRE_EXPORT int pakfire_shell(struct pakfire* pakfire, const char** packages,
        }
 
        // Initialize the build environment
-       r = pakfire_build_init(build);
+       r = pakfire_build_setup_snapshot(build);
        if (r)
                goto ERROR;