]> git.ipfire.org Git - pakfire.git/commitdiff
build: Refactor installing the source package
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 4 Nov 2022 11:43:10 +0000 (11:43 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 4 Nov 2022 11:43:10 +0000 (11:43 +0000)
This is required because the old way required the package to be
available on the local filesystem. This way, we only require the package
to exist (usually in the commandline repository).

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

index 4ec759e9e027b1813ba6c640ce39c3801b4fd2db..5027e16dce63e735d44a67941bc86cf7a5c29400 100644 (file)
@@ -1487,6 +1487,57 @@ ERROR:
        return r;
 }
 
+static int pakfire_build_install_source_package(
+               struct pakfire_build* build, struct pakfire_package* package) {
+       struct pakfire_request* request = NULL;
+       struct pakfire_transaction* transaction = NULL;
+       int r;
+
+       // Create a new request
+       r = pakfire_request_create(&request, build->pakfire, 0);
+       if (r)
+               goto ERROR;
+
+       // Add the package
+       r = pakfire_request_add_package(request, PAKFIRE_REQ_INSTALL, package,
+               PAKFIRE_REQUEST_ESSENTIAL);
+       if (r)
+               goto ERROR;
+
+       // Solve the request
+       r = pakfire_request_solve(request);
+       if (r)
+               goto ERROR;
+
+       // Fetch the transaction
+       r = pakfire_request_get_transaction(request, &transaction);
+       if (r)
+               goto ERROR;
+
+       // Set how many packages have been changed
+       const size_t changes = pakfire_transaction_count(transaction);
+
+       // Sanity check to see if we actually try to install anything
+       if (!changes) {
+               ERROR(build->pakfire, "The source package did not get installed\n");
+               r = 1;
+               goto ERROR;
+       }
+
+       // Run the transaction
+       r = pakfire_transaction_run(transaction, 0);
+       if (r)
+               goto ERROR;
+
+ERROR:
+       if (transaction)
+               pakfire_transaction_unref(transaction);
+       if (request)
+               pakfire_request_unref(request);
+
+       return r;
+}
+
 PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* path) {
        struct pakfire_package* package = NULL;
        struct pakfire_parser* makefile = NULL;
@@ -1512,15 +1563,10 @@ PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* p
        if (r)
                goto ERROR;
 
-       const char* packages[] = {
-               path, NULL
-       };
-
-       // Install the package into the build environment
-       r = pakfire_install(build->pakfire, 0, 0, packages, NULL, PAKFIRE_REQUEST_ESSENTIAL,
-               NULL, NULL, NULL);
+       // Install the source package
+       r = pakfire_build_install_source_package(build, package);
        if (r) {
-               ERROR(build->pakfire, "Could not install %s\n", path);
+               ERROR(build->pakfire, "Could not install the source package: %m\n");
                goto ERROR;
        }