]> git.ipfire.org Git - pakfire.git/commitdiff
build: Pass context to pakfire_build_package(s)
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 8 Aug 2022 16:59:06 +0000 (16:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 8 Aug 2022 16:59:06 +0000 (16:59 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c

index 02a5274cd97d8187ee7b7b1637c97cf5e5a7c141..b83b41740e840801a62bdb877d0dc611a99d7a3b 100644 (file)
@@ -498,8 +498,8 @@ static int pakfire_build_package_add_scriptlets(struct pakfire* pakfire, struct
        return 0;
 }
 
-static int pakfire_build_package(struct pakfire* pakfire, struct pakfire_parser* makefile,
-               uuid_t* build_id, const char* buildroot, const char* namespace, const char* target) {
+static int pakfire_build_package(struct pakfire_build* build, struct pakfire_parser* makefile,
+               const char* buildroot, const char* namespace) {
        struct pakfire_package* pkg = NULL;
        struct pakfire_packager* packager = NULL;
 
@@ -508,21 +508,21 @@ static int pakfire_build_package(struct pakfire* pakfire, struct pakfire_parser*
        // Expand the handle into the package name
        char* name = pakfire_parser_expand(makefile, "packages", namespace);
        if (!name) {
-               ERROR(pakfire, "Could not get package name: %m\n");
+               ERROR(build->pakfire, "Could not get package name: %m\n");
                goto ERROR;
        }
 
-       INFO(pakfire, "Building package '%s'...\n", name);
+       INFO(build->pakfire, "Building package '%s'...\n", name);
 
        // Fetch build architecture
-       const char* arch = pakfire_get_arch(pakfire);
+       const char* arch = pakfire_get_arch(build->pakfire);
        if (!arch)
                goto ERROR;
 
        // Fetch package from makefile
        r = pakfire_parser_create_package(makefile, &pkg, NULL, namespace, arch);
        if (r) {
-               ERROR(pakfire, "Could not create package from makefile: %m\n");
+               ERROR(build->pakfire, "Could not create package from makefile: %m\n");
                goto ERROR;
        }
 
@@ -532,7 +532,7 @@ static int pakfire_build_package(struct pakfire* pakfire, struct pakfire_parser*
                pakfire_package_set_distribution(pkg, distribution);
 
        // Set build ID
-       pakfire_package_set_build_id_from_uuid(pkg, build_id);
+       pakfire_package_set_build_id_from_uuid(pkg, &build->id);
 
        // Set source package
        const char* source_name = pakfire_parser_get(makefile, NULL, "name");
@@ -548,32 +548,33 @@ static int pakfire_build_package(struct pakfire* pakfire, struct pakfire_parser*
        pakfire_package_set_source_arch(pkg, "src");
 
        // Create a packager
-       r = pakfire_packager_create(&packager, pakfire, pkg);
+       r = pakfire_packager_create(&packager, build->pakfire, pkg);
        if (r)
                goto ERROR;
 
        // Add files
-       r = pakfire_build_package_add_files(pakfire, makefile, buildroot, namespace,
+       r = pakfire_build_package_add_files(build->pakfire, makefile, buildroot, namespace,
                pkg, packager);
        if (r)
                goto ERROR;
 
        // Add scriptlets
-       r = pakfire_build_package_add_scriptlets(pakfire, makefile, namespace, pkg, packager);
+       r = pakfire_build_package_add_scriptlets(build->pakfire, makefile, namespace,
+               pkg, packager);
        if (r)
                goto ERROR;
 
        // Write the finished package
-       r = pakfire_packager_finish_to_directory(packager, target, NULL);
+       r = pakfire_packager_finish_to_directory(packager, build->target, NULL);
        if (r) {
-               ERROR(pakfire, "pakfire_packager_finish() failed: %m\n");
+               ERROR(build->pakfire, "pakfire_packager_finish() failed: %m\n");
                goto ERROR;
        }
 
 #ifdef ENABLE_DEBUG
        char* dump = pakfire_package_dump(pkg, PAKFIRE_PKG_DUMP_LONG);
        if (dump) {
-               DEBUG(pakfire, "%s\n", dump);
+               DEBUG(build->pakfire, "%s\n", dump);
                free(dump);
        }
 #endif
@@ -592,15 +593,15 @@ ERROR:
        return r;
 }
 
-static int pakfire_build_packages(struct pakfire* pakfire, struct pakfire_parser* makefile,
-               uuid_t* build_id, const char* buildroot, const char* target) {
-       DEBUG(pakfire, "Creating packages...");
+static int pakfire_build_packages(struct pakfire_build* build,
+               struct pakfire_parser* makefile, const char* buildroot) {
+       DEBUG(build->pakfire, "Creating packages...");
        int r = 1;
 
        // Fetch a list all all packages
        char** packages = pakfire_parser_list_namespaces(makefile, "packages.package:*");
        if (!packages) {
-               ERROR(pakfire, "Could not find any packages: %m\n");
+               ERROR(build->pakfire, "Could not find any packages: %m\n");
                goto ERROR;
        }
 
@@ -610,11 +611,11 @@ static int pakfire_build_packages(struct pakfire* pakfire, struct pakfire_parser
        for (char** package = packages; *package; package++)
                num_packages++;
 
-       DEBUG(pakfire, "Found %d package(s)\n", num_packages);
+       DEBUG(build->pakfire, "Found %d package(s)\n", num_packages);
 
        // Build packages in reverse order
        for (int i = num_packages - 1; i >= 0; i--) {
-               r = pakfire_build_package(pakfire, makefile, build_id, buildroot, packages[i], target);
+               r = pakfire_build_package(build, makefile, buildroot, packages[i]);
                if (r)
                        goto ERROR;
        }
@@ -770,8 +771,7 @@ static int pakfire_build_makefile(struct pakfire_build* build, const char* path)
                goto ERROR;
 
        // Create the packages
-       r = pakfire_build_packages(build->pakfire, makefile, &build->id,
-                       buildroot_rel, build->target);
+       r = pakfire_build_packages(build, makefile, buildroot_rel);
        if (r) {
                ERROR(build->pakfire, "Could not create packages: %m\n");
                goto ERROR;