]> git.ipfire.org Git - pakfire.git/commitdiff
build: Add scaffolding to build packages
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 May 2021 15:10:17 +0000 (15:10 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 May 2021 15:10:17 +0000 (15:10 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c

index ca658f483f4ecc0fa14f75d046519b540d673325..58e8b600960aee0ebf17fc773788c7602070c798 100644 (file)
@@ -48,6 +48,67 @@ static const char* stages[] = {
        "\n" \
        "exit 0\n"
 
+static int pakfire_build_package(Pakfire pakfire, PakfireParser makefile, const char* handle) {
+       int r = 1;
+
+       // Expand the handle into the package name
+       char* name = pakfire_parser_expand(makefile, "packages", handle);
+       if (!name) {
+               ERROR(pakfire, "Could not get package name: %s\n", strerror(errno));
+               goto ERROR;
+       }
+
+       INFO(pakfire, "Building package '%s'...\n", name);
+
+       // XXX actually do all the work
+
+       // Success
+       r = 0;
+
+ERROR:
+       if (name)
+               free(name);
+
+       return r;
+}
+
+static int pakfire_build_packages(Pakfire pakfire, PakfireParser makefile) {
+       DEBUG(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: %s\n", strerror(errno));
+               goto ERROR;
+       }
+
+       unsigned int num_packages = 0;
+
+       // Count how many packages we have
+       for (char** package = packages; *package; package++)
+               num_packages++;
+
+       DEBUG(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,
+                       packages[i] + strlen("packages.package:"));
+               if (r)
+                       goto ERROR;
+       }
+
+       // Success
+       r = 0;
+
+ERROR:
+       if (packages)
+               free(packages);
+
+       return r;
+}
+
 static int pakfire_build_stage(Pakfire pakfire, PakfireParser makefile, const char* stage,
                pakfire_execute_logging_callback logging_callback, void* data) {
        char template[1024];
@@ -113,7 +174,12 @@ PAKFIRE_EXPORT int pakfire_build(Pakfire pakfire, const char* path,
                }
        }
 
-       // XXX Create the packages
+       // Create the packages
+       r = pakfire_build_packages(pakfire, makefile);
+       if (r) {
+               ERROR(pakfire, "Could not create packages: %s\n", strerror(errno));
+               goto ERROR;
+       }
 
 ERROR:
        if (makefile)