From: Michael Tremer Date: Mon, 8 Aug 2022 16:42:30 +0000 (+0000) Subject: build: Open source archive and extra some metadata X-Git-Tag: 0.9.28~568 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=33a8ba3c78545b32cff853b85c6d7a64f6369c3b;p=pakfire.git build: Open source archive and extra some metadata This saves us on guessing what package we might want to build later. Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 9c248b830..ba364232b 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -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; }