]> git.ipfire.org Git - people/ms/ipfire-2.x.git/commitdiff
make.sh: Rewrite how we are looking for rootfiles
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 9 Jul 2024 19:23:11 +0000 (19:23 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 9 Jul 2024 19:23:11 +0000 (19:23 +0000)
No function changes, just performance.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
lfs/Config
src/scripts/archive.files

index baf2bdbc034506f13ea819b314369ae19d1cf9fb..8323683fc3d40c3f519837a4afad7f43774ed005 100644 (file)
@@ -329,12 +329,11 @@ define B2SUM
 endef
 
 # Takes one rootfile or a directory and will return a list of all included files
-define COLLECT_FILES
-       BUILDTARGET="$(BUILDTARGET)" \
+COLLECT_FILES = \
        BUILD_ARCH="$(BUILD_ARCH)" \
+       BUILDTARGET="$(BUILDTARGET)" \
        KVER="$(KVER)" \
-               $(DIR_SRC)/src/scripts/archive.files $(1)
-endef
+               $(DIR_SRC)/src/scripts/archive.files $(BUILD_ARCH) $(1) $(2)
 
 # Takes a filelist from standard input and streams a tarball with all files
 __FILES_IN = \
index c512d2f9366495e677839df371c9efac0ab1975d..63c57367c0e6029ea40cbfe85578fb90ef58c706 100755 (executable)
 #                                                                             #
 ###############################################################################
 
-for i in BUILD_ARCH BUILDTARGET KVER; do
-       if [ -z "${!i}" ]; then
-               echo "${i} not set" >&2
-               exit 1
-       fi
-done
-
-FILELIST=()
+find_rootfile() {
+       local path="${1}"
+       local package="${2}"
 
-for dir in $@; do
-       # Skip all objects that do not exist.
-       [ -e "${dir}" ] || continue
-
-       # Files go directly to the rootfile.
-       if [ -f "${dir}" ]; then
-               FILELIST+=( "${dir}" )
-               continue
-       fi
+       local file
 
-       for exclude in ${dir}/${BUILD_ARCH}/*; do
-               [ -f "${exclude}" ] || continue
-               EXCLUDE="$EXCLUDE $exclude"
+       for file in "${path}/${arch}/${package}" "${path}/${package}"; do
+               if [ -f "${file}" ]; then
+                       echo "${file}"
+                       break
+               fi
        done
+}
 
-       FILELIST+=( "${EXCLUDE}" )
+descend() {
+       local path="${1}"
+       shift
 
-       for include in ${dir}/*; do
-               [ -d ${include} ] && continue
-               IN=true
-               for exclude in ${EXCLUDE}; do
-                       if [ "$(basename ${exclude})" = "$(basename ${include})" ]; then
-                               IN=false
-                               break
+       local packages=( "$@" )
+       local package
+       local file
+
+       # Find all packages
+       if [ "${#packages[@]}" -eq 0 ]; then
+               for file in "${path}/"* "${path}/${arch}"/*; do
+                       if [ -f "${file}" ]; then
+                               packages+=( "${file##*/}" )
                        fi
                done
-               ${IN} && FILELIST+=( "${include}" )
+       fi
+
+       # Return the correct rootfile
+       for package in ${packages[@]}; do
+               find_rootfile "${path}" "${package}"
        done
-done
+}
+
+find_rootfiles() {
+       local path="${1}"
+       shift
+
+       # Descend into directories
+       if [ -d "${path}" ]; then
+               descend "${path}" "$@"
+
+       # Or look straight for a file
+       else
+               find_rootfile "${path}" "$@"
+       fi
+}
+
+# This function takes a list of rootfiles from standard input and extracts all files
+read_rootfiles() {
+       xargs -n 64 grep --no-filename -v "^#" | sort -u
+}
+
+substitute_paths() {
+       sed \
+               -e "s/BUILDTARGET/${BUILDTARGET}/g" \
+               -e "s/KVER/${KVER}/g" \
+               -e "s/xxxMACHINExxx/${BUILD_ARCH}/g"
+}
+
+main() {
+       local arch="${1}"
+       shift
+
+       # Find all rootfiles
+       find_rootfiles "$@" | read_rootfiles | substitute_paths
+}
 
-grep --no-filename -v ^# "${FILELIST[@]}" 2>/dev/null | sort -u | \
-       sed -e "s/KVER/${KVER}/g" -e "s/xxxMACHINExxx/${BUILD_ARCH}/g" -e "s/BUILDTARGET/${BUILDTARGET}/g"
+main "$@" || exit $?