summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIsmael Luceno2020-04-09 21:40:05 +0200
committerIsmael Luceno2020-04-09 23:16:56 +0200
commitf4ef5e8287b1a65aa0f38229af8f2b7b077cd74d (patch)
tree8e3d2cb4871450f9b596e3ecc5b99fdac50424ef
parent112632ce607b3744b607deb21ac0ea3267c8ded5 (diff)
libmisc: Re-implement one-shot specfile selection
This version fixes the composition of SMGL_COMPAT_ARCHS. Reverts: 112632ce607b ("Revert "libmisc: Implement one-shot specfile selection"") Fixes: 615b00c28da7 ("libmisc: Implement one-shot specfile selection")
-rwxr-xr-xvar/lib/sorcery/modules/libmisc41
1 files changed, 23 insertions, 18 deletions
diff --git a/var/lib/sorcery/modules/libmisc b/var/lib/sorcery/modules/libmisc
index dd5952c2..b9e27de3 100755
--- a/var/lib/sorcery/modules/libmisc
+++ b/var/lib/sorcery/modules/libmisc
@@ -1478,28 +1478,33 @@ set_architecture() {
: ${arch:=${TARGET:-$ARCHITECTURE}}
# Find the specfile to use
- for specdir in ${ARCH_SPECS[@]} ; do
- SPECFILE=$(find -L ${specdir} -perm -400 -type f -name "$arch" 2>/dev/null | sed q)
- [ $SPECFILE ] && break
- done
- if [[ ! $SPECFILE ]] ; then
- message "${PROBLEM_COLOR}Cannot find arch spec for $arch!"
- message "Reverting to null!"
- message "Please run sorcery afterwards and pick another architecture!$DEFAULT_COLOR"
- echo
- sleep 2
- SPECFILE=$(find -L ${specdir} -perm -400 -type f -name "null" 2>/dev/null | sed q)
- fi
+ SPECFILE=$(find -L "${ARCH_SPECS[@]}" \( -name "$arch" -o -name null \) \
+ -perm -400 -type f 2>/dev/null |
+ awk '! /[/]null$/ { exit } END { print }')
+ case "$SPECFILE" in
+ */null)
+ message "${PROBLEM_COLOR}Cannot find arch spec for $arch!"
+ message "Reverting to null!"
+ message "Please run sorcery afterwards and pick another architecture!$DEFAULT_COLOR"
+ echo
+ sleep 2
+ esac
debug "libmisc" "set_architecture: SPECFILE=$SPECFILE"
- # turn the path into an array, but remove $specdir from the start first
- unset SMGL_COMPAT_ARCHS
- explode "${SPECFILE#$specdir/}" '/' SMGL_COMPAT_ARCHS
+ # turn the path into an array, removing the spec dir prefix
+ SMGL_COMPAT_ARCHS=($(awk -F/ -vdirs="^${ARCH_SPECS[*]}/" -vf="$SPECFILE" '
+ BEGIN {
+ sub(/[/]* +/, "/|^", dirs) # convert to regex
+ match(f, dirs)
+ f = substr(f, RLENGTH) # remove prefix
+ gsub(/[/]+/, " ", f) # split
+ print f
+ }'))
+ debug "libmisc" "set_architecture: SMGL_COMPAT_ARCHS[${#SMGL_COMPAT_ARCHS[@]}]=(${SMGL_COMPAT_ARCHS[*]})"
# Reverse the array so that the most specific arch is first
- ARCHITECTURE=(
- $(for i in "${SMGL_COMPAT_ARCHS[@]}"; do echo "$i"; done | tac)
- )
+ ARCHITECTURE=($(awk 'BEGIN { while (--ARGC > 0) print ARGV[ARGC] }' \
+ "${SMGL_COMPAT_ARCHS[@]}"))
# Guess libc ABI; archspecs default to "gnu"
if [ -z "$HOST_LIBC" ]; then