From: Michael Tremer Date: Tue, 9 Jul 2024 19:23:11 +0000 (+0000) Subject: make.sh: Rewrite how we are looking for rootfiles X-Git-Tag: v2.29-core188~10^2~286 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4830e79f3cf9911a36e1eefc6dc5b21035c797b3;p=ipfire-2.x.git make.sh: Rewrite how we are looking for rootfiles No function changes, just performance. Signed-off-by: Michael Tremer --- diff --git a/lfs/Config b/lfs/Config index baf2bdbc03..8323683fc3 100644 --- a/lfs/Config +++ b/lfs/Config @@ -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 = \ diff --git a/src/scripts/archive.files b/src/scripts/archive.files index c512d2f936..63c57367c0 100755 --- a/src/scripts/archive.files +++ b/src/scripts/archive.files @@ -19,44 +19,75 @@ # # ############################################################################### -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 $?