From d762bebc1c1a16c3fbb0d8fef024d4d995f9db51 Mon Sep 17 00:00:00 2001 From: Linux User Date: Tue, 1 Feb 2022 06:55:11 +0000 Subject: [PATCH] update shell scripts according to shellcheck recommendations and minor cleanup --- .travis/redox-toolchain.sh | 2 +- util/GHA-delete-GNU-workflow-logs.sh | 20 +++++++++--------- util/build-code_coverage.sh | 18 +++++++++------- util/build-gnu.sh | 4 ++-- util/publish.sh | 31 ++++++++++++---------------- util/run-gnu-test.sh | 3 ++- util/show-code_coverage.sh | 7 +++---- util/show-utils.sh | 16 ++++++-------- util/update-version.sh | 7 +++++-- 9 files changed, 52 insertions(+), 56 deletions(-) diff --git a/.travis/redox-toolchain.sh b/.travis/redox-toolchain.sh index 83bc8fc45..d8b43b489 100755 --- a/.travis/redox-toolchain.sh +++ b/.travis/redox-toolchain.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh rustup target add x86_64-unknown-redox sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys AA12E97F0881517F diff --git a/util/GHA-delete-GNU-workflow-logs.sh b/util/GHA-delete-GNU-workflow-logs.sh index 19e3311d4..f7406b831 100755 --- a/util/GHA-delete-GNU-workflow-logs.sh +++ b/util/GHA-delete-GNU-workflow-logs.sh @@ -15,21 +15,21 @@ ME_parent_dir_abs="$(realpath -mP -- "${ME_parent_dir}")" # * `gh` available? unset GH -gh --version 1>/dev/null 2>&1 -if [ $? -eq 0 ]; then export GH="gh"; fi +if gh --version 1>/dev/null 2>&1; then + export GH="gh" +else + echo "ERR!: missing \`gh\` (see install instructions at )" 1>&2 +fi # * `jq` available? unset JQ -jq --version 1>/dev/null 2>&1 -if [ $? -eq 0 ]; then export JQ="jq"; fi +if jq --version 1>/dev/null 2>&1; then + export JQ="jq" +else + echo "ERR!: missing \`jq\` (install with \`sudo apt install jq\`)" 1>&2 +fi if [ -z "${GH}" ] || [ -z "${JQ}" ]; then - if [ -z "${GH}" ]; then - echo 'ERR!: missing `gh` (see install instructions at )' 1>&2 - fi - if [ -z "${JQ}" ]; then - echo 'ERR!: missing `jq` (install with `sudo apt install jq`)' 1>&2 - fi exit 1 fi diff --git a/util/build-code_coverage.sh b/util/build-code_coverage.sh index 7ad3165fe..b92b7eb48 100755 --- a/util/build-code_coverage.sh +++ b/util/build-code_coverage.sh @@ -8,12 +8,13 @@ FEATURES_OPTION="--features feat_os_unix" -ME_dir="$(dirname -- $(readlink -fm -- "$0"))" +ME_dir="$(dirname -- "$(readlink -fm -- "$0")")" REPO_main_dir="$(dirname -- "${ME_dir}")" -cd "${REPO_main_dir}" +cd "${REPO_main_dir}" && echo "[ \"$PWD\" ]" +#shellcheck disable=SC2086 UTIL_LIST=$("${ME_dir}"/show-utils.sh ${FEATURES_OPTION}) CARGO_INDIVIDUAL_PACKAGE_OPTIONS="" for UTIL in ${UTIL_LIST}; do @@ -30,10 +31,12 @@ export RUSTC_WRAPPER="" ## NOTE: RUSTC_WRAPPER=='sccache' breaks code covera export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort" export RUSTDOCFLAGS="-Cpanic=abort" export RUSTUP_TOOLCHAIN="nightly-gnu" -cargo build ${FEATURES_OPTION} -cargo test --no-run ${FEATURES_OPTION} -cargo test --quiet ${FEATURES_OPTION} -cargo test --quiet ${FEATURES_OPTION} ${CARGO_INDIVIDUAL_PACKAGE_OPTIONS} +#shellcheck disable=SC2086 +{ cargo build ${FEATURES_OPTION} + cargo test --no-run ${FEATURES_OPTION} + cargo test --quiet ${FEATURES_OPTION} + cargo test --quiet ${FEATURES_OPTION} ${CARGO_INDIVIDUAL_PACKAGE_OPTIONS} +} export COVERAGE_REPORT_DIR if [ -z "${COVERAGE_REPORT_DIR}" ]; then COVERAGE_REPORT_DIR="${REPO_main_dir}/target/debug/coverage-nix"; fi @@ -47,8 +50,7 @@ mkdir -p "${COVERAGE_REPORT_DIR}" grcov . --output-type lcov --output-path "${COVERAGE_REPORT_DIR}/../lcov.info" --branch --ignore build.rs --ignore '/*' --ignore '[A-Za-z]:/*' --ignore 'C:/Users/*' --excl-br-line '^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()' # * build HTML # -- use `genhtml` if available for display of additional branch coverage information -genhtml --version 2>/dev/null 1>&2 -if [ $? -eq 0 ]; then +if genhtml --version 2>/dev/null 1>&2; then genhtml "${COVERAGE_REPORT_DIR}/../lcov.info" --output-directory "${COVERAGE_REPORT_DIR}" --branch-coverage --function-coverage | grep ": [0-9]" else grcov . --output-type html --output-path "${COVERAGE_REPORT_DIR}" --branch --ignore build.rs --ignore '/*' --ignore '[A-Za-z]:/*' --ignore 'C:/Users/*' --excl-br-line '^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()' diff --git a/util/build-gnu.sh b/util/build-gnu.sh index 8b1e4925b..a52d42107 100755 --- a/util/build-gnu.sh +++ b/util/build-gnu.sh @@ -15,7 +15,7 @@ if test ! -d ../gnulib; then fi -pushd $(pwd) +pushd "$PWD" make PROFILE=release BUILDDIR="$PWD/target/release/" cp "${BUILDDIR}/install" "${BUILDDIR}/ginstall" # The GNU tests rename this script before running, to avoid confusion with the make target @@ -49,7 +49,7 @@ make -j "$(nproc)" # Used to be 36. Reduced to 20 to decrease the log size for i in {00..20} do - make tests/factor/t${i}.sh + make "tests/factor/t${i}.sh" done # strip the long stuff diff --git a/util/publish.sh b/util/publish.sh index ae171e39c..6f4d9f237 100755 --- a/util/publish.sh +++ b/util/publish.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh set -e ARG="" @@ -6,26 +6,21 @@ if test "$1" != "--do-it"; then ARG="--dry-run --allow-dirty" fi -cd src/uucore/ -cargo publish $ARG -cd - -sleep 2s - -cd src/uucore_procs/ -cargo publish $ARG -cd - -sleep 2s - -cd src/uu/stdbuf/src/libstdbuf/ -cargo publish $ARG -cd - -sleep 2s +for dir in src/uucore/ src/uucore_procs/ src/uu/stdbuf/src/libstdbuf/ ; do + ( cd "$dir" + #shellcheck disable=SC2086 + cargo publish $ARG + ) + sleep 2s +done PROGS=$(ls -1d src/uu/*/) for p in $PROGS; do - cd $p - cargo publish $ARG - cd - + ( cd "$p" + #shellcheck disable=SC2086 + cargo publish $ARG + ) done +#shellcheck disable=SC2086 cargo publish $ARG diff --git a/util/run-gnu-test.sh b/util/run-gnu-test.sh index 483fc1be9..ff61e636e 100755 --- a/util/run-gnu-test.sh +++ b/util/run-gnu-test.sh @@ -1,6 +1,6 @@ #!/bin/bash # spell-checker:ignore (env/vars) BUILDDIR GNULIB SUBDIRS -cd "$(dirname "${BASH_SOURCE[0]}")/../.." +cd "$(dirname -- "$(readlink -fm -- "$0")")/../.." set -e BUILDDIR="${PWD}/uutils/target/release" GNULIB_DIR="${PWD}/gnulib" @@ -13,4 +13,5 @@ if test -n "$1"; then export RUN_TEST="TESTS=$1" fi +#shellcheck disable=SC2086 timeout -sKILL 2h make -j "$(nproc)" check $RUN_TEST SUBDIRS=. RUN_EXPENSIVE_TESTS=yes RUN_VERY_EXPENSIVE_TESTS=yes VERBOSE=no || : # Kill after 4 hours in case something gets stuck in make diff --git a/util/show-code_coverage.sh b/util/show-code_coverage.sh index 365041434..6226d856b 100755 --- a/util/show-code_coverage.sh +++ b/util/show-code_coverage.sh @@ -2,15 +2,14 @@ # spell-checker:ignore (vars) OSID -ME_dir="$(dirname -- $(readlink -fm -- "$0"))" +ME_dir="$(dirname -- "$(readlink -fm -- "$0")")" REPO_main_dir="$(dirname -- "${ME_dir}")" export COVERAGE_REPORT_DIR="${REPO_main_dir}/target/debug/coverage-nix" -"${ME_dir}/build-code_coverage.sh" -if [ $? -ne 0 ]; then exit 1 ; fi +if ! "${ME_dir}/build-code_coverage.sh"; then exit 1 ; fi case ";$OSID_tags;" in - *";wsl;"* ) powershell.exe -c $(wslpath -w "${COVERAGE_REPORT_DIR}"/index.html) ;; + *";wsl;"* ) powershell.exe -c "$(wslpath -w "${COVERAGE_REPORT_DIR}"/index.html)" ;; * ) xdg-open --version >/dev/null 2>&1 && xdg-open "${COVERAGE_REPORT_DIR}"/index.html || echo "report available at '\"${COVERAGE_REPORT_DIR}\"/index.html'" ;; esac ; diff --git a/util/show-utils.sh b/util/show-utils.sh index b4a613d9b..f69b42678 100755 --- a/util/show-utils.sh +++ b/util/show-utils.sh @@ -15,17 +15,13 @@ default_utils="base32 base64 basename cat cksum comm cp cut date dircolors dirna project_main_dir="${ME_parent_dir_abs}" # printf 'project_main_dir="%s"\n' "${project_main_dir}" -cd "${project_main_dir}" +cd "${project_main_dir}" && # `jq` available? -unset JQ -jq --version 1>/dev/null 2>&1 -if [ $? -eq 0 ]; then export JQ="jq"; fi - -if [ -z "${JQ}" ]; then - echo 'WARN: missing `jq` (install with `sudo apt install jq`); falling back to default (only fully cross-platform) utility list' 1>&2 - echo $default_utils +if ! jq --version 1>/dev/null 2>&1; then + echo "WARN: missing \`jq\` (install with \`sudo apt install jq\`); falling back to default (only fully cross-platform) utility list" 1>&2 + echo "$default_utils" else - cargo metadata $* --format-version 1 | jq -r "[.resolve.nodes[] | { id: .id, deps: [.deps[] | { name:.name, pkg:.pkg }] }] | .[] | select(.id|startswith(\"coreutils\")) | [.deps[] | select((.name|startswith(\"uu_\")) or (.pkg|startswith(\"uu_\")))] | [.[].pkg | match(\"^\\\w+\";\"g\")] | [.[].string | sub(\"^uu_\"; \"\")] | sort | join(\" \")" - # cargo metadata $* --format-version 1 | jq -r "[.resolve.nodes[] | { id: .id, deps: [.deps[] | { name:.name, pkg:.pkg }] }] | .[] | select(.id|startswith(\"coreutils\")) | [.deps[] | select((.name|startswith(\"uu_\")) or (.pkg|startswith(\"uu_\")))] | [.[].pkg | match(\"^\\\w+\";\"g\")] | [.[].string] | sort | join(\" \")" + cargo metadata "$*" --format-version 1 | jq -r "[.resolve.nodes[] | { id: .id, deps: [.deps[] | { name:.name, pkg:.pkg }] }] | .[] | select(.id|startswith(\"coreutils\")) | [.deps[] | select((.name|startswith(\"uu_\")) or (.pkg|startswith(\"uu_\")))] | [.[].pkg | match(\"^\\\w+\";\"g\")] | [.[].string | sub(\"^uu_\"; \"\")] | sort | join(\" \")" + # cargo metadata "$*" --format-version 1 | jq -r "[.resolve.nodes[] | { id: .id, deps: [.deps[] | { name:.name, pkg:.pkg }] }] | .[] | select(.id|startswith(\"coreutils\")) | [.deps[] | select((.name|startswith(\"uu_\")) or (.pkg|startswith(\"uu_\")))] | [.[].pkg | match(\"^\\\w+\";\"g\")] | [.[].string] | sort | join(\" \")" fi diff --git a/util/update-version.sh b/util/update-version.sh index 503f65e52..62b130bda 100755 --- a/util/update-version.sh +++ b/util/update-version.sh @@ -1,10 +1,10 @@ -#!/bin/bash +#!/bin/sh # This is a stupid helper. I will mass replace all versions (including other crates) # So, it should be triple-checked # How to ship a new release: # 1) update this script -# 2) run it: bash util/update-version.sh +# 2) run it: sh util/update-version.sh # 3) Do a spot check with "git diff" # 4) cargo test --release --features unix # 5) Run util/publish.sh in dry mode (it will fail as packages needs more recent version of uucore) @@ -23,6 +23,7 @@ UUCORE_TO="0.0.11" PROGS=$(ls -1d src/uu/*/Cargo.toml src/uu/stdbuf/src/libstdbuf/Cargo.toml Cargo.toml src/uu/base64/Cargo.toml) # update the version of all programs +#shellcheck disable=SC2086 sed -i -e "s|version = \"$FROM\"|version = \"$TO\"|" $PROGS # Update uucore_procs @@ -35,6 +36,8 @@ sed -i -e "s|= { optional=true, version=\"$FROM\", package=\"uu_|= { optional=tr # Update uucore itself sed -i -e "s|version = \"$UUCORE_FROM\"|version = \"$UUCORE_TO\"|" src/uucore/Cargo.toml # Update crates using uucore +#shellcheck disable=SC2086 sed -i -e "s|uucore = { version=\">=$UUCORE_FROM\",|uucore = { version=\">=$UUCORE_TO\",|" $PROGS # Update crates using uucore_procs +#shellcheck disable=SC2086 sed -i -e "s|uucore_procs = { version=\">=$UUCORE_PROCS_FROM\",|uucore_procs = { version=\">=$UUCORE_PROCS_TO\",|" $PROGS