]> git.ipfire.org Git - pakfire.git/blobdiff - src/libpakfire/build.c
build: Use uuid_t for UUIDs
[pakfire.git] / src / libpakfire / build.c
index 2868e8c282ced161ca88f72dbebb8cb0b80ce5a3..e853a676b60eec9f7fa3a2e2e542442ba92fce7e 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <sys/mount.h>
 #include <unistd.h>
+#include <uuid/uuid.h>
 
 #include <pakfire/build.h>
 #include <pakfire/execute.h>
@@ -579,7 +580,7 @@ static int pakfire_build_package_add_scriptlets(Pakfire pakfire, struct pakfire_
 }
 
 static int pakfire_build_package(Pakfire pakfire, struct pakfire_parser* makefile,
-               const char* id, const char* buildroot, const char* namespace, const char* target) {
+               uuid_t* build_id, const char* buildroot, const char* namespace, const char* target) {
        struct pakfire_repo* repo = NULL;
        struct pakfire_package* pkg = NULL;
        struct pakfire_packager* packager = NULL;
@@ -613,8 +614,7 @@ static int pakfire_build_package(Pakfire pakfire, struct pakfire_parser* makefil
        }
 
        // Set build ID
-       if (id)
-               pakfire_package_set_build_id(pkg, id);
+       pakfire_package_set_build_id_from_uuid(pkg, build_id);
 
        // Create a packager
        r = pakfire_packager_create(&packager, pkg);
@@ -664,7 +664,7 @@ ERROR:
 }
 
 static int pakfire_build_packages(Pakfire pakfire, struct pakfire_parser* makefile,
-               const char* id, const char* buildroot, const char* target) {
+               uuid_t* build_id, const char* buildroot, const char* target) {
        DEBUG(pakfire, "Creating packages...");
        int r = 1;
 
@@ -685,7 +685,7 @@ static int pakfire_build_packages(Pakfire pakfire, struct pakfire_parser* makefi
 
        // Build packages in reverse order
        for (int i = num_packages - 1; i >= 0; i--) {
-               r = pakfire_build_package(pakfire, makefile, id, buildroot, packages[i], target);
+               r = pakfire_build_package(pakfire, makefile, build_id, buildroot, packages[i], target);
                if (r)
                        goto ERROR;
        }
@@ -773,7 +773,8 @@ static int pakfire_build_run_post_build_scripts(Pakfire pakfire, const char* bui
 }
 
 static int pakfire_build_makefile(Pakfire pakfire, const char* path, const char* target,
-               const char* id, int flags, pakfire_execute_logging_callback logging_callback, void* data) {
+               uuid_t* build_id, int flags,
+               pakfire_execute_logging_callback logging_callback, void* data) {
        struct pakfire_parser* makefile = NULL;
        char buildroot[PATH_MAX];
        struct pakfire_parser_error* error = NULL;
@@ -826,7 +827,7 @@ static int pakfire_build_makefile(Pakfire pakfire, const char* path, const char*
                goto ERROR;
 
        // Create the packages
-       r = pakfire_build_packages(pakfire, makefile, id, buildroot_rel, target);
+       r = pakfire_build_packages(pakfire, makefile, build_id, buildroot_rel, target);
        if (r) {
                ERROR(pakfire, "Could not create packages: %m\n");
                goto ERROR;
@@ -847,7 +848,7 @@ PAKFIRE_EXPORT int pakfire_build(Pakfire pakfire, const char* path,
                pakfire_execute_logging_callback logging_callback, void* data) {
        char makefiles[PATH_MAX];
        char cwd[PATH_MAX];
-       char* generated_id = NULL;
+       uuid_t build_id;
        glob_t buffer;
        int r = 1;
 
@@ -857,6 +858,17 @@ PAKFIRE_EXPORT int pakfire_build(Pakfire pakfire, const char* path,
                return 1;
        }
 
+       // Try parsing the Build ID
+       if (id) {
+               r = uuid_parse(id, build_id);
+               if (r)
+                       return r;
+
+       // Otherwise initialize the Build ID with something random
+       } else {
+               uuid_generate_random(build_id);
+       }
+
        // The default target is the local repository path
        if (!target) {
                struct pakfire_repo* repo = pakfire_get_repo(pakfire, "@local");
@@ -870,15 +882,6 @@ PAKFIRE_EXPORT int pakfire_build(Pakfire pakfire, const char* path,
                }
        }
 
-       // If no build ID was passed, we generate a random one
-       if (!id) {
-               generated_id = pakfire_generate_uuid();
-               if (!generated_id)
-                       goto ERROR;
-
-               id = generated_id;
-       }
-
        const char* packages[] = {
                path, NULL
        };
@@ -905,7 +908,7 @@ PAKFIRE_EXPORT int pakfire_build(Pakfire pakfire, const char* path,
 
        // Iterate over all makefiles
        for (unsigned int i = 0; i < buffer.gl_pathc; i++) {
-               r = pakfire_build_makefile(pakfire, buffer.gl_pathv[i], target, id, flags,
+               r = pakfire_build_makefile(pakfire, buffer.gl_pathv[i], target, &build_id, flags,
                        logging_callback, data);
                if (r) {
                        ERROR(pakfire, "Could not build %s: %m\n", buffer.gl_pathv[i]);
@@ -915,9 +918,6 @@ PAKFIRE_EXPORT int pakfire_build(Pakfire pakfire, const char* path,
        }
 
 ERROR:
-       if (generated_id)
-               free(generated_id);
-
        return r;
 }