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",
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)
+++ /dev/null
-#!/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 $?