Skip to content

Commit 656928f

Browse files
committed
Apply some more fixes suggested by Shellcheck
1 parent d2c3a16 commit 656928f

File tree

2 files changed

+36
-30
lines changed

2 files changed

+36
-30
lines changed

ci/run-docker.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Small script to run tests for a target (or all targets) inside all the
44
# respective docker images.
55

6-
set -eux
6+
set -euxo pipefail
77

88
run() {
99
local target="$1"

ci/run.sh

+35-29
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/bin/bash
2+
13
set -eux
24

35
target="${1:-}"
@@ -29,13 +31,13 @@ else
2931
fi
3032

3133
if [ -d /builtins-target ]; then
32-
path=/builtins-target/${target}/debug/deps/libcompiler_builtins-*.rlib
34+
rlib_paths=/builtins-target/"${target}"/debug/deps/libcompiler_builtins-*.rlib
3335
else
34-
path=target/${target}/debug/deps/libcompiler_builtins-*.rlib
36+
rlib_paths=target/"${target}"/debug/deps/libcompiler_builtins-*.rlib
3537
fi
3638

3739
# Remove any existing artifacts from previous tests that don't set #![compiler_builtins]
38-
rm -f $path
40+
rm -f $rlib_paths
3941

4042
cargo build --target "$target"
4143
cargo build --target "$target" --release
@@ -44,7 +46,7 @@ cargo build --target "$target" --release --features c
4446
cargo build --target "$target" --features no-asm
4547
cargo build --target "$target" --release --features no-asm
4648

47-
PREFIX=$(echo "$target" | sed -e 's/unknown-//')-
49+
PREFIX=${target//unknown-/}-
4850
case "$target" in
4951
armv7-*)
5052
PREFIX=arm-linux-gnueabihf-
@@ -57,7 +59,7 @@ case "$target" in
5759
;;
5860
esac
5961

60-
NM=$(find $(rustc --print sysroot) \( -name llvm-nm -o -name llvm-nm.exe \) )
62+
NM=$(find "$(rustc --print sysroot)" \( -name llvm-nm -o -name llvm-nm.exe \) )
6163
if [ "$NM" = "" ]; then
6264
NM="${PREFIX}nm"
6365
fi
@@ -69,37 +71,41 @@ if [[ "$TOOLCHAIN" == *i686-pc-windows-gnu ]]; then
6971
fi
7072

7173
# Look out for duplicated symbols when we include the compiler-rt (C) implementation
72-
for rlib in $(echo $path); do
74+
for rlib in $rlib_paths; do
7375
set +x
7476
echo "================================================================"
7577
echo "checking $rlib for duplicate symbols"
7678
echo "================================================================"
79+
80+
duplicates_found=0
7781

78-
stdout=$($NM -g --defined-only $rlib 2>&1)
7982
# NOTE On i586, It's normal that the get_pc_thunk symbol appears several
8083
# times so ignore it
81-
set +e
82-
echo "$stdout" | \
83-
sort | \
84-
uniq -d | \
85-
grep -v __x86.get_pc_thunk | \
86-
grep 'T __'
87-
88-
if test $? = 0; then
84+
$NM -g --defined-only "$rlib" 2>&1 |
85+
sort |
86+
uniq -d |
87+
grep -v __x86.get_pc_thunk --quiet |
88+
grep 'T __' && duplicates_found=1
89+
90+
if [ "$duplicates_found" != 0 ]; then
91+
echo "error: found duplicate symbols"
8992
exit 1
93+
else
94+
echo "success; no duplicate symbols found"
9095
fi
91-
92-
set -ex
9396
done
9497

95-
rm -f $path
98+
rm -f $rlib_paths
99+
100+
build_intrinsics() {
101+
cargo build --target "$target" -v --example intrinsics "$@"
102+
}
96103

97104
# Verify that we haven't drop any intrinsic/symbol
98-
build_intrinsics="cargo build --target "$target" -v --example intrinsics"
99-
$build_intrinsics
100-
$build_intrinsics --release
101-
$build_intrinsics --features c
102-
$build_intrinsics --features c --release
105+
build_intrinsics
106+
build_intrinsics --release
107+
build_intrinsics --features c
108+
build_intrinsics --features c --release
103109

104110
# Verify that there are no undefined symbols to `panic` within our
105111
# implementations
@@ -109,7 +115,7 @@ CARGO_PROFILE_RELEASE_LTO=true \
109115
cargo build --target "$target" --example intrinsics --release
110116

111117
# Ensure no references to any symbols from core
112-
for rlib in $(echo $path); do
118+
for rlib in $(echo $rlib_paths); do
113119
set +x
114120
echo "================================================================"
115121
echo "checking $rlib for references to core"
@@ -121,14 +127,14 @@ for rlib in $(echo $path); do
121127
defined="$tmpdir/defined_symbols.txt"
122128
undefined="$tmpdir/defined_symbols.txt"
123129

124-
$NM --quiet -U $rlib | grep 'T _ZN4core' | awk '{print $3}' | sort | uniq > "$defined"
125-
$NM --quiet -u $rlib | grep 'U _ZN4core' | awk '{print $2}' | sort | uniq > "$undefined"
126-
grep_failed=0
127-
grep -v -F -x -f "$defined" "$undefined" && grep_failed=1
130+
$NM --quiet -U "$rlib" | grep 'T _ZN4core' | awk '{print $3}' | sort | uniq > "$defined"
131+
$NM --quiet -u "$rlib" | grep 'U _ZN4core' | awk '{print $2}' | sort | uniq > "$undefined"
132+
grep_has_results=0
133+
grep -v -F -x -f "$defined" "$undefined" && grep_has_results=1
128134

129135
if [ "$target" = "powerpc64-unknown-linux-gnu" ]; then
130136
echo "FIXME: powerpc64 fails these tests"
131-
elif [ "$grep_failed" != 0 ]; then
137+
elif [ "$grep_has_results" != 0 ]; then
132138
echo "error: found unexpected references to core"
133139
exit 1
134140
else

0 commit comments

Comments
 (0)