From: Michael Tremer Date: Thu, 3 Nov 2022 20:51:17 +0000 (+0000) Subject: package: Add packages available in the build environment to the package X-Git-Tag: 0.9.28~148 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1cb9c3bf5576982e6c029af908cd5c4677f94509;p=pakfire.git package: Add packages available in the build environment to the package Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/package.c b/src/libpakfire/package.c index c6b53d148..a3da16658 100644 --- a/src/libpakfire/package.c +++ b/src/libpakfire/package.c @@ -1747,6 +1747,80 @@ ERROR: return r; } +static int __pakfire_package_add_build_packages(struct pakfire* pakfire, + struct pakfire_package* pkg, void* p) { + struct json_object* object = (struct json_object*)p; + int r; + + const char* name = pakfire_package_get_string(pkg, PAKFIRE_PKG_NAME); + const char* evr = pakfire_package_get_string(pkg, PAKFIRE_PKG_EVR); + + if (!name || !evr) { + ERROR(pakfire, "Could not fetch package information: %m\n"); + return 1; + } + + // Add package information to the list + r = pakfire_json_add_string(pakfire, object, name, evr); + if (r) { + ERROR(pakfire, "Could not add package to packages list: %m\n"); + return r; + } + + return 0; +} + +static int pakfire_package_add_build_packages(struct pakfire_package* pkg, + struct json_object* md) { + struct pakfire_repo* repo = NULL; + struct pakfire_packagelist* packages = NULL; + struct json_object* object = NULL; + int r; + + // Create a new JSON array + object = json_object_new_object(); + if (!object) { + ERROR(pkg->pakfire, "Could not create a new JSON object: %m\n"); + r = 1; + goto ERROR; + } + + // Fetch the installed repository + repo = pakfire_get_installed_repo(pkg->pakfire); + if (!repo) { + ERROR(pkg->pakfire, "Could not fetch the installed repository: %m\n"); + r = 1; + goto ERROR; + } + + // Fetch all installed packages + r = pakfire_repo_create_packagelist(repo, &packages); + if (r) { + ERROR(pkg->pakfire, "Could not fetch packages from installed repository: %m\n"); + goto ERROR; + } + + // Add all packages to the array + r = pakfire_packagelist_walk(packages, __pakfire_package_add_build_packages, object); + if (r) + goto ERROR; + + // Add object + r = json_object_object_add(md, "packages", json_object_get(object)); + if (r) + goto ERROR; + +ERROR: + if (packages) + pakfire_packagelist_unref(packages); + if (repo) + pakfire_repo_unref(repo); + if (object) + json_object_put(object); + + return r; +} + static int pakfire_package_add_build_metadata(struct pakfire_package* pkg, struct json_object* md) { int r; @@ -1809,6 +1883,13 @@ static int pakfire_package_add_build_metadata(struct pakfire_package* pkg, goto ERROR; } + // Build Packages + if (!pakfire_package_is_source(pkg)) { + r = pakfire_package_add_build_packages(pkg, object); + if (r) + goto ERROR; + } + // Add object r = json_object_object_add(md, "build", object); if (r)