From: Michael Tremer Date: Tue, 15 Jun 2021 11:16:53 +0000 (+0000) Subject: build: Find makefiles and build them all X-Git-Tag: 0.9.28~1243 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=01b29895784642b0e3ecf95ab16e42569b8416f7;p=pakfire.git build: Find makefiles and build them all Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 0444800c7..b6975f49c 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -19,6 +19,7 @@ #############################################################################*/ #include +#include #include #include @@ -761,43 +762,12 @@ static int pakfire_build_run_post_build_scripts(Pakfire pakfire, const char* bui return 0; } -PAKFIRE_EXPORT int pakfire_build(Pakfire pakfire, const char* path, - const char* target, const char* id, int flags, - pakfire_execute_logging_callback logging_callback, void* data) { +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) { PakfireParser makefile = NULL; char buildroot[PATH_MAX]; struct pakfire_parser_error* error = NULL; - char* generated_id = NULL; - int r; - - // Check for valid input - if (!path) { - errno = EINVAL; - return 1; - } - - // The default target is the local repository path - if (!target) { - PakfireRepo repo = pakfire_get_repo(pakfire, "local"); - if (!repo) { - errno = EINVAL; - return 1; - } - - target = pakfire_repo_get_path(repo); - pakfire_repo_unref(repo); - } - - const char* packages[] = { - path, NULL - }; - - // Install the package into the build environment - r = pakfire_install(pakfire, packages, 0, NULL); - if (r) { - ERROR(pakfire, "Could not install %s\n", path); - goto ERROR; - } + int r = 1; const char* root = pakfire_get_path(pakfire); @@ -826,15 +796,6 @@ PAKFIRE_EXPORT int pakfire_build(Pakfire pakfire, const char* path, goto ERROR; } - // 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; - } - // Set BUILDROOT pakfire_parser_set(makefile, NULL, "BUILDROOT", buildroot_rel, 0); @@ -863,8 +824,6 @@ PAKFIRE_EXPORT int pakfire_build(Pakfire pakfire, const char* path, } ERROR: - if (generated_id) - free(generated_id); if (makefile) pakfire_parser_unref(makefile); @@ -874,6 +833,80 @@ ERROR: return r; } +PAKFIRE_EXPORT int pakfire_build(Pakfire pakfire, const char* path, + const char* target, const char* id, int flags, + pakfire_execute_logging_callback logging_callback, void* data) { + char makefiles[PATH_MAX]; + char* generated_id = NULL; + glob_t buffer; + int r = 1; + + // Check for valid input + if (!path) { + errno = EINVAL; + return 1; + } + + // The default target is the local repository path + if (!target) { + PakfireRepo repo = pakfire_get_repo(pakfire, "local"); + if (!repo) { + errno = EINVAL; + return 1; + } + + target = pakfire_repo_get_path(repo); + pakfire_repo_unref(repo); + } + + // 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 + }; + + // Install the package into the build environment + r = pakfire_install(pakfire, packages, 0, NULL); + if (r) { + ERROR(pakfire, "Could not install %s\n", path); + goto ERROR; + } + + // Where are the makefiles located? + r = pakfire_make_path(pakfire, makefiles, "/usr/src/packages/*/*.nm"); + if (r < 0) + goto ERROR; + + // Find all makefiles + r = glob(makefiles, 0, NULL, &buffer); + if (r) { + ERROR(pakfire, "glob() on %s failed: %m\n", makefiles); + goto ERROR; + } + + // 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, + logging_callback, data); + if (r) + goto ERROR; + } + +ERROR: + if (generated_id) + free(generated_id); + globfree(&buffer); + + return r; +} + PAKFIRE_EXPORT int pakfire_shell(Pakfire pakfire) { const char* argv[] = { "/bin/bash", "--login", NULL,