Skip to contentSkip to conversation

scripts/tags.sh: don't parse `ls` for $ALLSOURCE_ARCHS generation

PATCH In review Joey Pabalinas 2 participants 7 messages May 18, 2018

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 scripts/tags.sh: don't parse `ls` for $ALLSOURCE_ARCHS generation

Parsing ls is fragile at best and _will_ fail when $tree contains spaces. Replace this with a glob-generated string and directly assign it to $ALLSOURCE_ARCHS (Kconfig is removed as it isn't an architecture); a subshell is implied by $(), so cd doesn't affect the current working directory.

 1 file changed, 2 insertions(+), 4 deletions(-)
scripts/tags.sh +2 -4
index 78e546ff689c2d5f40..e4aba2983f6272fc44 100755
@@ -29,14 +29,12 @@ fi
 ignore="$ignore ( -path ${tree}tools ) -prune -o"
 
 # Find all available archs
 find_all_archs()
 {
-	ALLSOURCE_ARCHS=""
-	for arch in `ls ${tree}arch`; do
-		ALLSOURCE_ARCHS="${ALLSOURCE_ARCHS} "${arch##\/}
-	done
+	ALLSOURCE_ARCHS="$(cd "${tree}arch/" && echo *)"
+	ALLSOURCE_ARCHS="${ALLSOURCE_ARCHS/Kconfig}"
 }
 
 # Detect if ALLSOURCE_ARCHS is set. If not, we assume SRCARCH
 if [ "${ALLSOURCE_ARCHS}" = "" ]; then
 	ALLSOURCE_ARCHS=${SRCARCH}
Signature · 1 line
2.17.0.rc1.35.g90bbd502d54fe92035.dirty
#1 lore raw

2018-05-18 15:25 GMT+09:00 Joey Pabalinas <[email protected]>:

Quoted 32 lines

Parsing ls is fragile at best and _will_ fail when $tree contains spaces. Replace this with a glob-generated string and directly assign it to $ALLSOURCE_ARCHS (Kconfig is removed as it isn't an architecture); a subshell is implied by $(), so cd doesn't affect the current working directory.

 1 file changed, 2 insertions(+), 4 deletions(-)
scripts/tags.sh +2 -5
index 78e546ff689c2d5f40..e4aba2983f6272fc44 100755
@@ -29,14 +29,12 @@ fi
 ignore="$ignore ( -path ${tree}tools ) -prune -o"
 
 # Find all available archs
 find_all_archs()
 {
-       ALLSOURCE_ARCHS=""
-       for arch in `ls ${tree}arch`; do
-               ALLSOURCE_ARCHS="${ALLSOURCE_ARCHS} "${arch##\/}
-       done
+       ALLSOURCE_ARCHS="$(cd "${tree}arch/" && echo *)"
+       ALLSOURCE_ARCHS="${ALLSOURCE_ARCHS/Kconfig}"
 }
 
 # Detect if ALLSOURCE_ARCHS is set. If not, we assume SRCARCH
 if [ "${ALLSOURCE_ARCHS}" = "" ]; then
        ALLSOURCE_ARCHS=${SRCARCH}
--
Quoted 2 lines

2.17.0.rc1.35.g90bbd502d54fe92035.dirty

I do not like hard-coding the file(s) in arch/.

Don't you have an idea to list only directories?
'find -type d' or 'ls -F' or something?

For example, the following worked for me, I wonder if there is a cleverer way...

# Detect if ALLSOURCE_ARCHS is set. If not, we assume SRCARCH if [ "${ALLSOURCE_ARCHS}" = "" ]; then

        ALLSOURCE_ARCHS=${SRCARCH}
elif [ "${ALLSOURCE_ARCHS}" = "all" ]; then
        ALLSOURCE_ARCHS="$(cd "${tree}arch" && ls -1 -F | sed -n 's:/$::p')"

fi

Signature · 2 lines
Best Regards
Masahiro Yamada
#2 lore raw
Quoted 4 lines · Masahiro Yamada

I do not like hard-coding the file(s) in arch/.

Don't you have an idea to list only directories?
'find -type d' or 'ls -F' or something?

How do you feel about the following?

Quoted 7 lines

# Detect if ALLSOURCE_ARCHS is set. If not, we assume SRCARCH if [ "${ALLSOURCE_ARCHS}" = "" ]; then

         ALLSOURCE_ARCHS="${SRCARCH}"
 elif [ "${ALLSOURCE_ARCHS}" = "all" ]; then
         ALLSOURCE_ARCHS="$(cd "${tree}arch/" && find . -maxdepth 1 -type d | paste -sd' ')"
         ALLSOURCE_ARCHS="${ALLSOURCE_ARCHS//[.\/]}"

fi

If something like that if acceptable, I'll use that for the v4.

Signature · 2 lines
Cheers,
Joey Pabalinas
#3 lore raw

2018-05-18 18:31 GMT+09:00 Joey Pabalinas <[email protected]>:

Quoted 13 lines · Masahiro Yamada
Quoted 4 lines

I do not like hard-coding the file(s) in arch/.

Don't you have an idea to list only directories?
'find -type d' or 'ls -F' or something?

How do you feel about the following?

Quoted 5 lines

# Detect if ALLSOURCE_ARCHS is set. If not, we assume SRCARCH if [ "${ALLSOURCE_ARCHS}" = "" ]; then

         ALLSOURCE_ARCHS="${SRCARCH}"
 elif [ "${ALLSOURCE_ARCHS}" = "all" ]; then
         ALLSOURCE_ARCHS="$(cd "${tree}arch/" && find . -maxdepth 1 -type d | paste -sd' ')"

Why is 'paste' necessary?

Quoted 8 lines
Quoted 2 lines
         ALLSOURCE_ARCHS="${ALLSOURCE_ARCHS//[.\/]}"

fi

If something like that if acceptable, I'll use that for the v4.

--
Cheers,
Joey Pabalinas

Signature · 2 lines
Best Regards
Masahiro Yamada
#4 lore raw
Quoted 1 line · Masahiro Yamada

Why is 'paste' necessary?

Without it newlines from find are retained from the find output (at least in bash when I tested it). Though it doesn't really matter here since we are feeding it to a for loop, I just wanted to be sure this didn't surprise someone in the future by squeezing the newlines into spaces.

Signature · 2 lines
Cheers,
Joey Pabalinas
#5 lore raw

2018-05-18 18:58 GMT+09:00 Joey Pabalinas <[email protected]>:

Quoted 9 lines · Masahiro Yamada
Quoted 1 line

Why is 'paste' necessary?

Without it newlines from find are retained from the find output (at least in bash when I tested it). Though it doesn't really matter here since we are feeding it to a for loop, I just wanted to be sure this didn't surprise someone in the future by squeezing the newlines into spaces.

Hmm, I would personally get upset about that code.

Does this work?
ALLSOURCE_ARCHS=$(find "${tree}"arch -mindepth 1 -maxdepth 1 -type d -printf ' %f')

It would leave one leading space, but I do not think it is a big deal.

It would be possible to chop it like follows, but I wonder if it is worth doing. ALLSOURCE_ARCHS=$(find "${tree}"arch -mindepth 1 -maxdepth 1 -type d -printf ' %f' | cut -c2-)

Quoted 3 lines

--
Cheers,
Joey Pabalinas

Signature · 2 lines
Best Regards
Masahiro Yamada
#6 lore raw
Quoted 3 lines · Masahiro Yamada

Does this work?
ALLSOURCE_ARCHS=$(find "${tree}"arch -mindepth 1 -maxdepth 1 -type d -printf ' %f')

Aha, that actually works perfectly.

Quoted 6 lines

It would leave one leading space, but I do not think it is a big deal.

It would be possible to chop it like follows, but I wonder if it is worth doing. ALLSOURCE_ARCHS=$(find "${tree}"arch -mindepth 1 -maxdepth 1 -type d -printf ' %f' | cut -c2-)

Yeah, the leading space isn't really something that is worth worrying about here in my opinion either.

I'll use this in my v4 then, thanks.

Signature · 2 lines
Cheers,
Joey Pabalinas