From ca72c2a7013a81509444cf7bd680021d1e848112 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 8 Jan 2025 11:22:08 +0000 Subject: [PATCH] build: Install source package/update in one step This patch makes launching a new environment even faster. Everything will always be resolved in one go and installed in one huge transaction. Any dependency errors will be caught really early on and we will have less noise in the console/log. Signed-off-by: Michael Tremer --- src/pakfire/build.c | 104 +++++++------------------------------------- 1 file changed, 16 insertions(+), 88 deletions(-) diff --git a/src/pakfire/build.c b/src/pakfire/build.c index 89b6e24cd..b57a66e60 100644 --- a/src/pakfire/build.c +++ b/src/pakfire/build.c @@ -102,12 +102,6 @@ struct pakfire_build { // ccache path char ccache_path[PATH_MAX]; - - // State - enum pakfire_build_states { - PAKFIRE_BUILD_INIT = 0, - PAKFIRE_BUILD_READY, - } state; }; #define TEMPLATE \ @@ -2203,73 +2197,6 @@ int pakfire_build_set_target( return pakfire_string_set(build->target, target); } -static int pakfire_build_install_packages(struct pakfire_build* build) { - struct pakfire_transaction* transaction = NULL; - char* problems = NULL; - int r; - - // Create a new transaction - r = pakfire_transaction_create(&transaction, build->pakfire, 0); - if (r) - goto ERROR; - - // Install all build dependencies - for (const char** p = PAKFIRE_BUILD_PACKAGES; *p; p++) { - r = pakfire_transaction_request(transaction, - PAKFIRE_JOB_INSTALL, *p, PAKFIRE_JOB_ESSENTIAL); - if (r) - goto ERROR; - } - - // Also update everything that has already been installed - r = pakfire_transaction_request(transaction, PAKFIRE_JOB_SYNC, NULL, 0); - if (r) - goto ERROR; - - // Solve the transaction - r = pakfire_transaction_solve(transaction, 0, &problems); - if (r) { - ERROR(build->ctx, "Could not install build dependencies:\n%s\n", problems); - goto ERROR; - } - - // Run the transaction - r = pakfire_transaction_run(transaction); - if (r) - goto ERROR; - -ERROR: - if (transaction) - pakfire_transaction_unref(transaction); - if (problems) - free(problems); - - return r; -} - -/* - Initializes the build environment -*/ -static int pakfire_build_init(struct pakfire_build* build) { - int r; - - // Don't do it again - if (build->state != PAKFIRE_BUILD_INIT) { - DEBUG(build->ctx, "Build environment has already been initialized\n"); - return 0; - } - - // Install or update any build dependencies - r = pakfire_build_install_packages(build); - if (r) - return r; - - // Mark as ready - build->state = PAKFIRE_BUILD_READY; - - return 0; -} - static int pakfire_build_read_makefile(struct pakfire_build* build, struct pakfire_parser** parser, struct pakfire_package* package) { char path[PATH_MAX]; @@ -2550,8 +2477,7 @@ ERROR: return r; } -static int pakfire_build_install_source_package( - struct pakfire_build* build, struct pakfire_package* package) { +static int pakfire_build_init(struct pakfire_build* build, struct pakfire_package* package) { struct pakfire_transaction* transaction = NULL; char* problems = NULL; int r; @@ -2569,9 +2495,16 @@ static int pakfire_build_install_source_package( goto ERROR; } - // Add the source package - r = pakfire_transaction_request_package(transaction, - PAKFIRE_JOB_INSTALL, package, PAKFIRE_JOB_ESSENTIAL); + // Add the source package (if any) + if (package) { + r = pakfire_transaction_request_package(transaction, + PAKFIRE_JOB_INSTALL, package, PAKFIRE_JOB_ESSENTIAL); + if (r) + goto ERROR; + } + + // Also update everything that has already been installed + r = pakfire_transaction_request(transaction, PAKFIRE_JOB_SYNC, NULL, 0); if (r) goto ERROR; @@ -2679,13 +2612,8 @@ int pakfire_build_exec(struct pakfire_build* build, const char* path) { goto ERROR; } - // Initialize the build environment - r = pakfire_build_init(build); - if (r) - goto ERROR; - - // Install the source package - r = pakfire_build_install_source_package(build, package); + // Install everything we need and the source package, too + r = pakfire_build_init(build, package); if (r) { ERROR(build->ctx, "Could not install the source package: %m\n"); goto ERROR; @@ -2911,8 +2839,8 @@ int pakfire_build_mkimage(struct pakfire_build* build, if (r) goto ERROR; - // Initialize the build environment - r = pakfire_build_init(build); + // Install all packages + r = pakfire_build_install(build, NULL); if (r) goto ERROR; @@ -3024,7 +2952,7 @@ int pakfire_build_shell(struct pakfire_build* build, const char* argv[]) { int r; // Initialize the build environment - r = pakfire_build_init(build); + r = pakfire_build_init(build, NULL); if (r) return r; -- 2.47.3