From: Michael Tremer Date: Mon, 8 Aug 2022 16:29:23 +0000 (+0000) Subject: build: Split heavy lifting into a separate exec function X-Git-Tag: 0.9.28~569 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ea92465746a005916275df230bf5addd965f0ced;p=pakfire.git build: Split heavy lifting into a separate exec function Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index ea0c36f15..9c248b830 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -960,50 +960,22 @@ PAKFIRE_EXPORT struct pakfire_build* pakfire_build_unref(struct pakfire_build* b return NULL; } -PAKFIRE_EXPORT int pakfire_build(struct pakfire* pakfire, const char* path, - const char* target, const char* id, int flags) { - char makefiles[PATH_MAX]; - char cwd[PATH_MAX]; - uuid_t build_id; - glob_t buffer; - int r = 1; - - // Check for valid input - if (!path) { - errno = EINVAL; - return 1; - } - - DEBUG(pakfire, "Building %s...\n", path); - - // Try parsing the Build ID - if (id) { - r = uuid_parse(id, build_id); - if (r) { - ERROR(pakfire, "Could not parse build ID %s\n", id); - return r; - } +PAKFIRE_EXPORT int pakfire_build_set_target( + struct pakfire_build* build, const char* target) { + pakfire_string_set(build->target, target); - // Otherwise initialize the Build ID with something random - } else { - uuid_generate_random(build_id); - } + return 0; +} - // The default target is the local repository path - if (!target) { - struct pakfire_repo* repo = pakfire_get_repo(pakfire, PAKFIRE_REPO_LOCAL); - if (repo) { - target = pakfire_repo_get_path(repo); - pakfire_repo_unref(repo); +PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* path) { + char makefiles[PATH_MAX]; + glob_t buffer; + int r; - // If the repository could not be found, just write to the cwd - } else { - target = getcwd(cwd, sizeof(cwd)); - } - } + INFO(build->pakfire, "Building %s...\n", path); // Setup build environment - r = pakfire_build_setup(pakfire); + r = pakfire_build_setup(build->pakfire); if (r) return r; @@ -1012,31 +984,32 @@ PAKFIRE_EXPORT int pakfire_build(struct pakfire* pakfire, const char* path, }; // Install the package into the build environment - r = pakfire_install(pakfire, 0, 0, packages, NULL, PAKFIRE_REQUEST_ESSENTIAL, + r = pakfire_install(build->pakfire, 0, 0, packages, NULL, PAKFIRE_REQUEST_ESSENTIAL, NULL, NULL, NULL); if (r) { - ERROR(pakfire, "Could not install %s\n", path); - goto ERROR; + ERROR(build->pakfire, "Could not install %s\n", path); + return r; } // Where are the makefiles located? - r = pakfire_make_path(pakfire, makefiles, "/usr/src/packages/*/*.nm"); + r = pakfire_make_path(build->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); + ERROR(build->pakfire, "glob() on %s failed: %m\n", makefiles); globfree(&buffer); 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, &build_id, flags); + r = pakfire_build_makefile(build->pakfire, buffer.gl_pathv[i], build->target, + &build->id, build->flags); if (r) { - ERROR(pakfire, "Could not build %s: %m\n", buffer.gl_pathv[i]); + ERROR(build->pakfire, "Could not build %s: %m\n", buffer.gl_pathv[i]); globfree(&buffer); goto ERROR; } @@ -1046,6 +1019,42 @@ ERROR: return r; } +/* + Compatibility function to keep the legacy API. +*/ +PAKFIRE_EXPORT int pakfire_build(struct pakfire* pakfire, const char* path, + const char* target, const char* id, int flags) { + struct pakfire_build* build = NULL; + int r; + + // Check if path is set + if (!path) { + errno = EINVAL; + return 1; + } + + // Create a new build environment + r = pakfire_build_create(&build, pakfire, id, flags); + if (r) + goto ERROR; + + // Set target + if (target) { + r = pakfire_build_set_target(build, target); + if (r) + goto ERROR; + } + + // Run build + r = pakfire_build_exec(build, path); + +ERROR: + if (build) + pakfire_build_unref(build); + + return r; +} + /* This function enables the local repository so that it can be access by a pakfire instance running inside the chroot. diff --git a/src/libpakfire/include/pakfire/build.h b/src/libpakfire/include/pakfire/build.h index 2af00c746..0f313dc30 100644 --- a/src/libpakfire/include/pakfire/build.h +++ b/src/libpakfire/include/pakfire/build.h @@ -31,6 +31,10 @@ int pakfire_build_create(struct pakfire_build** build, struct pakfire_build* pakfire_build_ref(struct pakfire_build* build); struct pakfire_build* pakfire_build_unref(struct pakfire_build* build); +int pakfire_build_set_target(struct pakfire_build* build, const char* target); + +int pakfire_build_exec(struct pakfire_build* build, const char* path); + int pakfire_build(struct pakfire* pakfire, const char* path, const char* target, const char* id, int flags); int pakfire_shell(struct pakfire* pakfire, const char** packages); diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index d527125ab..2bc802e35 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -71,7 +71,9 @@ global: # build pakfire_build; pakfire_build_create; + pakfire_build_exec; pakfire_build_ref; + pakfire_build_set_target; pakfire_build_unref; pakfire_shell;