]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
dependencies: Add support for arch() namespace
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 21 Feb 2023 12:59:14 +0000 (12:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 21 Feb 2023 12:59:14 +0000 (12:59 +0000)
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 <michael.tremer@ipfire.org>
src/libpakfire/dependencies.c
src/libpakfire/pakfire.c
tests/libpakfire/dependencies.c

index 9a2f3b52724d5984a40917310a74f71c77cdc464..96350f631e2e95eac585d4754bb6c65d6dc217e3 100644 (file)
@@ -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);
index 507c9471990c5b1b555ff224c463e1d9598e0cfb..318cf5d69194e8912942849d4c3c64c0f8d24fbd 100644 (file)
@@ -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) {
index 750224bf723658ccecca770d86b5b65032bb2a53..cad448ba582904b577c3e5ea79102e607bedc796 100644 (file)
@@ -68,6 +68,7 @@ static const char* relations[] = {
 
        // Namespaces
        "pakfire(test)",
+       "arch(x86_64)",
 
        // Rich dependencies
        "(foo if bar else baz)",