]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
build: Remove any *.a and *.la files internally instead of using a script
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 21 Feb 2023 16:43:35 +0000 (16:43 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 21 Feb 2023 16:43:35 +0000 (16:43 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/libpakfire/build.c
src/scripts/remove-static-libs [deleted file]

index 621b57a42a390fa7f6388c0939ccb69c8d25a96d..8ba32a72653e616589b439054e221597dda0177b 100644 (file)
@@ -729,7 +729,6 @@ dist_scripts_SCRIPTS = \
        src/scripts/find-requires \
        src/scripts/perl.prov \
        src/scripts/perl.req \
-       src/scripts/remove-static-libs \
        src/scripts/strip
 
 # ------------------------------------------------------------------------------
index c585f4642279fe7e6f0165d3f7d4fce015679645..1d06bf26ac356e189ff8d82f19df73e0f2499abb 100644 (file)
@@ -988,8 +988,128 @@ ERROR:
        return r;
 }
 
+/*
+       This helper function takes a callback which is expected to add any files
+       to the given filelist which will be all removed after.
+*/
+static int pakfire_build_post_remove_files(struct pakfire_build* build,
+               struct pakfire_filelist* filelist, const char* description,
+               int (*callback)(struct pakfire* pakfire, struct pakfire_file* file, void* data)) {
+       struct pakfire_filelist* removees = NULL;
+       int r;
+
+       // Create a filelist with objects that need to be removed
+       r = pakfire_filelist_create(&removees, build->pakfire);
+       if (r)
+               goto ERROR;
+
+       // Find all files that need to be removed
+       r = pakfire_filelist_walk(filelist, callback, removees);
+       if (r)
+               goto ERROR;
+
+       if (!pakfire_filelist_is_empty(removees)) {
+               if (description)
+                       INFO(build->pakfire, "%s\n", description);
+
+               // Show all files which will be removed
+               pakfire_filelist_dump(removees, 0);
+
+               // Remove all files on the removee list
+               r = pakfire_filelist_cleanup(removees);
+               if (r)
+                       goto ERROR;
+
+               // Remove all files from the filelist
+               r = pakfire_filelist_remove_all(filelist, removees);
+               if (r)
+                       goto ERROR;
+       }
+
+ERROR:
+       if (removees)
+               pakfire_filelist_unref(removees);
+
+       return r;
+}
+
+static int __pakfire_build_remove_static_libraries(
+               struct pakfire* pakfire, struct pakfire_file* file, void* data) {
+       struct pakfire_filelist* removees = (struct pakfire_filelist*)data;
+
+       // Find all static libraries
+       if (pakfire_file_matches_class(file, PAKFIRE_FILE_STATIC_LIBRARY))
+               return pakfire_filelist_append(removees, file);
+
+       return 0;
+}
+
+static int pakfire_build_post_remove_static_libraries(
+               struct pakfire_build* build, struct pakfire_filelist* filelist) {
+       return pakfire_build_post_remove_files(build, filelist,
+               "Removing static libaries...", __pakfire_build_remove_static_libraries);
+}
+
+static int __pakfire_build_remove_libtool_archives(
+               struct pakfire* pakfire, struct pakfire_file* file, void* data) {
+       struct pakfire_filelist* removees = (struct pakfire_filelist*)data;
+
+       // Find all libtool archive files
+       if (pakfire_file_matches_class(file, PAKFIRE_FILE_LIBTOOL_ARCHIVE))
+               return pakfire_filelist_append(removees, file);
+
+       return 0;
+}
+
+static int pakfire_build_post_remove_libtool_archives(
+               struct pakfire_build* build, struct pakfire_filelist* filelist) {
+       return pakfire_build_post_remove_files(build, filelist,
+               "Removing libtool archives...", __pakfire_build_remove_libtool_archives);
+}
+
+static int pakfire_build_run_post_build_checks(struct pakfire_build* build) {
+       struct pakfire_filelist* filelist = NULL;
+       int r;
+
+       // Create a filelist of all files in the build
+       r = pakfire_filelist_create(&filelist, build->pakfire);
+       if (r) {
+               ERROR(build->pakfire, "Could not create filelist: %m\n");
+               goto ERROR;
+       }
+
+       // Scan for all files in BUILDROOT
+       r = pakfire_filelist_scan(filelist, build->buildroot, NULL, NULL);
+       if (r)
+               goto ERROR;
+
+       const size_t length = pakfire_filelist_size(filelist);
+
+       // If the filelist is empty, we can are done
+       if (length == 0) {
+               DEBUG(build->pakfire, "Empty BUILDROOT. Skipping post build checks...\n");
+               r = 0;
+               goto ERROR;
+       }
+
+       // Remove any static libraries
+       r = pakfire_build_post_remove_static_libraries(build, filelist);
+       if (r)
+               goto ERROR;
+
+       // Remove any libtool archives
+       r = pakfire_build_post_remove_libtool_archives(build, filelist);
+       if (r)
+               goto ERROR;
+
+ERROR:
+       if (filelist)
+               pakfire_filelist_unref(filelist);
+
+       return r;
+}
+
 static const char* post_build_scripts[] = {
-       "remove-static-libs",
        "check-symlinks",
        "check-unsafe-files",
        "check-libraries",
@@ -1458,6 +1578,11 @@ static int pakfire_build_perform(struct pakfire_build* build,
        if (r)
                goto ERROR;
 
+       // Run post build checks
+       r = pakfire_build_run_post_build_checks(build);
+       if (r)
+               goto ERROR;
+
        // Run post build scripts
        r = pakfire_build_run_post_build_scripts(build);
        if (r)
diff --git a/src/scripts/remove-static-libs b/src/scripts/remove-static-libs
deleted file mode 100644 (file)
index 39a2fbf..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/bin/bash
-###############################################################################
-#                                                                             #
-# Pakfire - The IPFire package management system                              #
-# Copyright (C) 2021 Pakfire development team                                 #
-#                                                                             #
-# This program is free software: you can redistribute it and/or modify        #
-# it under the terms of the GNU General Public License as published by        #
-# the Free Software Foundation, either version 3 of the License, or           #
-# (at your option) any later version.                                         #
-#                                                                             #
-# This program is distributed in the hope that it will be useful,             #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
-# GNU General Public License for more details.                                #
-#                                                                             #
-# You should have received a copy of the GNU General Public License           #
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
-#                                                                             #
-###############################################################################
-
-error() {
-       echo "$@" >&2
-}
-
-main() {
-       local buildroot="${1}"
-       shift
-
-       # Check if BUILDROOT exists
-       if [ ! -d "${buildroot}" ]; then
-               error "BUILDROOT does not exist"
-               return 1
-       fi
-
-       echo "Removing unwanted static libraries..."
-
-       local file
-       for file in $(find "${buildroot}" -name "*.a"); do
-               if [ -e "${file%.a}.so" ]; then
-                       echo "  ${file/${buildroot}/}"
-                       rm -f "${file}"
-               fi
-       done
-
-       # Remove all .la files
-       for file in $(find "${buildroot}" -name "*.la"); do
-               rm -f "${file}"
-       done
-
-       return 0
-}
-
-main "$@" || exit $?