]> git.ipfire.org Git - pakfire.git/commitdiff
build: Add implicit dist() when a makefile is passed
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 29 Sep 2023 14:59:37 +0000 (14:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 29 Sep 2023 14:59:37 +0000 (14:59 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/lib/build.c
src/libpakfire/pakfire.c

index 3287888655134e90ed44bb66662b63e086cc54a9..2e739bcfa2f2857f8600117fadd5f558b8a6cde1 100644 (file)
@@ -168,8 +168,6 @@ int cli_build(struct pakfire* pakfire, int argc, char* argv[]) {
 
        // Process all packages
        for (int i = optind; i < argc; i++) {
-               // XXX implement dist
-
                // Run the build
                r = pakfire_build_exec(build, argv[i]);
                if (r) {
index 08a7fbb99261cdf530543a697365a0b773558a4f..38776c1cd81de9fac7f822754fd305434c1393e6 100644 (file)
@@ -48,6 +48,7 @@
 #include <pakfire/constants.h>
 #include <pakfire/db.h>
 #include <pakfire/dependencies.h>
+#include <pakfire/dist.h>
 #include <pakfire/logging.h>
 #include <pakfire/mount.h>
 #include <pakfire/package.h>
@@ -1408,6 +1409,31 @@ struct pakfire_repo* pakfire_get_installed_repo(struct pakfire* pakfire) {
        return pakfire_repo_create_from_repo(pakfire, pakfire->pool->installed);
 }
 
+/*
+       Convenience function to dist() a package on the fly
+*/
+static int pakfire_commandline_dist(struct pakfire* pakfire, struct pakfire_repo* repo,
+               const char* path, struct pakfire_package** package) {
+       char* result = NULL;
+       int r;
+
+       // XXX result is not unique!
+
+       // Run dist()
+       r = pakfire_dist(pakfire, path, PAKFIRE_TMP_DIR, &result);
+       if (r)
+               goto ERROR;
+
+       // Try to add the package to the repository
+       r = pakfire_repo_add(repo, result, package);
+
+ERROR:
+       if (result)
+               free(result);
+
+       return r;
+}
+
 /*
        Convenience function to add a package to the @commandline repository
 */
@@ -1425,8 +1451,14 @@ int pakfire_commandline_add(struct pakfire* pakfire, const char* path,
 
        // Add the package
        r = pakfire_repo_add(repo, path, package);
-       if (r)
-               goto ERROR;
+       switch (-r) {
+               case ENOMSG:
+                       r = pakfire_commandline_dist(pakfire, repo, path, package);
+                       break;
+
+               default:
+                       goto ERROR;
+       }
 
 ERROR:
        if (repo)