]> git.ipfire.org Git - pakfire.git/commitdiff
build: Open source archive and extra some metadata
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 8 Aug 2022 16:42:30 +0000 (16:42 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 8 Aug 2022 16:42:30 +0000 (16:42 +0000)
This saves us on guessing what package we might want to build later.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c

index 9c248b8307c0d609f45ca12b75c0f4e507d37a9c..ba364232bacb0b92ed95c04b3ad2eaebb46e7a09 100644 (file)
@@ -968,16 +968,36 @@ PAKFIRE_EXPORT int pakfire_build_set_target(
 }
 
 PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* path) {
-       char makefiles[PATH_MAX];
-       glob_t buffer;
+       struct pakfire_archive* archive = NULL;
+       struct pakfire_package* package = NULL;
+
+       char makefile[PATH_MAX];
        int r;
 
-       INFO(build->pakfire, "Building %s...\n", path);
+       // Open source archive
+       r = pakfire_archive_open(&archive, build->pakfire, path);
+       if (r) {
+               ERROR(build->pakfire, "Could not open source archive %s: %m\n", path);
+               goto ERROR;
+       }
+
+       // Fetch package metadata
+       r = pakfire_archive_make_package(archive, NULL, &package);
+       if (r) {
+               ERROR(build->pakfire, "Could not read package metadata: %m\n");
+               goto ERROR;
+       }
+
+       // Fetch some information
+       const char* nevra = pakfire_package_get_nevra(package);
+       const char* name  = pakfire_package_get_name(package);
+
+       INFO(build->pakfire, "Building %s...\n", nevra);
 
        // Setup build environment
        r = pakfire_build_setup(build->pakfire);
        if (r)
-               return r;
+               goto ERROR;
 
        const char* packages[] = {
                path, NULL
@@ -988,34 +1008,30 @@ PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* p
                NULL, NULL, NULL);
        if (r) {
                ERROR(build->pakfire, "Could not install %s\n", path);
-               return r;
+               goto ERROR;
        }
 
-       // Where are the makefiles located?
-       r = pakfire_make_path(build->pakfire, makefiles, "/usr/src/packages/*/*.nm");
-       if (r < 0)
+       // Compose path to makefile
+       r = pakfire_string_format(makefile, "/usr/src/packages/%s/%s.nm", name, name);
+       if (r < 0) {
+               ERROR(build->pakfire, "Could not compose makefile path: %m\n");
                goto ERROR;
+       }
 
-       // Find all makefiles
-       r = glob(makefiles, 0, NULL, &buffer);
+       // Run build
+       r = pakfire_build_makefile(build->pakfire, makefile, build->target,
+               &build->id, build->flags);
        if (r) {
-               ERROR(build->pakfire, "glob() on %s failed: %m\n", makefiles);
-               globfree(&buffer);
+               ERROR(build->pakfire, "Could not build %s: %m\n", nevra);
                goto ERROR;
        }
 
-       // Iterate over all makefiles
-       for (unsigned int i = 0; i < buffer.gl_pathc; i++) {
-               r = pakfire_build_makefile(build->pakfire, buffer.gl_pathv[i], build->target,
-                       &build->id, build->flags);
-               if (r) {
-                       ERROR(build->pakfire, "Could not build %s: %m\n", buffer.gl_pathv[i]);
-                       globfree(&buffer);
-                       goto ERROR;
-               }
-       }
-
 ERROR:
+       if (archive)
+               pakfire_archive_unref(archive);
+       if (package)
+               pakfire_package_unref(package);
+
        return r;
 }