]> git.ipfire.org Git - pakfire.git/commitdiff
packager: Add virtual requirement if using rich dependencies
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 9 Nov 2021 18:38:20 +0000 (18:38 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 10 Nov 2021 09:43:08 +0000 (09:43 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/package.h
src/libpakfire/package.c
src/libpakfire/packager.c
src/libpakfire/pakfire.c

index 58857324d6877bbfc6b9ddbdfbfd4c58781c256e..6279e921dee2cf9a1fc61d7f29a02ad95426fe5d 100644 (file)
@@ -147,6 +147,7 @@ void pakfire_package_add_recommends(struct pakfire_package* pkg, const char* dep
 void pakfire_package_add_suggests(struct pakfire_package* pkg, const char* dep);
 void pakfire_package_add_supplements(struct pakfire_package* pkg, const char* dep);
 void pakfire_package_add_enhances(struct pakfire_package* pkg, const char* dep);
+int pakfire_package_has_rich_deps(struct pakfire_package* pkg);
 
 #endif
 
index 39554d3f4e3715fb1db732f0dd5f88d323a70499..738e98867c39f5bd4038110ee9605c117bbdc86c 100644 (file)
@@ -889,6 +889,62 @@ ERROR:
        return r;
 }
 
+static int pakfire_package_has_rich_deps_in_deparray(
+               struct pakfire_package* pkg, Id type) {
+       int r = 0;
+
+       Solvable* s = get_solvable(pkg);
+
+       Queue q;
+       queue_init(&q);
+
+       // Fetch all deps
+       solvable_lookup_deparray(s, type, &q, 0);
+
+       // Nothing to do if the array was empty
+       if (!q.count)
+               goto ERROR;
+
+       for (int i = 0; i < q.count; i++) {
+               const char* dep = pakfire_dep2str(pkg->pakfire, q.elements[i]);
+
+               // Is this a rich dependency?
+               if (dep && *dep == '(') {
+                       r = 1;
+                       break;
+               }
+       }
+
+ERROR:
+       queue_free(&q);
+
+       return r;
+}
+
+int pakfire_package_has_rich_deps(struct pakfire_package* pkg) {
+       static const Id types[] = {
+               // Requires (includes pre-requires)
+               SOLVABLE_REQUIRES,
+               SOLVABLE_PROVIDES,
+               SOLVABLE_CONFLICTS,
+               SOLVABLE_OBSOLETES,
+               SOLVABLE_RECOMMENDS,
+               SOLVABLE_SUGGESTS,
+               SOLVABLE_SUPPLEMENTS,
+               SOLVABLE_ENHANCES,
+               0,
+       };
+
+       for (const Id* type = types; *type; type++) {
+               int r = pakfire_package_has_rich_deps_in_deparray(pkg, *type);
+               if (r)
+                       return r;
+       }
+
+       // No match
+       return 0;
+}
+
 PAKFIRE_EXPORT struct pakfire_repo* pakfire_package_get_repo(struct pakfire_package* pkg) {
        if (!pkg->repo) {
                Solvable* s = get_solvable(pkg);
index 42657e7961dd538f912d2872e68e5d50c09b9302..4dbda9ecf8fd750b6b84c37446812d67600a6895 100644 (file)
@@ -781,6 +781,10 @@ int pakfire_packager_finish(struct pakfire_packager* packager, FILE* f) {
        FILE* fmtree = NULL;
        int r = 1;
 
+       // Add requires feature markers
+       if (pakfire_package_has_rich_deps(packager->pkg))
+               pakfire_package_add_requires(packager->pkg, "pakfire(RichDependencies)");
+
        // Store total install size
        pakfire_package_set_installsize(packager->pkg, packager->installsize);
 
index 5b0aebb682a53adc10616f0c4e2d046f3142a802..49906a676e00b60e6e5efe330b79d858eb90362e 100644 (file)
@@ -119,6 +119,8 @@ struct pakfire {
 static const struct pakfire_feature {
        const char* name;
 } features[] = {
+       { "RichDependencies" },
+
        // Package Formats
        { "PackageFormat-6" },
        { "PackageFormat-5" },