From e545f6ec4fd89657a5bf92c7a44e41f239e8d914 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 16 Aug 2022 17:12:11 +0000 Subject: [PATCH] build: Move local build repository here Signed-off-by: Michael Tremer --- src/libpakfire/build.c | 62 ++++++++++++++++++++++++++++++++---------- src/libpakfire/repo.c | 26 ------------------ 2 files changed, 47 insertions(+), 41 deletions(-) diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index e87f698d..d757fc20 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -67,6 +68,9 @@ struct pakfire_build { // Jail struct pakfire_jail* jail; + + // Local build repo + struct pakfire_repo* repo; }; static const char* stages[] = { @@ -100,21 +104,14 @@ static int pakfire_build_enable_repos(struct pakfire_build* build) { FILE* f = NULL; int r = 1; - // Fetch the local repository - struct pakfire_repo* repo = pakfire_get_repo(build->pakfire, PAKFIRE_REPO_LOCAL); - if (!repo) { - DEBUG(build->pakfire, "Could not find repository '%s': %m\n", PAKFIRE_REPO_LOCAL); - return 0; - } - // Fetch repository configuration - char* config = pakfire_repo_get_config(repo); + char* config = pakfire_repo_get_config(build->repo); if (!config) { ERROR(build->pakfire, "Could not generate repository configuration: %m\n"); goto ERROR; } - const char* path = pakfire_repo_get_path(repo); + const char* path = pakfire_repo_get_path(build->repo); // Make sure the source directory exists r = pakfire_mkdir(path, 0700); @@ -160,7 +157,6 @@ ERROR: fclose(f); if (config) free(config); - pakfire_repo_unref(repo); return r; } @@ -830,6 +826,9 @@ ERROR: } static void pakfire_build_free(struct pakfire_build* build) { + if (build->repo) + pakfire_repo_unref(build->repo); + if (build->jail) pakfire_jail_unref(build->jail); @@ -873,13 +872,10 @@ static int pakfire_build_parse_id(struct pakfire_build* build, const char* id) { */ static int pakfire_build_set_default_target(struct pakfire_build* build) { // Look for the "local" repository - struct pakfire_repo* repo = pakfire_get_repo(build->pakfire, PAKFIRE_REPO_LOCAL); - if (repo) { - const char* target = pakfire_repo_get_path(repo); + if (build->repo) { + const char* target = pakfire_repo_get_path(build->repo); if (target) pakfire_string_set(build->target, target); - - pakfire_repo_unref(repo); } // Default to the current working directory @@ -993,6 +989,28 @@ static int pakfire_build_setup_ccache(struct pakfire_build* build) { return 0; } +static int pakfire_build_setup_repos(struct pakfire_build* build) { + int r; + + // Create a new repository + r = pakfire_repo_create(&build->repo, build->pakfire, PAKFIRE_REPO_LOCAL); + if (r) { + ERROR(build->pakfire, "Could not create repository %s: %m\n", PAKFIRE_REPO_LOCAL); + return 1; + } + + // Set description + pakfire_repo_set_description(build->repo, _("Locally Built Packages")); + + // Set path + pakfire_repo_set_baseurl(build->repo, PAKFIRE_REPO_LOCAL_PATH); + + // Set priority + pakfire_repo_set_priority(build->repo, PAKFIRE_REPO_LOCAL_PRIORITY); + + return 0; +} + PAKFIRE_EXPORT int pakfire_build_create(struct pakfire_build** build, struct pakfire* pakfire, const char* id, int flags) { int r; @@ -1016,6 +1034,11 @@ PAKFIRE_EXPORT int pakfire_build_create(struct pakfire_build** build, if (r) goto ERROR; + // Setup repos + r = pakfire_build_setup_repos(b); + if (r) + goto ERROR; + // Set target r = pakfire_build_set_default_target(b); if (r) @@ -1135,6 +1158,15 @@ static int pakfire_build_extract_snapshot(struct pakfire_build* build) { char path[PATH_MAX]; int r; + // Refresh the local repository + if (build->repo) { + r = pakfire_repo_refresh(repo, 0); + if (r) { + ERROR(build->pakfire, "Could not refresh the local repository: %m\n"); + return 1; + } + } + // Check if the user wants a snapshot extracted if (pakfire_build_has_flag(build, PAKFIRE_BUILD_DISABLE_SNAPSHOT)) { DEBUG(build->pakfire, "Snapshot extraction has been disabled for this build\n"); diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index 822de8bc..f12ead72 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -230,32 +230,6 @@ int pakfire_repo_import(struct pakfire* pakfire, struct pakfire_config* config) pakfire_repo_unref(repo); } - // Add local repository (in build mode) - if (pakfire_has_flag(pakfire, PAKFIRE_FLAGS_BUILD)) { - // Does this repository exist already? - repo = pakfire_get_repo(pakfire, PAKFIRE_REPO_LOCAL); - - // Create it if it doesn't exist, yet - if (!repo) { - r = pakfire_repo_create(&repo, pakfire, PAKFIRE_REPO_LOCAL); - if (r) { - ERROR(pakfire, "Could not create repository %s: %m\n", PAKFIRE_REPO_LOCAL); - goto ERROR; - } - - // Set description - pakfire_repo_set_description(repo, _("Locally built packages")); - - // Set path - pakfire_repo_set_baseurl(repo, PAKFIRE_REPO_LOCAL_PATH); - - // Set priority - pakfire_repo_set_priority(repo, PAKFIRE_REPO_LOCAL_PRIORITY); - - pakfire_repo_unref(repo); - } - } - // Refresh repositories r = pakfire_refresh(pakfire, 0); if (r) -- 2.47.3