]> git.ipfire.org Git - pakfire.git/commitdiff
build: Set BUILDROOT to some temporary directory
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 25 May 2021 17:47:30 +0000 (17:47 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 25 May 2021 17:47:30 +0000 (17:47 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c

index 6f19841c61282ed097243abe617ee1f02b3f6a68..775c291c363d35931200e8cc5941b536ee57678f 100644 (file)
@@ -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;
 }