]> git.ipfire.org Git - pakfire.git/commitdiff
build: Check if we can build a packager on our architecture
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 30 Aug 2023 17:04:41 +0000 (17:04 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 30 Aug 2023 17:04:41 +0000 (17:04 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c
src/libpakfire/include/pakfire/package.h
src/libpakfire/package.c

index 82dc635c2cc85d5b79e67e0d8d87b6f20c8749d0..a6c71ed0ca0562e0384fb17dc1131c84153425d5 100644 (file)
@@ -2072,6 +2072,9 @@ PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* p
        char duration[TIME_STRING_MAX];
        int r;
 
+       // Fetch architecture
+       const char* arch = pakfire_get_arch(build->pakfire);
+
        // Set buildroot
        r = pakfire_path(build->pakfire, build->buildroot, "%s",
                PAKFIRE_TMP_DIR "/pakfire-buildroot.XXXXXX");
@@ -2087,6 +2090,13 @@ PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* p
 
        INFO(build->pakfire, "Building %s...\n", nevra);
 
+       // Check if this package can be build in this environment
+       if (!pakfire_package_supports_build_arch(package, arch)) {
+               ERROR(build->pakfire, "%s does not support being built on %s\n", nevra, arch);
+               r = -ENOTSUP;
+               goto ERROR;
+       }
+
        // Initialize the build environment
        r = pakfire_build_init(build);
        if (r)
index fc3d5a8733329a4d22b75a24c61b05c4d1fb37b9..eb73988435ff4e46fbd7071c897f2e6fb9e12253 100644 (file)
@@ -163,6 +163,7 @@ int pakfire_package_set_strings_from_string(struct pakfire_package* pkg,
        const enum pakfire_package_key key, const char* value);
 
 int pakfire_package_is_source(struct pakfire_package* pkg);
+int pakfire_package_supports_build_arch(struct pakfire_package* pkg, const char* arch);
 
 char* pakfire_package_join_evr(const char* e, const char* v, const char* r);
 
index 56823cfc7a4e5f4496b3bb60f41dc19176c28ffb..6f4b3e786064ba0cd82c23d722300a4cf7ce47d3 100644 (file)
@@ -1259,6 +1259,35 @@ PAKFIRE_EXPORT size_t pakfire_package_get_size(struct pakfire_package* pkg) {
        return pakfire_package_get_num(pkg, PAKFIRE_PKG_DOWNLOADSIZE, 0);
 }
 
+// Build
+
+int pakfire_package_supports_build_arch(struct pakfire_package* pkg, const char* arch) {
+       int r;
+
+       char** supported_arches = pakfire_package_get_strings(pkg, PAKFIRE_PKG_BUILD_ARCHES);
+
+       // If no build arches are configured, this package supports all arches
+       if (!supported_arches)
+               return 1;
+
+       for (char** supported_arch = supported_arches; *supported_arch; supported_arch++) {
+               if (strcmp(arch, *supported_arch) == 0) {
+                       r = 1;
+                       goto END;
+               }
+       }
+
+       // No match found
+       r = 0;
+
+END:
+       // Cleanup
+       if (supported_arches)
+               pakfire_strings_free(supported_arches);
+
+       return r;
+}
+
 // Dependencies
 
 PAKFIRE_EXPORT char** pakfire_package_get_deps(struct pakfire_package* pkg,