]> git.ipfire.org Git - pakfire.git/commitdiff
build: Allocate buildroot
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 17 Aug 2022 21:19:35 +0000 (21:19 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 17 Aug 2022 21:19:35 +0000 (21:19 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c

index f6aa43f1df4aeeace0884755413ce0948d8a091a..b17afe00339dc6bed123d278b812a02402e75db1 100644 (file)
@@ -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;
 }