From: Michael Tremer Date: Wed, 17 Aug 2022 21:19:35 +0000 (+0000) Subject: build: Allocate buildroot X-Git-Tag: 0.9.28~460 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6fc3956f56e3c00b19e0f285cfa742dc79128f1d;p=pakfire.git build: Allocate buildroot Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index f6aa43f1d..b17afe003 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -72,6 +72,9 @@ struct pakfire_build { // Local build repo struct pakfire_repo* repo; + // Buildroot + char buildroot[PATH_MAX]; + // States int init:1; }; @@ -1217,6 +1220,8 @@ static int pakfire_build_read_makefile(struct pakfire_build* build, struct pakfire_parser_error* error = NULL; + const char* root = pakfire_get_path(build->pakfire); + const char* nevra = pakfire_package_get_nevra(package); const char* name = pakfire_package_get_name(package); @@ -1243,6 +1248,11 @@ static int pakfire_build_read_makefile(struct pakfire_build* build, goto ERROR; } + // Set BUILDROOT + const char* buildroot = pakfire_path_relpath(root, build->buildroot); + if (buildroot) + pakfire_parser_set(*parser, NULL, "BUILDROOT", buildroot, 0); + ERROR: if (error) pakfire_parser_error_unref(error); @@ -1254,8 +1264,12 @@ PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* p struct pakfire_archive* archive = NULL; struct pakfire_package* package = NULL; struct pakfire_parser* makefile = NULL; + char* buildroot = NULL; int r; + // Set buildroot + pakfire_make_path(build->pakfire, build->buildroot, "/var/tmp/.buildroot.XXXXXX"); + // Open source archive r = pakfire_archive_open(&archive, build->pakfire, path); if (r) { @@ -1291,6 +1305,13 @@ PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* p goto ERROR; } + // Create BUILDROOT + buildroot = pakfire_mkdtemp(build->buildroot); + if (!buildroot) { + ERROR(build->pakfire, "Could not create BUILDROOT: %m\n"); + goto ERROR; + } + // Open the makefile r = pakfire_build_read_makefile(build, &makefile, package); if (r) @@ -1313,6 +1334,10 @@ ERROR: if (package) pakfire_package_unref(package); + // Cleanup buildroot + if (buildroot) + pakfire_rmtree(buildroot, 0); + return r; }