From 41f7f39551857836e691da81580296ba5acf6ac3 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Sat, 22 May 2021 22:49:34 -0700 Subject: [PATCH] hack: add shellcheck Signed-off-by: Tonis Tiigi --- .github/workflows/validate.yml | 1 + base/xx-apk | 47 +++++++---- base/xx-apt | 31 +++----- base/xx-cc | 103 ++++++++++++------------- base/xx-go | 23 ++---- base/xx-info | 29 +++---- base/xx-verify | 18 ++--- base/xx-windres | 40 +++++----- hack/dockerfiles/shellcheck.Dockerfile | 5 ++ hack/shellcheck | 8 ++ 10 files changed, 154 insertions(+), 151 deletions(-) create mode 100644 hack/dockerfiles/shellcheck.Dockerfile create mode 100755 hack/shellcheck diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index a98e84e..2eb9286 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -21,3 +21,4 @@ jobs: name: Run run: | ./hack/validate-shfmt + ./hack/shellcheck diff --git a/base/xx-apk b/base/xx-apk index 054afd9..0568575 100755 --- a/base/xx-apk +++ b/base/xx-apk @@ -4,8 +4,8 @@ set -e if [ -z "$XX_APK_NOLOCK" ]; then lock="/var/lock/xx-apk" - exec 200>$lock - flock -x 200 + exec 9>$lock + flock -x 9 export XX_APK_NOLOCK=1 fi @@ -14,7 +14,7 @@ if [ -n "$XX_DEBUG_APK" ]; then fi for l in $(xx-info env); do - export $l + export "${l?}" done if [ "${TARGETOS}" != "linux" ]; then @@ -44,15 +44,15 @@ setup() { cp /etc/apk/repositories "$apk_dir/" mkdir "$apk_dir/keys" mkdir "$apk_dir/protected_paths.d" - echo $XX_PKG_ARCH >"$apk_dir/arch" + echo "$XX_PKG_ARCH" >"$apk_dir/arch" apk add --no-cache --initdb -p "/${XX_TRIPLE}" --allow-untrusted alpine-keys if [ -d "/etc/apk/cache" ]; then - mkdir -p /etc/apk/cache/_$XX_PKG_ARCH - ln -s /etc/apk/cache/_$XX_PKG_ARCH "$apk_dir/cache" + mkdir -p "/etc/apk/cache/_$XX_PKG_ARCH" + ln -s "/etc/apk/cache/_$XX_PKG_ARCH" "$apk_dir/cache" fi - touch $done_file + touch "$done_file" } clean() { @@ -64,25 +64,38 @@ clean() { echo >&2 "invalid triple root $XX_TRIPLE" exit 1 fi - rm -rf "/${XX_TRIPLE}" + rm -rf "/${XX_TRIPLE:?}" } cmd() { setup - root="-p /" + root="/" if xx-info is-cross; then - root="-p /${XX_TRIPLE}" + root="/${XX_TRIPLE}" fi - args=$(echo "$@" | sed "s/xx-c-essentials/musl-dev gcc/" | sed "s/xx-cxx-essentials/g++/") - if [ "$#" = "0" ]; then - root="" - else - echo "+ apk $root" "$args" + n=$# + for a in "$@"; do + if [ $# = $n ]; then set --; fi + case "$a" in + "xx-c-essentials") + set -- "$@" musl-dev gcc + ;; + "xx-cxx-essentials") + set -- "$@" g++ + ;; + *) + set -- "$@" "$a" + ;; + esac + done + if [ "$#" != "0" ]; then + set -- "--root" "$root" "$@" + echo "+ apk " "$@" fi - apk $root $args + apk "$@" if xx-info is-cross; then if [ -z "$XX_APK_KEEP_BINARIES" ]; then - rm -rf /${XX_TRIPLE}/usr/bin/* + rm -rf "/${XX_TRIPLE:?}/usr/bin/*" fi fi } diff --git a/base/xx-apt b/base/xx-apt index 4241466..7f5639c 100755 --- a/base/xx-apt +++ b/base/xx-apt @@ -14,7 +14,7 @@ if [ -n "$XX_DEBUG_APT" ]; then fi for l in $(xx-info env); do - export $l + export "${l?}" done if [ "${TARGETOS}" != "linux" ]; then @@ -34,9 +34,9 @@ esac packages= parsed= -args= - +n=$# for p in "$@"; do + if [ $# = $n ]; then set --; fi arg= case "$p" in -*) @@ -59,11 +59,7 @@ for p in "$@"; do ;; esac if [ -n "$arg" ]; then - if [ -z "$args" ]; then - args="$arg" - else - args="${args} ${arg}" - fi + set -- "$@" "$arg" fi done @@ -90,13 +86,13 @@ packages2= for p in ${packages}; do if [ "${p}" = "xx-c-essentials" ]; then p="libc6-dev" - if apt info libgcc-10-dev:${XX_PKG_ARCH}; then + if apt info "libgcc-10-dev:${XX_PKG_ARCH}"; then p="$p libgcc-10-dev" else p="$p libgcc-8-dev" fi elif [ "${p}" = "xx-cxx-essentials" ]; then - if apt info libstdc++-10-dev:${XX_PKG_ARCH}; then + if apt info "libstdc++-10-dev:${XX_PKG_ARCH}"; then p="libstdc++-10-dev" else p="libstdc++-8-dev" @@ -109,24 +105,19 @@ for p in ${packages}; do fi done -new= for p in ${packages2}; do n= if [ -n "$nocross" ]; then n=${p} - elif apt info ${p}-${suffix} >/dev/null 2>/dev/null; then + elif apt info "${p}-${suffix}" >/dev/null 2>/dev/null; then n="${p}-${suffix}" - elif [ -n "${XX_APT_PREFER_CROSS}" ] && apt info ${p}-${XX_PKG_ARCH}-cross >/dev/null 2>/dev/null; then + elif [ -n "${XX_APT_PREFER_CROSS}" ] && apt info "${p}-${XX_PKG_ARCH}-cross" >/dev/null 2>/dev/null; then n="${p}-${XX_PKG_ARCH}-cross" else n="${p}:${XX_PKG_ARCH}" fi - if [ -z "$new" ]; then - new="$n" - else - new="${new} ${n}" - fi + set -- "$@" "$n" done -echo >&2 "+ apt ${args} ${new}" -exec apt ${args} ${new} +echo >&2 "+ apt " "$@" +exec apt "$@" diff --git a/base/xx-cc b/base/xx-cc index 755629c..cc3098b 100755 --- a/base/xx-cc +++ b/base/xx-cc @@ -119,7 +119,6 @@ EOF } macos_sdk_path=/xx-sdk/MacOSX11.1.sdk -macos_sdk_version=11.1 detectTargetOSArch() { targetos="" @@ -135,7 +134,7 @@ detectTargetOSArch() { targetos=$(xx-info os) fi - arch=$(echo $target | cut -d- -f1) + arch=$(echo "$target" | cut -d- -f1) targetarch="" targetvariant="" @@ -169,11 +168,6 @@ detectMacOSSDK() { if [ -d "/xx-sdk" ]; then for f in /xx-sdk/MacOSX*.sdk; do macos_sdk_path="$f" - trim="${sdk_path#/xx-sdk/MacOSX}" - trim="${trim%.sdk}" - if [ -n "$trim" ]; then - macos_sdk_version=$trim - fi break done fi @@ -194,8 +188,8 @@ ld64-signed-linux-armv7 1dbf5be507a73768bb1ee72d3325020640cca614 EOT ) - file="ld64-signed-$(TARGETPLATFORM= TARGETPAIR= TARGETOS= TARGETARCH= TARGETVARIANT= xx-info os)-$(TARGETPLATFORM= TARGETPAIR= TARGETOS= TARGETARCH= TARGETVARIANT= xx-info arch)$(TARGETPLATFORM= TARGETPAIR= TARGETOS= TARGETARCH= TARGETVARIANT= xx-info variant)" - sha=$(echo $shas | grep $file | cut -d' ' -f2 || true) + file="ld64-signed-$(TARGETPLATFORM='' TARGETPAIR='' TARGETOS='' TARGETARCH='' TARGETVARIANT='' xx-info os)-$(TARGETPLATFORM='' TARGETPAIR='' TARGETOS='' TARGETARCH='' TARGETVARIANT='' xx-info arch)$(TARGETPLATFORM='' TARGETPAIR='' TARGETOS='' TARGETARCH='' TARGETVARIANT='' xx-info variant)" + sha=$(echo "$shas" | grep "$file" | cut -d' ' -f2 || true) if [ -z "$sha" ]; then return @@ -205,27 +199,27 @@ EOT for m in $mirrors; do # busybox wget - if ! wget $m/$file.tar.gz -q -O $tmpdir/$file.tar.gz; then + if ! wget "$m/$file.tar.gz" -q -O "$tmpdir/$file.tar.gz"; then continue fi - if ! wget --no-check-certificate $m/$file.tar.gz -q -O $tmpdir/$file.tar.gz; then + if ! wget --no-check-certificate "$m/$file.tar.gz" -q -O "$tmpdir/$file.tar.gz"; then continue fi - if [ -z "XX_DOWNLOAD_NO_VALIDATE" ]; then - sha2="$(sha1sum $tmpdir/$file.tar.gz | cut -d' ' -f2)" + if [ -z "$XX_DOWNLOAD_NO_VALIDATE" ]; then + sha2="$(sha1sum "$tmpdir/$file.tar.gz" | cut -d' ' -f2)" if [ "$sha" != "$sha2" ]; then echo >&2 "checksum mismatch for $file.tar.gz $sha $sha2" - rm $tmpdir/$file.tar.gz + rm "$tmpdir/$file.tar.gz" continue fi fi - tar xzf $tmpdir/$file.tar.gz -C /usr/bin - ln -s ld64.signed /usr/bin/$target-ld - rm $tmpdir/$file.tar.gz + tar xzf "$tmpdir/$file.tar.gz" -C /usr/bin + ln -s ld64.signed "/usr/bin/$target-ld" + rm "$tmpdir/$file.tar.gz" break done - rm -r $tmpdir + rm -r "$tmpdir" if [ -f "/usr/bin/$target-ld" ]; then linker="/usr/bin/$target-ld" fi @@ -312,8 +306,8 @@ windows-amd64-ld-linux-s390x 92777b3e15b6bdde0c106a86466abc9d0d9cdb94 EOT ) - file="$targetos-$targetarch$targetvariant-ld-$(TARGETPLATFORM= TARGETPAIR= TARGETOS= TARGETARCH= TARGETVARIANT= xx-info os)-$(TARGETPLATFORM= TARGETPAIR= TARGETOS= TARGETARCH= TARGETVARIANT= xx-info arch)$(TARGETPLATFORM= TARGETPAIR= TARGETOS= TARGETARCH= TARGETVARIANT= xx-info variant)" - sha=$(echo $shas | grep $file | cut -d' ' -f2 || true) + file="$targetos-$targetarch$targetvariant-ld-$(TARGETPLATFORM='' TARGETPAIR='' TARGETOS='' TARGETARCH='' TARGETVARIANT='' xx-info os)-$(TARGETPLATFORM='' TARGETPAIR='' TARGETOS='' TARGETARCH='' TARGETVARIANT='' xx-info arch)$(TARGETPLATFORM='' TARGETPAIR='' TARGETOS='' TARGETARCH='' TARGETVARIANT='' xx-info variant)" + sha=$(echo "$shas" | grep "$file" | cut -d' ' -f2 || true) if [ -z "$sha" ]; then return @@ -323,36 +317,36 @@ EOT for m in $mirrors; do # busybox wget - if ! wget $m/$file.tar.gz -q -O $tmpdir/$file.tar.gz; then + if ! wget "$m/$file.tar.gz" -q -O "$tmpdir/$file.tar.gz"; then continue fi - if ! wget --no-check-certificate $m/$file.tar.gz -q -O $tmpdir/$file.tar.gz; then + if ! wget --no-check-certificate "$m/$file.tar.gz" -q -O "$tmpdir/$file.tar.gz"; then continue fi - if [ -z "XX_DOWNLOAD_NO_VALIDATE" ]; then - sha2="$(sha1sum $tmpdir/$file.tar.gz | cut -d' ' -f2)" + if [ -z "$XX_DOWNLOAD_NO_VALIDATE" ]; then + sha2="$(sha1sum "$tmpdir/$file.tar.gz" | cut -d' ' -f2)" if [ "$sha" != "$sha2" ]; then echo >&2 "checksum mismatch for $file.tar.gz $sha $sha2" - rm $tmpdir/$file.tar.gz + rm "$tmpdir/$file.tar.gz" continue fi fi - tar xzf $tmpdir/$file.tar.gz -C /usr/bin - ln -s "$targetos-$targetarch$targetvariant-ld" /usr/bin/$target-ld - rm $tmpdir/$file.tar.gz + tar xzf "$tmpdir/$file.tar.gz" -C /usr/bin + ln -s "$targetos-$targetarch$targetvariant-ld" "/usr/bin/$target-ld" + rm "$tmpdir/$file.tar.gz" break done - rm -r $tmpdir + rm -r "$tmpdir" if [ -f "/usr/bin/$target-ld" ]; then linker="/usr/bin/$target-ld" fi } -basename=$(basename $0) +basename=$(basename "$0") name=${basename#xx-} -: ${XX_CC_PREFER_LINKER=lld} +: "${XX_CC_PREFER_LINKER=lld}" if [ "$name" = "cc" ]; then name="clang" @@ -421,7 +415,7 @@ setup() { if [ -z "$linker" ] && [ "${XX_CC_PREFER_LINKER}" = "gold" ]; then if [ -z "${linker}" ]; then - ld=$(which $target-gold 2>/dev/null || true) + ld=$(which "$target-gold" 2>/dev/null || true) if [ -n "$ld" ]; then linker=${ld} fi @@ -432,7 +426,7 @@ setup() { fi if [ -z "${linker}" ]; then - ld=$(which $target-ld 2>/dev/null || true) + ld=$(which "$target-ld" 2>/dev/null || true) if [ -n "$ld" ]; then linker=${ld} fi @@ -442,7 +436,6 @@ setup() { fi if [ -z "${linker}" ] && which ld >/dev/null 2>/dev/null; then - support=$(ld -V 2>/dev/null || true) exp=$targetarch if [ "$exp" = "amd64" ]; then exp="x86_64" @@ -460,7 +453,7 @@ setup() { exp="riscv" fi if ld -V 2>/dev/null | grep $exp >/dev/null; then - ln -s $(which ld) /usr/bin/${target}-ld + ln -s "$(which ld)" "/usr/bin/${target}-ld" linker="/usr/bin/${target}-ld" fi fi @@ -500,13 +493,13 @@ setup() { if [ -f /usr/bin/$f ]; then # there seems to be a bug in llvm that prevents config to be loaded if target contains a dot , like macos10.4 if echo "${target}" | grep '\.' 2>/dev/null >/dev/null; then - cat </usr/bin/${target}-$f + cat <"/usr/bin/${target}-$f" #!/usr/bin/env sh $f --config /usr/bin/${target}.cfg "\$@" EOT - chmod +x /usr/bin/${target}-$f + chmod +x "/usr/bin/${target}-$f" else - ln -s $f /usr/bin/${target}-$f + ln -s $f "/usr/bin/${target}-$f" fi else echo >&2 "/usr/bin/$f not found: skipping" @@ -517,13 +510,13 @@ EOT if ! which "${target}-${f}" >/dev/null 2>/dev/null; then if [ -f "/usr/bin/llvm-${f}" ]; then if echo "${target}" | grep '\.' 2>/dev/null >/dev/null; then - cat </usr/bin/${target}-$f + cat <"/usr/bin/${target}-$f" #!/usr/bin/env sh llvm-$f "\$@" EOT - chmod +x /usr/bin/${target}-$f + chmod +x "/usr/bin/${target}-$f" else - ln -s llvm-$f /usr/bin/${target}-$f + ln -s "llvm-$f" "/usr/bin/${target}-$f" fi fi fi @@ -531,18 +524,18 @@ EOT if [ "$targetos" = "windows" ]; then if which llvm-rc 2>/dev/null >/dev/null; then - if [ ! -f /usr/bin/${target}-windres ] && [ ! -h /usr/bin/${target}-windres ]; then - cat </usr/bin/${target}-windres + if [ ! -f "/usr/bin/${target}-windres" ] && [ ! -h "/usr/bin/${target}-windres" ]; then + cat <"/usr/bin/${target}-windres" #!/usr/bin/env sh exec xx-windres --target=${target} "\$@" EOT - chmod +x /usr/bin/${target}-windres + chmod +x "/usr/bin/${target}-windres" fi fi fi config="--target=${target} -fuse-ld=${linker}" - nativeTarget=$(TARGETPLATFORM= TARGETARCH= TARGETOS= TARGETPAIR= xx-info triple) + nativeTarget=$(TARGETPLATFORM='' TARGETARCH='' TARGETOS='' TARGETPAIR='' xx-info triple) if [ "${nativeTarget}" != "${target}" ]; then if [ "$targetos" = "darwin" ]; then detectMacOSSDK @@ -552,20 +545,20 @@ EOT elif [ -f /etc/alpine-release ]; then config="${config} --sysroot=/${target}/" - cat </usr/bin/${target}-pkg-config + cat <"/usr/bin/${target}-pkg-config" #!/usr/bin/env sh export PKG_CONFIG_SYSROOT_DIR=/${target} exec pkg-config "\$@" EOT - chmod +x /usr/bin/${target}-pkg-config + chmod +x "/usr/bin/${target}-pkg-config" fi - elif [ ! -f /usr/bin/${target}-pkg-config ] && [ ! -h /usr/bin/${target}-pkg-config ]; then - ln -s pkg-config /usr/bin/${target}-pkg-config + elif [ ! -f "/usr/bin/${target}-pkg-config" ] && [ ! -h "/usr/bin/${target}-pkg-config" ]; then + ln -s pkg-config "/usr/bin/${target}-pkg-config" fi - f=$(dirname $(readlink -f $(which /usr/bin/clang)))/${target}.cfg - echo $config >${f} + f="$(dirname "$(readlink -f "$(which /usr/bin/clang)")")/${target}.cfg" + echo "$config" >"${f}" if [ "${f}" != "/usr/bin/${target}.cfg" ]; then - ln -s ${f} /usr/bin/${target}.cfg + ln -s "${f}" "/usr/bin/${target}.cfg" fi if [ "${targetos}" = "darwin" ]; then @@ -657,13 +650,13 @@ fi # if print & target then setup and print current target if [ -n "${target}" ] && [ -n "${printTarget}" ]; then setup - echo ${target} + echo "${target}" exit 0 fi if [ -n "${printCmake}" ]; then setup - echo -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_ASM_COMPILER=clang -DPKG_CONFIG_EXECUTABLE=$(xx-clang --print-prog-name=pkg-config) -DCMAKE_C_COMPILER_TARGET=$(xx-clang --print-target-triple) -DCMAKE_CXX_COMPILER_TARGET=$(xx-clang++ --print-target-triple) -DCMAKE_ASM_COMPILER_TARGET=$(xx-clang --print-target-triple) + echo -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_ASM_COMPILER=clang -DPKG_CONFIG_EXECUTABLE="$(xx-clang --print-prog-name=pkg-config)" -DCMAKE_C_COMPILER_TARGET="$(xx-clang --print-target-triple)" -DCMAKE_CXX_COMPILER_TARGET="$(xx-clang++ --print-target-triple)" -DCMAKE_ASM_COMPILER_TARGET="$(xx-clang --print-target-triple)" exit 0 fi @@ -691,7 +684,7 @@ fi if [ -z "$target" ] && [ -f /etc/llvm/xx-default.cfg ]; then exec /usr/bin/$name --config /etc/llvm/xx-default.cfg "$@" elif [ -f "/usr/bin/${target}.cfg" ]; then - exec /usr/bin/$name --config /usr/bin/${target}.cfg "$@" + exec /usr/bin/$name --config "/usr/bin/${target}.cfg" "$@" else exec /usr/bin/$name "$@" fi diff --git a/base/xx-go b/base/xx-go index 2dfe442..20a211c 100755 --- a/base/xx-go +++ b/base/xx-go @@ -3,14 +3,14 @@ set -e for l in $(xx-info env); do - export $l + export "${l?}" done export GOOS=${TARGETOS} export GOARCH=${TARGETARCH} if [ "$TARGETARCH" = "arm" ]; then - if [ ! -z "$TARGETVARIANT" ]; then + if [ -n "$TARGETVARIANT" ]; then case "$TARGETVARIANT" in "v5") export GOARM="5" @@ -31,26 +31,17 @@ if [ "$GOOS" = "wasi" ]; then export GOOS="js" fi -cgo_enabled= c_set= cxx_set= ar_set= pkgconfig_set= -if [ "$CGO_ENABLED" = "1" ]; then - cgo_enabled=1 -fi - -if [ -z "$CGO_ENABLED" ] && ! xx-info is-cross; then - cgo_enabled=1 -fi - -if which $XX_TRIPLE-gcc >/dev/null 2>/dev/null; then +if which "$XX_TRIPLE-gcc" >/dev/null 2>/dev/null; then export CC=$XX_TRIPLE-gcc c_set=1 fi -if which $XX_TRIPLE-g++ >/dev/null 2>/dev/null; then +if which "$XX_TRIPLE-g++" >/dev/null 2>/dev/null; then export CXX=$XX_TRIPLE-g++ cxx_set=1 fi @@ -65,12 +56,12 @@ if which clang >/dev/null 2>/dev/null; then fi fi -if which $XX_TRIPLE-ar >/dev/null 2>/dev/null; then +if which "$XX_TRIPLE-ar" >/dev/null 2>/dev/null; then export AR=$XX_TRIPLE-ar ar_set=1 fi -if which $XX_TRIPLE-pkg-config >/dev/null 2>/dev/null; then +if which "$XX_TRIPLE-pkg-config" >/dev/null 2>/dev/null; then export PKG_CONFIG=$XX_TRIPLE-pkg-config pkgconfig_set=1 fi @@ -84,7 +75,7 @@ wrap() { if [ -z "$f" ]; then return fi - mkdir -p $(dirname "$f") + mkdir -p "$(dirname "$f")" echo "GOOS=$GOOS" >"$f" echo "GOARCH=$GOARCH" >>"$f" if [ -n "$GOARM" ]; then diff --git a/base/xx-info b/base/xx-info index 26b4a78..e3e6175 100755 --- a/base/xx-info +++ b/base/xx-info @@ -1,23 +1,23 @@ #!/usr/bin/env sh -: ${TARGETPLATFORM=} -: ${TARGETOS=} -: ${TARGETARCH=} -: ${TARGETVARIANT=} -: ${MACOSX_VERSION_MIN=} +: "${TARGETPLATFORM=}" +: "${TARGETOS=}" +: "${TARGETARCH=}" +: "${TARGETVARIANT=}" +: "${MACOSX_VERSION_MIN=}" -: ${XX_MARCH=unknown} +: "${XX_MARCH=unknown}" # https://pkgs.alpinelinux.org/packages -: ${XX_ALPINE_ARCH=unknown} +: "${XX_ALPINE_ARCH=unknown}" # https://www.debian.org/ports/ -: ${XX_DEBIAN_ARCH=unknown} -: ${XX_TRIPLE=unknown-unknown-none} -: ${XX_VENDOR=unknown} -: ${XX_LIBC=} +: "${XX_DEBIAN_ARCH=unknown}" +: "${XX_TRIPLE=unknown-unknown-none}" +: "${XX_VENDOR=unknown}" +: "${XX_LIBC=}" usage() { cat >&2 </dev/null; then XX_VENDOR=$ID fi diff --git a/base/xx-verify b/base/xx-verify index 6639a73..c87144c 100755 --- a/base/xx-verify +++ b/base/xx-verify @@ -14,13 +14,13 @@ if [ -n "$XX_DEBUG_VERIFY" ]; then fi for l in $(xx-info env); do - export $l + export "${l?}" done setup() { if ! which file >/dev/null 2>/dev/null; then if which apk >/dev/null; then - apk add --no-cache file >$1 + apk add --no-cache file >"$1" elif which apt >/dev/null; then apt update && apt install -y file else @@ -32,7 +32,7 @@ setup() { usage() { cat >&2 <&1) - - if [ $? != 0 ]; then + if ! out=$(file -L -b "${f}" 2>&1); then echo >&2 "failed to run file for ${f}: $out" exit 1 fi @@ -103,7 +101,7 @@ for f in "$@"; do exit 1 fi - if ! echo $out | grep "$expOS" >/dev/null; then + if ! echo "$out" | grep "$expOS" >/dev/null; then echo >&2 "file ${f} does not match expected target OS ${TARGETOS}: $out" exit 1 fi @@ -191,20 +189,20 @@ for f in "$@"; do exit 1 fi - if ! echo $out | grep "$expArch" >/dev/null; then + if ! echo "$out" | grep "$expArch" >/dev/null; then echo >&2 "file ${f} does not match expected target architecture ${TARGETARCH}: $out" exit 1 fi if [ -n "$expArch2" ]; then - if ! echo $out | grep "$expArch2" >/dev/null; then + if ! echo "$out" | grep "$expArch2" >/dev/null; then echo >&2 "file ${f} does not match expected endianness for ${TARGETARCH}: $out" exit 1 fi fi if [ -n "$static" ] && [ "$TARGETOS" = "linux" ]; then - if ! echo $out | grep "statically linked" >/dev/null; then + if ! echo "$out" | grep "statically linked" >/dev/null; then echo >&2 "file ${f} is not statically linked: $out" exit 1 fi diff --git a/base/xx-windres b/base/xx-windres index e2e94e5..5a6b99c 100755 --- a/base/xx-windres +++ b/base/xx-windres @@ -106,7 +106,7 @@ while :; do "xx-windres 0.1" ;; -o | --output) - isnextarg $1 $2 + isnextarg "$1" "$2" output=$2 shift ;; @@ -117,7 +117,7 @@ while :; do output=${1#-o} ;; -i | --input) - isnextarg $1 $2 + isnextarg "$1" "$2" input=$2 shift ;; @@ -128,7 +128,7 @@ while :; do input=${1#-i} ;; -J | --input-format) - isnextarg $1 $2 + isnextarg "$1" "$2" inputf=$2 shift ;; @@ -139,7 +139,7 @@ while :; do inputf=${1#-J} ;; -O | --output-format) - isnextarg $1 $2 + isnextarg "$1" "$2" outputf=$2 shift ;; @@ -150,7 +150,7 @@ while :; do outputf=${1#-O} ;; -F | --target) - isnextarg $1 $2 + isnextarg "$1" "$2" target=$2 shift ;; @@ -161,7 +161,7 @@ while :; do target=${1#-F} ;; --preprocessor) - isnextarg $1 $2 + isnextarg "$1" "$2" preprocessor=$2 shift ;; @@ -169,7 +169,7 @@ while :; do preprocessor=${1#--preprocessor=} ;; --preprocessor-arg) - isnextarg $1 $2 + isnextarg "$1" "$2" preprocessorargs="$preprocessorargs $2" shift ;; @@ -177,7 +177,7 @@ while :; do preprocessorargs="$preprocessorargs ${1#--preprocessor-arg=}" ;; -I | --include-path) - isnextarg $1 $2 + isnextarg "$1" "$2" preprocessorargs="$preprocessorargs -I$2" shift ;; @@ -188,7 +188,7 @@ while :; do preprocessorargs="$preprocessorargs -I${1#-I}" ;; -l | --language) - isnextarg $1 $2 + isnextarg "$1" "$2" rcargs="$rcargs -L $2" shift ;; @@ -199,7 +199,7 @@ while :; do rcargs="$rcargs -L ${1#-l}" ;; -c | --codepage) - isnextarg $1 $2 + isnextarg "$1" "$2" rcargs="$rcargs -C $2" shift ;; @@ -210,7 +210,7 @@ while :; do rcargs="$rcargs -C ${1#-c}" ;; -D | --define) - isnextarg $1 $2 + isnextarg "$1" "$2" preprocessorargs="$preprocessorargs -D $2" shift ;; @@ -221,7 +221,7 @@ while :; do preprocessorargs="$preprocessorargs -D ${1#-D}" ;; -U | --undefine) - isnextarg $1 $2 + isnextarg "$1" "$2" preprocessorargs="$preprocessorargs -U $2" shift ;; @@ -271,7 +271,7 @@ if [ -z "$input" ]; then fi if [ -z "$output" ]; then - stdout=/dev/stdout + output=/dev/stdout fi if [ -z "$inputf" ]; then @@ -310,12 +310,12 @@ case $target in x86_64* | *x86-64*) machine="X64" ;; - arm*) - machine="ARM" - ;; aarch64* | arm64*) machine="ARM64" ;; + arm*) + machine="ARM" + ;; *) echo >&2 "invalid target $target for xx-windres" ;; @@ -341,15 +341,17 @@ if [ "$inputf" = "rc" ]; then fi newtmp + # shellcheck disable=SC2086 run "$preprocessor" -E -xc -D RC_INVOKED=1 $preprocessorargs -o $tmpfile $input ptmp=$tmpfile newtmp - run llvm-rc $rcargs -fo $tmpfile -I $(dirname $input) $ptmp + # shellcheck disable=SC2086 + run llvm-rc $rcargs -fo $tmpfile -I "$(dirname $input)" $ptmp - if [ -f $ptmp ]; then - rm $ptmp + if [ -f "$ptmp" ]; then + rm "$ptmp" fi resfile=$tmpfile diff --git a/hack/dockerfiles/shellcheck.Dockerfile b/hack/dockerfiles/shellcheck.Dockerfile new file mode 100644 index 0000000..beb7f19 --- /dev/null +++ b/hack/dockerfiles/shellcheck.Dockerfile @@ -0,0 +1,5 @@ +# syntax = docker/dockerfile:1.2 +from koalaman/shellcheck-alpine:v0.7.2 +workdir /src +copy base . +run shellcheck xx-* \ No newline at end of file diff --git a/hack/shellcheck b/hack/shellcheck new file mode 100755 index 0000000..7d87118 --- /dev/null +++ b/hack/shellcheck @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +set -e + +docker buildx build \ + --output "type=cacheonly" \ + --file "./hack/dockerfiles/shellcheck.Dockerfile" \ + .