From: Michael Tremer Date: Tue, 21 Feb 2023 12:59:14 +0000 (+0000) Subject: dependencies: Add support for arch() namespace X-Git-Tag: 0.9.29~391 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f6c74b93bb20b4429f7b00302ed67f562895dcb2;p=pakfire.git dependencies: Add support for arch() namespace This can be used (mainly in source packages) to check on what system a package is being installed - but not to check whether it is compatible. Most commonly, this feature is going to be used to pull in dependencies that should only be installed on certain architectures. Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/dependencies.c b/src/libpakfire/dependencies.c index 9a2f3b527..96350f631 100644 --- a/src/libpakfire/dependencies.c +++ b/src/libpakfire/dependencies.c @@ -164,7 +164,7 @@ static Id pakfire_parse_dep(struct pakfire* pakfire, const char** s) { size_t l = skip(&p, &n); // Add name to pool - if (pakfire_string_startswith(n, "pakfire(")) + if (pakfire_string_startswith(n, "pakfire(") || pakfire_string_startswith(n, "arch(")) id = pakfire_parse_namespace(pool, n); else id = pool_strn2id(pool, n, l, 1); diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 507c94719..318cf5d69 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -248,6 +248,23 @@ static void pool_log(Pool* pool, void* data, int type, const char* s) { DEBUG(pakfire, "pool: %s", s); } +static Id pakfire_handle_ns_pakfire(struct pakfire* pakfire, const char* name) { + // Find all supported features + for (const struct pakfire_feature* feature = features; feature->name; feature++) { + if (strcmp(feature->name, name) == 0) + return 1; + } + + // Not supported + return 0; +} + +static Id pakfire_handle_ns_arch(struct pakfire* pakfire, const char* name) { + const char* arch = pakfire_get_arch(pakfire); + + return strcmp(arch, name) == 0; +} + static Id pakfire_namespace_callback(Pool* pool, void* data, Id ns, Id id) { struct pakfire* pakfire = (struct pakfire*)data; @@ -256,18 +273,17 @@ static Id pakfire_namespace_callback(Pool* pool, void* data, Id ns, Id id) { DEBUG(pakfire, "Namespace callback called for %s(%s)\n", namespace, name); - // We only handle the pakfire namesapce - if (strcmp(namespace, "pakfire") != 0) - return 0; + // Handle the pakfire() namespace + if (strcmp(namespace, "pakfire") == 0) + return pakfire_handle_ns_pakfire(pakfire, name); - // Find all supported features - for (const struct pakfire_feature* feature = features; feature->name; feature++) { - if (strcmp(feature->name, name) == 0) - return 1; - } + // Handle the arch() namespace + else if (strcmp(namespace, "arch") == 0) + return pakfire_handle_ns_arch(pakfire, name); - // Not supported - return 0; + // Not handled here + else + return 0; } static int pakfire_populate_pool(struct pakfire* pakfire) { diff --git a/tests/libpakfire/dependencies.c b/tests/libpakfire/dependencies.c index 750224bf7..cad448ba5 100644 --- a/tests/libpakfire/dependencies.c +++ b/tests/libpakfire/dependencies.c @@ -68,6 +68,7 @@ static const char* relations[] = { // Namespaces "pakfire(test)", + "arch(x86_64)", // Rich dependencies "(foo if bar else baz)",