From: Michael Tremer Date: Tue, 25 May 2021 17:47:30 +0000 (+0000) Subject: build: Set BUILDROOT to some temporary directory X-Git-Tag: 0.9.28~1285^2~72 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d4011eb1da6585958f5a2c8a361df0c74a858ba;p=pakfire.git build: Set BUILDROOT to some temporary directory Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 6f19841c6..775c291c3 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -341,7 +341,9 @@ PAKFIRE_EXPORT int pakfire_build(Pakfire pakfire, const char* path, const char* target, int flags, pakfire_execute_logging_callback logging_callback, void* data) { PakfireParser makefile = NULL; + char buildroot[PATH_MAX]; struct pakfire_parser_error* error = NULL; + int r; // Check for valid input if (!path) { @@ -361,8 +363,20 @@ PAKFIRE_EXPORT int pakfire_build(Pakfire pakfire, const char* path, pakfire_repo_unref(repo); } + const char* root = pakfire_get_path(pakfire); + + // Create BUILDROOT + pakfire_make_path(pakfire, buildroot, "/tmp/.buildroot.XXXXXX"); + if (!pakfire_mkdtemp(buildroot)) + return 1; + + // Make relative BUILDROOT path + const char* buildroot_rel = pakfire_path_relpath(root, buildroot); + if (!buildroot_rel) + return 1; + // Read makefile - int r = pakfire_read_makefile(&makefile, pakfire, path, &error); + r = pakfire_read_makefile(&makefile, pakfire, path, &error); if (r) { if (error) { ERROR(pakfire, "Could not parse makefile %s: %s\n", path, @@ -376,6 +390,9 @@ PAKFIRE_EXPORT int pakfire_build(Pakfire pakfire, const char* path, goto ERROR; } + // Set BUILDROOT + pakfire_parser_set(makefile, NULL, "BUILDROOT", buildroot_rel); + // Run through all build stages for (const char** stage = stages; *stage; stage++) { int r = pakfire_build_stage(pakfire, makefile, *stage, logging_callback, data); @@ -404,6 +421,9 @@ ERROR: if (makefile) pakfire_parser_unref(makefile); + // Remove buildroot + pakfire_rmtree(buildroot, 0); + return r; }