]> git.ipfire.org Git - pakfire.git/commitdiff
build: Always create a local build repository in the home directory
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Jan 2025 15:20:41 +0000 (15:20 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Jan 2025 15:20:41 +0000 (15:20 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/build.c

index 394093e1f2f5369f432577b480201e61c9b535b5..d45a0453a1e6933f847ca4f00ef7060e06f438c5 100644 (file)
@@ -93,6 +93,9 @@ struct pakfire_build {
        // The build repository
        struct pakfire_repo* repo;
 
+       // The local repository
+       struct pakfire_repo* local;
+
        // Buildroot
        char buildroot[PATH_MAX];
 
@@ -1666,6 +1669,10 @@ static void pakfire_build_free(struct pakfire_build* build) {
                pakfire_repo_unref(build->repo);
        }
 
+       // Free the local repository
+       if (build->local)
+               pakfire_repo_unref(build->local);
+
        if (build->jail)
                pakfire_jail_unref(build->jail);
        if (build->env)
@@ -1899,11 +1906,91 @@ static int pakfire_build_setup_ccache(struct pakfire_build* build) {
        return 0;
 }
 
+static int pakfire_build_setup_local_repo(struct pakfire_build* self) {
+       char path[PATH_MAX];
+       char url[PATH_MAX];
+       int r;
+
+       // Fetch distro ID
+       const char* distro_id  = pakfire_get_distro_id(self->pakfire);
+       if (!distro_id) {
+               ERROR(self->ctx, "Could not fetch the distro ID\n");
+               return -EINVAL;
+       }
+
+       // Fetch the distro version ID
+       const char* version_id = pakfire_get_distro_version_id(self->pakfire);
+       if (!version_id) {
+               ERROR(self->ctx, "Could not fetch the distro version ID\n");
+               return -EINVAL;
+       }
+
+       // Make the repository path
+       r = pakfire_string_format(path,
+                       "~/.local/share/%s/%s/%s", PACKAGE_NAME, distro_id, version_id);
+       if (r < 0) {
+               ERROR(self->ctx, "Could not compose the local repository path: %s\n", strerror(-r));
+               return r;
+       }
+
+       // Expand the path
+       r = pakfire_path_expand(path, path);
+       if (r < 0) {
+               ERROR(self->ctx, "Could not expand the local repository path: %s\n", strerror(-r));
+               return r;
+       }
+
+       // Create the path
+       r = pakfire_mkdir(path, 0700);
+       if (r < 0) {
+               ERROR(self->ctx, "Could not create the local repository at %s: %s\n",
+                       path, strerror(-r));
+               return r;
+       }
+
+       // Create a new repository
+       r = pakfire_repo_create(&self->local, self->pakfire, PAKFIRE_REPO_LOCAL);
+       if (r < 0) {
+               ERROR(self->ctx, "Could not create local repository: %s\n", strerror(-r));
+               return r;
+       }
+
+       // Set description
+       r = pakfire_repo_set_description(self->local, _("Locally Built Packages"));
+       if (r < 0) {
+               ERROR(self->ctx, "Could not set local repository description: %s\n", strerror(-r));
+               return r;
+       }
+
+       // Compose the URL
+       r = pakfire_string_format(url, "file://%s", path);
+       if (r < 0) {
+               ERROR(self->ctx, "Could not compose the local repository URL: %s\n", strerror(-r));
+               return r;
+       }
+
+       // Set the URL
+       r = pakfire_repo_set_baseurl(self->local, url);
+       if (r < 0) {
+               ERROR(self->ctx, "Could not set local repository URL: %s\n", strerror(-r));
+               return r;
+       }
+
+       return 0;
+}
+
 static int pakfire_build_setup_repo(struct pakfire_build* build) {
        char path[PATH_MAX] = PAKFIRE_TMP_DIR "/pakfire-build-repo.XXXXXX";
        char url[PATH_MAX];
        int r;
 
+       // Create a local repository for local builds
+       if (pakfire_build_has_flag(build, PAKFIRE_BUILD_LOCAL)) {
+               r = pakfire_build_setup_local_repo(build);
+               if (r < 0)
+                       return r;
+       }
+
        // Create a new repository
        r = pakfire_repo_create(&build->repo, build->pakfire, PAKFIRE_REPO_RESULT);
        if (r) {