]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
build: Automatically create the local repository
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 22 Sep 2021 10:15:42 +0000 (10:15 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 22 Sep 2021 10:15:42 +0000 (10:15 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
contrib/config/distros/ipfire3.conf
src/libpakfire/build.c
src/libpakfire/include/pakfire/repo.h
src/libpakfire/repo.c

index ae4cae262af7064e48cb3a09ddb2f428ad5317d0..0caefecb3c516b44737146c1ec1810071f4d1e51 100644 (file)
@@ -35,8 +35,3 @@ description   = IPFire 3 - Unstable Repository
 baseurl                = https://pakfire.ipfire.org/repositories/ipfire3/unstable/%{arch}
 mirrors                = https://pakfire.ipfire.org/distro/ipfire3/repo/unstable/mirrorlist?arch=%{arch}
 priority       = 300
-
-[repo:@local]
-description    = IPFire 3 locally built packages
-baseurl                = file:///var/lib/pakfire/local/ipfire3
-priority       = 1000
index e5dfd6825af2b136d0254ec23e456c8c6292f447..998eb86a1e9569149633100a501ff95a1727e0c1 100644 (file)
@@ -743,7 +743,7 @@ PAKFIRE_EXPORT int pakfire_build(struct pakfire* pakfire, const char* path,
 
        // The default target is the local repository path
        if (!target) {
-               struct pakfire_repo* repo = pakfire_get_repo(pakfire, "@local");
+               struct pakfire_repo* repo = pakfire_get_repo(pakfire, PAKFIRE_REPO_LOCAL);
                if (repo) {
                        target = pakfire_repo_get_path(repo);
                        pakfire_repo_unref(repo);
@@ -814,9 +814,9 @@ int pakfire_build_clean(struct pakfire* pakfire, int flags) {
        int r = 0;
 
        // Fetch local repository
-       local = pakfire_get_repo(pakfire, "@local");
+       local = pakfire_get_repo(pakfire, PAKFIRE_REPO_LOCAL);
        if (!local) {
-               ERROR(pakfire, "Could not find local repository: %m\n");
+               ERROR(pakfire, "Could not find repository %s: %m\n", PAKFIRE_REPO_LOCAL);
                goto ERROR;
        }
 
index 37c79ab621438d0d679f94f7ec758c799d689cbc..9317dec0b06028b0ae5e1fc9951fa5d60ec7e8d6 100644 (file)
@@ -101,6 +101,10 @@ int pakfire_repo_compose(struct pakfire* pakfire, const char* path, int flags,
 #include <pakfire/downloader.h>
 #include <pakfire/package.h>
 
+#define PAKFIRE_REPO_LOCAL              "local"
+#define PAKFIRE_REPO_LOCAL_PATH         "file://" PAKFIRE_PRIVATE_DIR "/local/%{distro}/%{version}"
+#define PAKFIRE_REPO_LOCAL_PRIORITY      1000
+
 int pakfire_repo_import(struct pakfire* pakfire, struct pakfire_config* config);
 const char* pakfire_repo_get_path(struct pakfire_repo* repo);
 
index 3f412248edc871867bfacc6e09abf884aaf97f28..69f1a6e6ae04639771495f188aad95a50bd42702 100644 (file)
@@ -219,6 +219,32 @@ 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);
+               }
+       }
+
 ERROR:
        for (char** section = sections; *section; section++)
                free(*section);
@@ -658,15 +684,14 @@ static char* pakfire_repo_url_replace(struct pakfire_repo* repo, const char* url
        if (!url)
                return NULL;
 
-       const char* arch = pakfire_get_arch(repo->pakfire);
-       const char* name = pakfire_repo_get_name(repo);
-
        const struct replacement {
                const char* pattern;
                const char* replacement;
        } replacements[] = {
-               { "%{name}", name },
-               { "%{arch}", arch },
+               { "%{name}", pakfire_repo_get_name(repo) },
+               { "%{arch}", pakfire_get_arch(repo->pakfire) },
+               { "%{distro}", pakfire_get_distro_id(repo->pakfire) },
+               { "%{version}", pakfire_get_distro_version_id(repo->pakfire) },
                { NULL, NULL },
        };