From 3afdaf8c59164646d1d4b2f078896dd36c9d3a79 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 15 Apr 2024 14:44:39 -0400 Subject: [PATCH] Add some more shellcheck fixes --- ci/run-docker.sh | 2 +- ci/run.sh | 67 ++++++++++++++++++++++++++---------------------- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/ci/run-docker.sh b/ci/run-docker.sh index 819643039..b85f64133 100755 --- a/ci/run-docker.sh +++ b/ci/run-docker.sh @@ -3,7 +3,7 @@ # Small script to run tests for a target (or all targets) inside all the # respective docker images. -set -eux +set -euxo pipefail run() { local target="$1" diff --git a/ci/run.sh b/ci/run.sh index dba72a463..eb7e54809 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -1,4 +1,6 @@ -set -eux +#!/bin/bash + +set -euxo pipefail target="$1" @@ -22,14 +24,15 @@ else $run --features no-asm --release fi +shopt -s nullglob if [ -d /builtins-target ]; then - path=/builtins-target/${target}/debug/deps/libcompiler_builtins-*.rlib + path=(/builtins-target/"${target}"/debug/deps/libcompiler_builtins-*.rlib) else - path=target/${target}/debug/deps/libcompiler_builtins-*.rlib + path=(target/"${target}"/debug/deps/libcompiler_builtins-*.rlib) fi # Remove any existing artifacts from previous tests that don't set #![compiler_builtins] -rm -f $path +rm -f "${path[@]}" cargo build --target "$target" cargo build --target "$target" --release @@ -38,7 +41,7 @@ cargo build --target "$target" --release --features c cargo build --target "$target" --features no-asm cargo build --target "$target" --release --features no-asm -PREFIX=$(echo "$target" | sed -e 's/unknown-//')- +PREFIX=${target//unknown-/}- case "$target" in armv7-*) PREFIX=arm-linux-gnueabihf- @@ -51,7 +54,7 @@ case "$target" in ;; esac -NM=$(find $(rustc --print sysroot) \( -name llvm-nm -o -name llvm-nm.exe \) ) +NM=$(find "$(rustc --print sysroot)" \( -name llvm-nm -o -name llvm-nm.exe \) ) if [ "$NM" = "" ]; then NM="${PREFIX}nm" fi @@ -63,37 +66,41 @@ if [[ "$TOOLCHAIN" == *i686-pc-windows-gnu ]]; then fi # Look out for duplicated symbols when we include the compiler-rt (C) implementation -for rlib in $(echo $path); do +for rlib in "${path[@]}"; do set +x echo "================================================================" echo "checking $rlib for duplicate symbols" echo "================================================================" + + duplicates_found=0 - stdout=$($NM -g --defined-only $rlib 2>&1) # NOTE On i586, It's normal that the get_pc_thunk symbol appears several # times so ignore it - set +e - echo "$stdout" | \ - sort | \ - uniq -d | \ - grep -v __x86.get_pc_thunk | \ - grep 'T __' - - if test $? = 0; then + $NM -g --defined-only "$rlib" 2>&1 | + sort | + uniq -d | + grep -v __x86.get_pc_thunk --quiet | + grep 'T __' && duplicates_found=1 + + if [ "$duplicates_found" != 0 ]; then + echo "error: found duplicate symbols" exit 1 + else + echo "success; no duplicate symbols found" fi - - set -ex done -rm -f $path +rm -f "${path[@]}" + +build_intrinsics() { + cargo build --target "$target" -v --example intrinsics "$@" +} # Verify that we haven't drop any intrinsic/symbol -build_intrinsics="cargo build --target "$target" -v --example intrinsics" -$build_intrinsics -$build_intrinsics --release -$build_intrinsics --features c -$build_intrinsics --features c --release +build_intrinsics +build_intrinsics --release +build_intrinsics --features cr +build_intrinsics --features c --release # Verify that there are no undefined symbols to `panic` within our # implementations @@ -103,7 +110,7 @@ CARGO_PROFILE_RELEASE_LTO=true \ cargo build --target "$target" --example intrinsics --release # Ensure no references to any symbols from core -for rlib in $(echo $path); do +for rlib in "${path[@]}"; do set +x echo "================================================================" echo "checking $rlib for references to core" @@ -115,14 +122,14 @@ for rlib in $(echo $path); do defined="$tmpdir/defined_symbols.txt" undefined="$tmpdir/defined_symbols.txt" - $NM --quiet -U $rlib | grep 'T _ZN4core' | awk '{print $3}' | sort | uniq > "$defined" - $NM --quiet -u $rlib | grep 'U _ZN4core' | awk '{print $2}' | sort | uniq > "$undefined" - grep_failed=0 - grep -v -F -x -f "$defined" "$undefined" && grep_failed=1 + $NM --quiet -U "$rlib" | grep 'T _ZN4core' | awk '{print $3}' | sort | uniq > "$defined" + $NM --quiet -u "$rlib" | grep 'U _ZN4core' | awk '{print $2}' | sort | uniq > "$undefined" + grep_has_results=0 + grep -v -F -x -f "$defined" "$undefined" && grep_has_results=1 if [ "$target" = "powerpc64-unknown-linux-gnu" ]; then echo "FIXME: powerpc64 fails these tests" - elif [ "$grep_failed" != 0 ]; then + elif [ "$grep_has_results" != 0 ]; then echo "error: found unexpected references to core" exit 1 else