From be3f4199cb45eb3299cf5f7d09ccc5290068b726 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 30 Aug 2023 17:04:41 +0000 Subject: [PATCH] build: Check if we can build a packager on our architecture Signed-off-by: Michael Tremer --- src/libpakfire/build.c | 10 ++++++++ src/libpakfire/include/pakfire/package.h | 1 + src/libpakfire/package.c | 29 ++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 82dc635c2..a6c71ed0c 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -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) diff --git a/src/libpakfire/include/pakfire/package.h b/src/libpakfire/include/pakfire/package.h index fc3d5a873..eb7398843 100644 --- a/src/libpakfire/include/pakfire/package.h +++ b/src/libpakfire/include/pakfire/package.h @@ -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); diff --git a/src/libpakfire/package.c b/src/libpakfire/package.c index 56823cfc7..6f4b3e786 100644 --- a/src/libpakfire/package.c +++ b/src/libpakfire/package.c @@ -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, -- 2.39.5