diff options
author | Sevinj Aghayeva <sevinj.aghayeva@gmail.com> | 2022-04-15 06:23:17 -0400 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2022-04-15 17:09:09 +0200 |
commit | bba4de97647ecc746f43764a0390f9756771cd13 (patch) | |
tree | 873bcbe8ecf6dca0b66a8e0ca0a7f7218a5b13d8 | |
parent | 1cc97f6c01e0d1cb8006fce4198c82ec0efb763e (diff) | |
download | mbuto-bba4de97647ecc746f43764a0390f9756771cd13.tar mbuto-bba4de97647ecc746f43764a0390f9756771cd13.tar.gz mbuto-bba4de97647ecc746f43764a0390f9756771cd13.tar.bz2 mbuto-bba4de97647ecc746f43764a0390f9756771cd13.tar.lz mbuto-bba4de97647ecc746f43764a0390f9756771cd13.tar.xz mbuto-bba4de97647ecc746f43764a0390f9756771cd13.tar.zst mbuto-bba4de97647ecc746f43764a0390f9756771cd13.zip |
mbuto: add a function to join elements of a list into a string
In multiple places we loop over a list by joining its elements with a prefix,
suffix, and a delimiter into a single string. Add a function for this
functionality and replace these loops with a function.
Signed-off-by: Sevinj Aghayeva <sevinj.aghayeva@gmail.com>
-rwxr-xr-x | mbuto | 35 |
1 files changed, 20 insertions, 15 deletions
@@ -223,21 +223,11 @@ profile_kselftests() { if [ -f ${__cfg} ]; then __mods=$(${AWK} -F'=' '/=m/ {print $1}' ${__cfg} | ${SORT} -u) - __egrep_pattern="" - for __c in ${__mods}; do - __egrep_pattern='^obj-\$\('"${__c}"'\).*.o$|'"${__egrep_pattern}" - done - __egrep_pattern=${__egrep_pattern%|} - - __kmods_needed= - __find_pattern= - for __mo in $(${EGREP} -rn --include "*Makefile" ${__egrep_pattern} | \ - ${AWK} -F'+=' '/+=/ {print $2}'); do - __m=$(${BASENAME} -s .o ${__mo}) - __find_pattern="-name ${__m}.ko -o ${__find_pattern}" - __kmods_needed="${__m} ${__kmods_needed}" - done - __find_pattern=${__find_pattern%-o } + __pattern=$(list_join "${__mods}" '^obj-\$\(' '\).*.o$' '|') + __result=$(${BASENAME} -a -s .o \ + $(${EGREP} -rn --include "*Makefile" ${__pattern} | \ + ${AWK} -F'+=' '/+=/ {print $2}')) + __find_pattern=$(list_join "${__result}" '-name ' '.ko ' '-o ') KMODS=$(${FIND} "${MODDIR}" ${__find_pattern} | ${TR} '\n' ' ') @@ -245,6 +235,7 @@ profile_kselftests() { KMODS="$(${BASENAME} -a -s .ko ${KMODS})" + __kmods_needed=$(list_join "${__result}" '' '' ' ') __kmods_missing=$(list_diff "${__kmods_needed}" "${KMODS}") if [ ! -z "${__kmods_missing}" ]; then @@ -434,6 +425,20 @@ list_diff() { printf '%s' "${__diff}" } +# list_join() - Add prefix and suffix, with separator, to all tokens in list +# $1: List of tokens +# $2: Prefix +# $3: Suffix +# $4: Separator, used after prefix and before suffix +list_join() { + __s= + for __t in ${1}; do + __s="${2}${__t}${3}${4}${__s}" + done + __s=${__s%${4}} + printf '%s' "${__s}" +} + ################################################################################ |