Forráskód Böngészése

utils/docker-run: fix shellcheck errors

In utils/test-pkg line 8:
    if [ ! -z "${TEMP_CONF}" ]; then
         ^-- SC2236: Use -n instead of ! -z.

In utils/test-pkg line 75:
        TEMP_CONF=$(mktemp /tmp/test-${pkg}-config.XXXXXX)
                                     ^----^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
        TEMP_CONF=$(mktemp /tmp/test-"${pkg}"-config.XXXXXX)

In utils/test-pkg line 76:
        echo "${pkg_br_name}=y" > ${TEMP_CONF}
                                  ^----------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
        echo "${pkg_br_name}=y" > "${TEMP_CONF}"

In utils/test-pkg line 86:
    if [ ${random} -gt 0 ]; then
         ^-------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
    if [ "${random}" -gt 0 ]; then

In utils/test-pkg line 90:
    if [ ${number} -gt 0 ]; then
         ^-------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
    if [ "${number}" -gt 0 ]; then

In utils/test-pkg line 109:
    toolchains=($(sed -r -e 's/,.*//; /internal/d; /^#/d; /^$/d;' "${toolchains_csv}" \
                ^-- SC2207: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

In utils/test-pkg line 110:
                  |if [ ${random} -gt 0 ]; then \
                        ^-------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
                  |if [ "${random}" -gt 0 ]; then \

In utils/test-pkg line 111:
                      sort -R |head -n ${random}
                                       ^-------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
                      sort -R |head -n "${random}"

In utils/test-pkg line 121:
    if [ ${nb_tc} -eq 0 ]; then
         ^------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
    if [ "${nb_tc}" -eq 0 ]; then

In utils/test-pkg line 134:
        printf "%40s [%*d/%d]: " "${toolchain}" ${#nb_tc} ${nb} ${nb_tc}
                                                          ^---^ SC2086: Double quote to prevent globbing and word splitting.
                                                                ^------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
        printf "%40s [%*d/%d]: " "${toolchain}" ${#nb_tc} "${nb}" "${nb_tc}"

In utils/test-pkg line 146:
        ${nb} ${nb_skip} ${nb_fail} ${nb_legal} ${nb_show}
        ^---^ SC2086: Double quote to prevent globbing and word splitting.
              ^--------^ SC2086: Double quote to prevent globbing and word splitting.
                         ^--------^ SC2086: Double quote to prevent globbing and word splitting.
                                    ^---------^ SC2086: Double quote to prevent globbing and word splitting.
                                                ^--------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
        "${nb}" "${nb_skip}" "${nb_fail}" "${nb_legal}" "${nb_show}"

In utils/test-pkg line 160:
    CONFIG_= support/kconfig/merge_config.sh -O "${dir}" \
            ^-- SC1007: Remove space after = if trying to assign a value (for empty string, use var='' ... ).

In utils/test-pkg line 181:
    if [ ${prepare_only} -eq 1 ]; then
         ^-------------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
    if [ "${prepare_only}" -eq 1 ]; then

For more information:
  https://www.shellcheck.net/wiki/SC1007 -- Remove space after = if trying to...
  https://www.shellcheck.net/wiki/SC2207 -- Prefer mapfile or read -a to spli...
  https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...

The suggestions from shellcheck can be applied.

This script already uses bash so we can rely on mapfile.

The warning about CONFIG_= assignment misinterpreted the intention: we
don't want to assign to CONFIG_, we want to clear it from the
environment. Spell this as CONFIG_="".

Signed-off-by: Arnout Vandecappelle <arnout@mind.be>
Arnout Vandecappelle 2 éve
szülő
commit
dab7a87714
1 módosított fájl, 20 hozzáadás és 21 törlés
  1. 20 21
      utils/test-pkg

+ 20 - 21
utils/test-pkg

@@ -5,7 +5,7 @@ TOOLCHAINS_CSV='support/config-fragments/autobuild/toolchain-configs.csv'
 TEMP_CONF=""
 
 do_clean() {
-    if [ ! -z "${TEMP_CONF}" ]; then
+    if [ -n "${TEMP_CONF}" ]; then
         rm -f "${TEMP_CONF}"
     fi
 }
@@ -72,8 +72,8 @@ main() {
     if [ -z "${cfg}" ]; then
         pkg_br_name="${pkg//-/_}"
         pkg_br_name="BR2_PACKAGE_${pkg_br_name^^}"
-        TEMP_CONF=$(mktemp /tmp/test-${pkg}-config.XXXXXX)
-        echo "${pkg_br_name}=y" > ${TEMP_CONF}
+        TEMP_CONF="$(mktemp /tmp/test-"${pkg}"-config.XXXXXX)"
+        echo "${pkg_br_name}=y" > "${TEMP_CONF}"
         cfg="${TEMP_CONF}"
     fi
     if [ ! -e "${cfg}" ]; then
@@ -83,15 +83,15 @@ main() {
         dir="${HOME}/br-test-pkg"
     fi
 
-    if [ ${random} -gt 0 ]; then
+    if [ "${random}" -gt 0 ]; then
         mode=$((mode+1))
     fi
 
-    if [ ${number} -gt 0 ]; then
+    if [ "${number}" -gt 0 ]; then
         mode=$((mode+1))
     fi
 
-    if [ ${all} -eq 1 ]; then
+    if [ "${all}" -eq 1 ]; then
         mode=$((mode+1))
     fi
 
@@ -106,19 +106,18 @@ main() {
     # Extract the URLs of the toolchains; drop internal toolchains
     # E.g.: http://server/path/to/name.config,arch,libc
     #  -->  http://server/path/to/name.config
-    toolchains=($(sed -r -e 's/,.*//; /internal/d; /^#/d; /^$/d;' "${toolchains_csv}" \
-                  |if [ ${random} -gt 0 ]; then \
-                      sort -R |head -n ${random}
-                  elif [ ${number} -gt 0 ]; then \
-                      head -n ${number}
-                  else
-                      sort
-                  fi
-                 )
-               )
+    mapfile -t toolchains < <(sed -r -e 's/,.*//; /internal/d; /^#/d; /^$/d;' "${toolchains_csv}" \
+                                | if [ "${random}" -gt 0 ]; then \
+                                    sort -R | head -n "${random}"
+                                elif [ "${number}" -gt 0 ]; then \
+                                    head -n "${number}"
+                                else
+                                    sort
+                                fi
+                             )
 
     nb_tc="${#toolchains[@]}"
-    if [ ${nb_tc} -eq 0 ]; then
+    if [ "${nb_tc}" -eq 0 ]; then
         printf "error: no toolchain found (networking issue?)\n" >&2; exit 1
     fi
 
@@ -131,7 +130,7 @@ main() {
         : $((nb++))
         toolchain="$(basename "${toolchainconfig}" .config)"
         build_dir="${dir}/${toolchain}"
-        printf "%40s [%*d/%d]: " "${toolchain}" ${#nb_tc} ${nb} ${nb_tc}
+        printf "%40s [%*d/%d]: " "${toolchain}" ${#nb_tc} "${nb}" "${nb_tc}"
         build_one "${build_dir}" "${toolchainconfig}" "${cfg}" "${pkg}" "${prepare_only}" && ret=0 || ret=${?}
         case ${ret} in
         (0) printf "OK\n";;
@@ -143,7 +142,7 @@ main() {
     done
 
     printf "%d builds, %d skipped, %d build failed, %d legal-info failed, %d show-info failed\n" \
-        ${nb} ${nb_skip} ${nb_fail} ${nb_legal} ${nb_show}
+        "${nb}" "${nb_skip}" "${nb_fail}" "${nb_legal}" "${nb_show}"
 
     return $((nb_fail + nb_legal))
 }
@@ -157,7 +156,7 @@ build_one() {
 
     mkdir -p "${dir}"
 
-    CONFIG_= support/kconfig/merge_config.sh -O "${dir}" \
+    CONFIG_="" support/kconfig/merge_config.sh -O "${dir}" \
         "${toolchainconfig}" "support/config-fragments/minimal.config" "${cfg}" \
         >> "${dir}/logfile" 2>&1
     # We want all the options from the snippet to be present as-is (set
@@ -178,7 +177,7 @@ build_one() {
     rm -f "${dir}/missing.config"
 
     # Defer building the job to the caller (e.g. a gitlab pipeline)
-    if [ ${prepare_only} -eq 1 ]; then
+    if [ "${prepare_only}" -eq 1 ]; then
         return 0
     fi