]> git.ipfire.org Git - pakfire.git/commitdiff
build: Process pkg-config provides
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 3 Jan 2025 11:51:23 +0000 (11:51 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 3 Jan 2025 11:51:23 +0000 (11:51 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/build.c

index 383ba13836735e82a28e7512694b0e517e87f6a0..d07c5e9dfc2c6d9cc6591b00ad2d4bae39dee221 100644 (file)
@@ -425,9 +425,8 @@ ERROR:
        return r;
 }
 
-static int __pakfire_build_find_pkgconfig_requires(struct pakfire_ctx* ctx,
-               void* data, const char* line, const size_t length) {
-       struct pakfire_find_deps_ctx* deps = data;
+static int pakfire_build_process_pkgconfig_dep(struct pakfire_package* pkg,
+               const enum pakfire_package_key key, const char* line, const size_t length) {
        char buffer[PATH_MAX];
        int r;
 
@@ -472,15 +471,13 @@ static int __pakfire_build_find_pkgconfig_requires(struct pakfire_ctx* ctx,
 
        // Add everything if we have all the information
        if (name && op && version) {
-               r = pakfire_package_add_dep(deps->pkg, PAKFIRE_PKG_REQUIRES,
-                               "pkgconfig(%s) %s %s", name, op, version);
+               r = pakfire_package_add_dep(pkg, key, "pkgconfig(%s) %s %s", name, op, version);
                if (r < 0)
                        return r;
 
        // Otherwise we add the entire buffer and hope for the best
        } else {
-               r = pakfire_package_add_dep(deps->pkg, PAKFIRE_PKG_REQUIRES,
-                               "pkgconfig(%s)", buffer);
+               r = pakfire_package_add_dep(pkg, key, "pkgconfig(%s)", buffer);
                if (r < 0)
                        return r;
        }
@@ -488,6 +485,51 @@ static int __pakfire_build_find_pkgconfig_requires(struct pakfire_ctx* ctx,
        return length;
 }
 
+static int pakfire_build_process_pkgconfig_provides(
+               struct pakfire_ctx* ctx, void* data, const char* line, const size_t length) {
+       struct pakfire_find_deps_ctx* deps = data;
+
+       return pakfire_build_process_pkgconfig_dep(deps->pkg, PAKFIRE_PKG_PROVIDES, line, length);
+}
+
+static int pakfire_build_process_pkgconfig_requires(
+               struct pakfire_ctx* ctx, void* data, const char* line, const size_t length) {
+       struct pakfire_find_deps_ctx* deps = data;
+
+       return pakfire_build_process_pkgconfig_dep(deps->pkg, PAKFIRE_PKG_REQUIRES, line, length);
+}
+
+static int pakfire_build_find_pkgconfig_provides(
+               struct pakfire_ctx* ctx, struct pakfire_file* file, struct pakfire_find_deps_ctx* deps) {
+       const char* buildroot = NULL;
+       int r;
+
+       // Fetch the absolute path
+       const char* path = pakfire_file_get_abspath(file);
+       if (!path)
+               return -EINVAL;
+
+       // Fetch the path to the buildroot
+       buildroot = pakfire_relpath(deps->build->pakfire, deps->build->buildroot);
+       if (!buildroot)
+               return -EINVAL;
+
+       const char* argv[] = {
+               "pkg-config",
+               "--print-provides",
+               pakfire_relpath(deps->build->pakfire, path),
+               NULL,
+       };
+
+       // Run pkg-config and process the output
+       r = pakfire_jail_communicate(deps->build->jail, argv, NULL, 0, NULL, NULL,
+                       pakfire_build_process_pkgconfig_provides, deps);
+       if (r < 0)
+               return r;
+
+       return 0;
+}
+
 static int pakfire_build_find_pkgconfig_requires(
                struct pakfire_ctx* ctx, struct pakfire_file* file, struct pakfire_find_deps_ctx* deps) {
        struct pakfire_env* env = NULL;
@@ -531,7 +573,7 @@ static int pakfire_build_find_pkgconfig_requires(
 
        // Run pkg-config and process the output
        r = pakfire_jail_communicate(deps->build->jail, argv, env, 0, NULL, NULL,
-                       __pakfire_build_find_pkgconfig_requires, deps);
+                       pakfire_build_process_pkgconfig_requires, deps);
        if (r < 0)
                goto ERROR;
 
@@ -617,7 +659,46 @@ static int pakfire_build_find_python_abi_requires(
                PAKFIRE_PKG_REQUIRES, "python-abi = %s", basename + strlen("python"));
 }
 
-static int __pakfire_build_find_requires(
+static int pakfire_build_find_provides(
+               struct pakfire_ctx* ctx, struct pakfire_file* file, void* data) {
+       struct pakfire_find_deps_ctx* deps = data;
+       const char* path = NULL;
+       int r;
+
+       // Fetch the file path
+       path = pakfire_file_get_path(file);
+       if (!path)
+               return -EINVAL;
+
+       // Skip debug files
+       if (pakfire_path_match("/usr/lib/debug/**", path))
+               return 0;
+
+       // Skip debug sources
+       else if (pakfire_path_match("/usr/src/debug/**", path))
+               return 0;
+
+       // Handle pkg-config files
+       else if (pakfire_path_match("**.pc", path))
+               return pakfire_build_find_pkgconfig_provides(ctx, file, deps);
+
+#if 0
+       // Split certain file types differently
+       switch (pakfire_file_get_type(file)) {
+               // Regular files
+               case S_IFREG:
+                       // Handle ELF files
+                       r = pakfire_build_find_elf_provides(ctx, file, deps);
+                       if (r < 0)
+                               return r;
+                       break;
+       }
+#endif
+
+       return 0;
+}
+
+static int pakfire_build_find_requires(
                struct pakfire_ctx* ctx, struct pakfire_file* file, void* data) {
        struct pakfire_find_deps_ctx* deps = data;
        const char* path = NULL;
@@ -665,16 +746,6 @@ static int __pakfire_build_find_requires(
        return 0;
 }
 
-static int pakfire_build_find_requires(struct pakfire_build* build,
-               struct pakfire_package* pkg, struct pakfire_filelist* filelist) {
-       struct pakfire_find_deps_ctx deps = {
-               .build = build,
-               .pkg   = pkg,
-       };
-
-       return pakfire_filelist_walk(filelist, __pakfire_build_find_requires, &deps, 0, NULL);
-}
-
 /*
        This function is a special way to run a script.
 
@@ -725,6 +796,11 @@ static int pakfire_build_find_dependencies(struct pakfire_build* build,
        char* filter_requires = NULL;
        int r;
 
+       struct pakfire_find_deps_ctx deps = {
+               .build = build,
+               .pkg   = pkg,
+       };
+
        // Fetch the provides filter
        filter_provides = pakfire_parser_get(makefile, namespace, "filter_provides");
        if (filter_provides) {
@@ -742,6 +818,11 @@ static int pakfire_build_find_dependencies(struct pakfire_build* build,
        }
 
        // Find all provides
+       r = pakfire_filelist_walk(filelist, pakfire_build_find_provides, &deps, 0, NULL);
+       if (r < 0)
+               goto ERROR;
+
+       // XXX LEGACY CODE
        r = pakfire_build_find_deps(build, pkg,
                PAKFIRE_PKG_PROVIDES, "find-provides", filelist, 0);
        if (r)
@@ -754,7 +835,7 @@ static int pakfire_build_find_dependencies(struct pakfire_build* build,
                goto ERROR;
 
        // Find all requires
-       r = pakfire_build_find_requires(build, pkg, filelist);
+       r = pakfire_filelist_walk(filelist, pakfire_build_find_requires, &deps, 0, NULL);
        if (r < 0)
                goto ERROR;