From: Michael Tremer Date: Fri, 4 Nov 2022 11:43:10 +0000 (+0000) Subject: build: Refactor installing the source package X-Git-Tag: 0.9.28~134 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fcc68dffea6ca1cb181919c4118627a1a125c019;p=pakfire.git build: Refactor installing the source package 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 --- diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 4ec759e9e..5027e16dc 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -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; }