From: Michael Tremer Date: Tue, 21 Feb 2023 16:43:35 +0000 (+0000) Subject: build: Remove any *.a and *.la files internally instead of using a script X-Git-Tag: 0.9.29~385 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=45dd196007dbf282649c8069cb70da893854715b;p=pakfire.git build: Remove any *.a and *.la files internally instead of using a script Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 621b57a42..8ba32a726 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 # ------------------------------------------------------------------------------ diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index c585f4642..1d06bf26a 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -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 index 39a2fbffc..000000000 --- a/src/scripts/remove-static-libs +++ /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 . # -# # -############################################################################### - -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 $?