]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
build: Move local build repository here
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 16 Aug 2022 17:12:11 +0000 (17:12 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 16 Aug 2022 17:12:11 +0000 (17:12 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c
src/libpakfire/repo.c

index e87f698d056e8a58aa879c63b38974af9a2b153c..d757fc200f3e14db7f9117c89f50153e65f36167 100644 (file)
@@ -28,6 +28,7 @@
 #include <pakfire/cgroup.h>
 #include <pakfire/dist.h>
 #include <pakfire/file.h>
+#include <pakfire/i18n.h>
 #include <pakfire/jail.h>
 #include <pakfire/logging.h>
 #include <pakfire/mount.h>
@@ -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");
index 822de8bc30db280676a7d7a9d89bc71bbdf3479a..f12ead7277caf88f0845bf4fa3a17945c53c8fe1 100644 (file)
@@ -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)