From: Michael Tremer Date: Tue, 9 Nov 2021 18:38:20 +0000 (+0000) Subject: packager: Add virtual requirement if using rich dependencies X-Git-Tag: 0.9.28~880 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=555b6dd2bf05579d4e008307218ca6b697d852eb;p=pakfire.git packager: Add virtual requirement if using rich dependencies Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/include/pakfire/package.h b/src/libpakfire/include/pakfire/package.h index 58857324d..6279e921d 100644 --- a/src/libpakfire/include/pakfire/package.h +++ b/src/libpakfire/include/pakfire/package.h @@ -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 diff --git a/src/libpakfire/package.c b/src/libpakfire/package.c index 39554d3f4..738e98867 100644 --- a/src/libpakfire/package.c +++ b/src/libpakfire/package.c @@ -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); diff --git a/src/libpakfire/packager.c b/src/libpakfire/packager.c index 42657e796..4dbda9ecf 100644 --- a/src/libpakfire/packager.c +++ b/src/libpakfire/packager.c @@ -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); diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 5b0aebb68..49906a676 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -119,6 +119,8 @@ struct pakfire { static const struct pakfire_feature { const char* name; } features[] = { + { "RichDependencies" }, + // Package Formats { "PackageFormat-6" }, { "PackageFormat-5" },