]> git.ipfire.org Git - pakfire.git/commitdiff
package: Add packages available in the build environment to the package
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 3 Nov 2022 20:51:17 +0000 (20:51 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 3 Nov 2022 20:58:02 +0000 (20:58 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/package.c

index c6b53d148963e730f1586b5c2b50d3d87ad9a2fe..a3da16658b13af60350544a1c978c0eff9b05af5 100644 (file)
@@ -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)