Skip to content

Commit

Permalink
Merge pull request #10586 from ethereum/shellcheck-fixes-part1
Browse files Browse the repository at this point in the history
Fixes for shellcheck warnings, part 1
  • Loading branch information
cameel authored Mar 5, 2021
2 parents 08df163 + cf94c3f commit 093ea46
Show file tree
Hide file tree
Showing 24 changed files with 86 additions and 95 deletions.
4 changes: 2 additions & 2 deletions .circleci/soltest.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /bin/bash
#!/usr/bin/env bash
#------------------------------------------------------------------------------
# Bash script to execute the Solidity tests by CircleCI.
#
Expand Down Expand Up @@ -56,7 +56,7 @@ get_logfile_basename() {
echo -ne "${filename}"
}

BOOST_TEST_ARGS=("--color_output=no" "--show_progress=yes" "--logger=JUNIT,error,test_results/`get_logfile_basename`.xml" "${BOOST_TEST_ARGS[@]}")
BOOST_TEST_ARGS=("--color_output=no" "--show_progress=yes" "--logger=JUNIT,error,test_results/$(get_logfile_basename).xml" "${BOOST_TEST_ARGS[@]}")
SOLTEST_ARGS=("--evm-version=$EVM" "${SOLTEST_FLAGS[@]}")

test "${OPTIMIZE}" = "1" && SOLTEST_ARGS+=(--optimize)
Expand Down
29 changes: 13 additions & 16 deletions .circleci/soltest_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,35 @@ EVM_VALUES=(homestead byzantium constantinople petersburg istanbul)
OPTIMIZE_VALUES=(0 1)
STEPS=$(( 2 + ${#EVM_VALUES[@]} * ${#OPTIMIZE_VALUES[@]} ))

if (( $CIRCLE_NODE_TOTAL )) && (( $CIRCLE_NODE_TOTAL > 1 ))
if (( CIRCLE_NODE_TOTAL )) && (( CIRCLE_NODE_TOTAL > 1 ))
then
# Run step 1 as the only step on the first executor
# and evenly distribute the other steps among
# the other executors.
# The first step takes much longer than the other steps.
if (( $CIRCLE_NODE_INDEX == 0 ))
if (( CIRCLE_NODE_INDEX == 0 ))
then
RUN_STEPS="1"
else
export CIRCLE_NODE_INDEX=$(($CIRCLE_NODE_INDEX - 1))
export CIRCLE_NODE_TOTAL=$(($CIRCLE_NODE_TOTAL - 1))
RUN_STEPS=$(seq 2 "$STEPS" | circleci tests split)
export CIRCLE_NODE_INDEX=$((CIRCLE_NODE_INDEX - 1))
export CIRCLE_NODE_TOTAL=$((CIRCLE_NODE_TOTAL - 1))
RUN_STEPS=$(seq 2 "$STEPS" | circleci tests split | xargs)
fi
else
RUN_STEPS=$(seq "$STEPS")
RUN_STEPS=$(seq "$STEPS" | xargs)
fi

# turn newlines into spaces
RUN_STEPS=$(echo $RUN_STEPS)

echo "Running steps $RUN_STEPS..."

STEP=1

# Run SMTChecker tests separately, as the heaviest expected run.
[[ " $RUN_STEPS " =~ " $STEP " ]] && EVM=istanbul OPTIMIZE=1 ABI_ENCODER_V1=1 BOOST_TEST_ARGS="-t smtCheckerTests/*" "${REPODIR}/.circleci/soltest.sh"
STEP=$(($STEP + 1))
[[ " $RUN_STEPS " == *" $STEP "* ]] && EVM=istanbul OPTIMIZE=1 ABI_ENCODER_V1=1 BOOST_TEST_ARGS="-t smtCheckerTests/*" "${REPODIR}/.circleci/soltest.sh"
STEP=$((STEP + 1))

# Run without SMTChecker tests.
[[ " $RUN_STEPS " =~ " $STEP " ]] && EVM=istanbul OPTIMIZE=1 ABI_ENCODER_V1=1 BOOST_TEST_ARGS="-t !smtCheckerTests" "${REPODIR}/.circleci/soltest.sh"
STEP=$(($STEP + 1))
[[ " $RUN_STEPS " == *" $STEP "* ]] && EVM=istanbul OPTIMIZE=1 ABI_ENCODER_V1=1 BOOST_TEST_ARGS="-t !smtCheckerTests" "${REPODIR}/.circleci/soltest.sh"
STEP=$((STEP + 1))

for OPTIMIZE in "${OPTIMIZE_VALUES[@]}"
do
Expand All @@ -73,12 +70,12 @@ do
EWASM_ARGS=""
[ "${EVM}" = "byzantium" ] && [ "${OPTIMIZE}" = "0" ] && EWASM_ARGS="--ewasm"

[[ " $RUN_STEPS " =~ " $STEP " ]] && EVM="$EVM" OPTIMIZE="$OPTIMIZE" SOLTEST_FLAGS="$SOLTEST_FLAGS $EWASM_ARGS" BOOST_TEST_ARGS="-t !@nooptions" "${REPODIR}/.circleci/soltest.sh"
STEP=$(($STEP + 1))
[[ " $RUN_STEPS " == *" $STEP "* ]] && EVM="$EVM" OPTIMIZE="$OPTIMIZE" SOLTEST_FLAGS="$SOLTEST_FLAGS $EWASM_ARGS" BOOST_TEST_ARGS="-t !@nooptions" "${REPODIR}/.circleci/soltest.sh"
STEP=$((STEP + 1))
done
done

if (($STEP != $STEPS + 1))
if ((STEP != STEPS + 1))
then
echo "Step counter not properly adjusted!" >&2
exit 1
Expand Down
9 changes: 4 additions & 5 deletions scripts/ASTImportTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ TESTED=0

if [ "$(ls | wc -l)" -ne 0 ]; then
echo "Test directory not empty. Skipping!"
exit -1
exit 1
fi

# function tests whether exporting and importing again leaves the JSON ast unchanged
Expand All @@ -45,8 +45,7 @@ function testImportExportEquivalence {
# save exported json as expected result (silently)
$SOLC --combined-json ast,compact-format --pretty-json "$nth_input_file" "${all_input_files[@]}" > expected.json 2> /dev/null
# import it, and export it again as obtained result (silently)
$SOLC --import-ast --combined-json ast,compact-format --pretty-json expected.json > obtained.json 2> /dev/null
if [ $? -ne 0 ]
if ! $SOLC --import-ast --combined-json ast,compact-format --pretty-json expected.json > obtained.json 2> /dev/null
then
# For investigating, use exit 1 here so the script stops at the
# first failing test
Expand All @@ -61,9 +60,9 @@ function testImportExportEquivalence {
then
echo -e "ERROR: JSONS differ for $1: \n $DIFF \n"
echo "Expected:"
echo "$(cat ./expected.json)"
cat ./expected.json
echo "Obtained:"
echo "$(cat ./obtained.json)"
cat ./obtained.json
else
# Use user supplied diff view binary
$DIFFVIEW expected.json obtained.json
Expand Down
6 changes: 4 additions & 2 deletions scripts/check_style.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

set -eu

ERROR_LOG="$(mktemp -t check_style_XXXXXX.log)"

EXCLUDE_FILES=(
Expand All @@ -20,7 +22,7 @@ REPO_ROOT="$(dirname "$0")"/..
cd "$REPO_ROOT" || exit 1

WHITESPACE=$(git grep -n -I -E "^.*[[:space:]]+$" |
grep -v "test/libsolidity/ASTJSON\|test/libsolidity/ASTRecoveryTests\|test/compilationTests/zeppelin/LICENSE\|${EXCLUDE_FILES_JOINED}"
grep -v "test/libsolidity/ASTJSON\|test/libsolidity/ASTRecoveryTests\|test/compilationTests/zeppelin/LICENSE\|${EXCLUDE_FILES_JOINED}" || true
)

if [[ "$WHITESPACE" != "" ]]
Expand Down Expand Up @@ -49,7 +51,7 @@ FORMATERROR=$(
preparedGrep "[a-zA-Z0-9_]\s*[&][a-zA-Z_]" | grep -E -v "return [&]" # right-aligned reference ampersand (needs to exclude return)
# right-aligned reference pointer star (needs to exclude return and comments)
preparedGrep "[a-zA-Z0-9_]\s*[*][a-zA-Z_]" | grep -E -v -e "return [*]" -e "^* [*]" -e "^*//.*"
) | grep -E -v -e "^[a-zA-Z\./]*:[0-9]*:\s*\/(\/|\*)" -e "^test/"
) | grep -E -v -e "^[a-zA-Z\./]*:[0-9]*:\s*\/(\/|\*)" -e "^test/" || true
)

if [[ "$FORMATERROR" != "" ]]
Expand Down
2 changes: 1 addition & 1 deletion scripts/chk_shellscripts/chk_shellscripts.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -e
set -eu

REPO_ROOT="$(dirname "$0")"/../..
REPO_ROOT=$(realpath "${REPO_ROOT}")
Expand Down
10 changes: 0 additions & 10 deletions scripts/chk_shellscripts/ignore.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
./test/cmdlineTests.sh
./scripts/wasm-rebuild/docker-scripts/rebuild_tags.sh
./scripts/wasm-rebuild/docker-scripts/rebuild_current.sh
./scripts/wasm-rebuild/docker-scripts/genbytecode.sh
./scripts/ci/build_emscripten.sh
./scripts/docs_version_pragma_check.sh
./scripts/uniqueErrors.sh
./scripts/tests.sh
./scripts/bytecodecompare/storebytecode.sh
./scripts/deps-ppa/static_z3.sh
./scripts/ASTImportTest.sh
./scripts/install_static_z3.sh
./scripts/install_deps.sh
./scripts/common_cmdline.sh
./scripts/docker_deploy_manual.sh
./scripts/endToEndExtraction/create_traces.sh
./scripts/release_ppa.sh
./scripts/create_source_tarball.sh
./.circleci/soltest.sh
./.circleci/soltest_all.sh
2 changes: 1 addition & 1 deletion scripts/ci/build_emscripten.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ mkdir -p upload
cp "$BUILD_DIR/libsolc/soljson.js" upload/
cp "$BUILD_DIR/libsolc/soljson.js" ./

OUTPUT_SIZE=`ls -la soljson.js`
OUTPUT_SIZE=$(ls -la soljson.js)

echo "Emscripten output size: $OUTPUT_SIZE"
5 changes: 3 additions & 2 deletions scripts/common_cmdline.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# ------------------------------------------------------------------------------
# vim:ts=4:et
# This file is part of solidity.
Expand Down Expand Up @@ -50,12 +51,12 @@ function compileFull()

local files=("$@")

local stderr_path=$(mktemp)
local stderr_path; stderr_path=$(mktemp)

set +e
"$SOLC" "${args[@]}" "${files[@]}" >/dev/null 2>"$stderr_path"
local exit_code=$?
local errors=$(grep -v -E 'Warning: This is a pre-release compiler version|Warning: Experimental features are turned on|pragma experimental ABIEncoderV2|^ +--> |^ +\||^[0-9]+ +\|' < "$stderr_path")
local errors; errors=$(grep -v -E 'Warning: This is a pre-release compiler version|Warning: Experimental features are turned on|pragma experimental ABIEncoderV2|^ +--> |^ +\||^[0-9]+ +\|' < "$stderr_path")
set -e
rm "$stderr_path"

Expand Down
4 changes: 2 additions & 2 deletions scripts/create_source_tarball.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ REPO_ROOT="$(dirname "$0")"/..
commitdate=$(git show --format=%ci HEAD | head -n 1 | cut - -b1-10 | sed -e 's/-0?/./' | sed -e 's/-0?/./')

# file exists and has zero size -> not a prerelease
if [ -e prerelease.txt -a ! -s prerelease.txt ]
if [ -e prerelease.txt ] && [ ! -s prerelease.txt ]
then
versionstring="$version"
else
Expand All @@ -25,7 +25,7 @@ REPO_ROOT="$(dirname "$0")"/..
git checkout-index -a --prefix="$SOLDIR"
# Store the commit hash
echo "$commithash" > "$SOLDIR/commit_hash.txt"
if [ -e prerelease.txt -a ! -s prerelease.txt ]
if [ -e prerelease.txt ] && [ ! -s prerelease.txt ]
then
cp prerelease.txt "$SOLDIR/"
fi
Expand Down
6 changes: 3 additions & 3 deletions scripts/deps-ppa/static_z3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ if wget --quiet -O $orig-tmp "$ppafilesurl/$orig"
then
echo "[WARN] Original tarball found in Ubuntu archive, using it instead"
mv $orig-tmp $orig
new_size=$(ls -l *.orig.tar.gz | cut -d ' ' -f 5)
new_size=$(ls -l ./*.orig.tar.gz | cut -d ' ' -f 5)
new_sha1=$(sha1sum $orig | cut -d ' ' -f 1)
new_sha256=$(sha256sum $orig | cut -d ' ' -f 1)
new_md5=$(md5sum $orig | cut -d ' ' -f 1)
sed -i -e "s,$orig_sha1,$new_sha1,g" -e "s,$orig_sha256,$new_sha256,g" -e "s,$orig_size,$new_size,g" -e "s,$orig_md5,$new_md5,g" *.dsc
sed -i -e "s,$orig_sha1,$new_sha1,g" -e "s,$orig_sha256,$new_sha256,g" -e "s,$orig_size,$new_size,g" -e "s,$orig_md5,$new_md5,g" *.changes
sed -i -e "s,$orig_sha1,$new_sha1,g" -e "s,$orig_sha256,$new_sha256,g" -e "s,$orig_size,$new_size,g" -e "s,$orig_md5,$new_md5,g" ./*.dsc
sed -i -e "s,$orig_sha1,$new_sha1,g" -e "s,$orig_sha256,$new_sha256,g" -e "s,$orig_size,$new_size,g" -e "s,$orig_md5,$new_md5,g" ./*.changes
fi
)

Expand Down
4 changes: 2 additions & 2 deletions scripts/docker_deploy_manual.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
#!/usr/bin/env bash

set -e

Expand All @@ -21,7 +21,7 @@ cd solidity
commithash=$(git rev-parse --short=8 HEAD)
echo -n "$commithash" > commit_hash.txt
version=$("$(dirname "$0")/get_version.sh")
if [ "$branch" = "release" -o "$branch" = v"$version" ]
if [ "$branch" = "release" ] || [ "$branch" = v"$version" ]
then
echo -n > prerelease.txt
else
Expand Down
8 changes: 4 additions & 4 deletions scripts/docs_version_pragma_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ function versionEqual()
function getAllAvailableVersions()
{
allVersions=()
local allListedVersions=( $(
local allListedVersions
mapfile -t allListedVersions <<< "$(
wget -q -O- https://binaries.soliditylang.org/bin/list.txt |
grep -Po '(?<=soljson-v)\d+.\d+.\d+(?=\+commit)' |
sort -V
) )
)"
for listed in "${allListedVersions[@]}"
do
if versionGreater "$listed" "0.4.10"
Expand Down Expand Up @@ -187,8 +188,7 @@ SOLTMPDIR=$(mktemp -d)
ln -sf "$solc_bin" "solc"
chmod a+x solc

SOLC="$SOLTMPDIR/solc"
compileFull "${opts[@]}" "$SOLTMPDIR/$f"
SOLC="$SOLTMPDIR/solc" compileFull "${opts[@]}" "$SOLTMPDIR/$f"
done
)
rm -rf "$SOLTMPDIR"
Expand Down
17 changes: 10 additions & 7 deletions scripts/endToEndExtraction/create_traces.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
BASE_PATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 || exit ; pwd -P )"
#!/usr/bin/env bash
set -eu

BASE_PATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 && pwd -P )"

mkdir -p build
cd build || exit
cd build
cmake ../../../
make soltest
cd test/ || exit
cd test/
echo "running soltest on 'semanticTests/extracted'..."
./soltest --color_output=false --log_level=test_suite -t semanticTests/extracted/ -- --testpath "${BASE_PATH}/../../test" --no-smt --evmonepath /Users/alex/evmone/lib/libevmone.dylib --show-messages --show-metadata > "${BASE_PATH}/extracted-tests.trace"
echo "running soltest on 'semanticTests/extracted'... done"

cd "$BASE_PATH" || exit
cd "$BASE_PATH"
git clone git@github.com:ethereum/solidity.git solidity-develop
cd solidity-develop || exit
cd solidity-develop
mkdir -p build
cd build || exit
cd build
cmake ..
make soltest
cd test/ || exit
cd test/
echo "running soltest on 'SolidityEndToEndTest'..."
./soltest --color_output=false --log_level=test_suite -t SolidityEndToEndTest/ -- --testpath "${BASE_PATH}/solidity-develop/test" --no-smt --evmonepath /Users/alex/evmone/lib/libevmone.dylib --show-messages --show-metadata > "${BASE_PATH}/endToEndExtraction-tests.trace"
echo "running soltest on 'SolidityEndToEndTest'... done"
2 changes: 1 addition & 1 deletion scripts/install_cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# (the cmake executable will be in ~/.local/bin).
# This is mostly suitable for CIs, not end users.

set -e
set -eu

VERSION_MAJOR=3
VERSION_MINOR=15
Expand Down
4 changes: 2 additions & 2 deletions scripts/install_obsolete_jsoncpp_1_7_4.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env sh
set -e
#!/usr/bin/env bash
set -eu

TEMPDIR=$(mktemp -d)
(
Expand Down
2 changes: 2 additions & 0 deletions scripts/install_static_z3.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

set -eu

git clone --depth 1 --branch z3-4.8.7 https://github.com/Z3Prover/z3.git
cd z3
mkdir build
Expand Down
6 changes: 3 additions & 3 deletions scripts/release_ppa.sh
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,12 @@ if wget --quiet -O "$orig-tmp" "$ppafilesurl/$orig"
then
echo "[WARN] Original tarball found in Ubuntu archive, using it instead"
mv "$orig-tmp" "$orig"
new_size=$(ls -l *.orig.tar.gz | cut -d ' ' -f 5)
new_size=$(ls -l ./*.orig.tar.gz | cut -d ' ' -f 5)
new_sha1=$(sha1sum "$orig" | cut -d ' ' -f 1)
new_sha256=$(sha256sum "$orig" | cut -d ' ' -f 1)
new_md5=$(md5sum "$orig" | cut -d ' ' -f 1)
sed -i -e "s,$orig_sha1,$new_sha1,g" -e "s,$orig_sha256,$new_sha256,g" -e "s,$orig_size,$new_size,g" -e "s,$orig_md5,$new_md5,g" *.dsc
sed -i -e "s,$orig_sha1,$new_sha1,g" -e "s,$orig_sha256,$new_sha256,g" -e "s,$orig_size,$new_size,g" -e "s,$orig_md5,$new_md5,g" *.changes
sed -i -e "s,$orig_sha1,$new_sha1,g" -e "s,$orig_sha256,$new_sha256,g" -e "s,$orig_size,$new_size,g" -e "s,$orig_md5,$new_md5,g" ./*.dsc
sed -i -e "s,$orig_sha1,$new_sha1,g" -e "s,$orig_sha256,$new_sha256,g" -e "s,$orig_size,$new_size,g" -e "s,$orig_md5,$new_md5,g" ./*.changes
fi
)

Expand Down
2 changes: 1 addition & 1 deletion scripts/soltest.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
set -e
set -eu

REPO_ROOT="$(dirname "$0")"/..
USE_DEBUGGER=0
Expand Down
2 changes: 1 addition & 1 deletion scripts/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ IFS=" " read -r -a SMT_FLAGS <<< "$SMT_FLAGS"

source "${REPO_ROOT}/scripts/common.sh"

WORKDIR=`mktemp -d`
WORKDIR=$(mktemp -d)
CMDLINE_PID=

cleanup() {
Expand Down
4 changes: 2 additions & 2 deletions scripts/uniqueErrors.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/sh
#!/usr/bin/env bash

REPO="$(dirname "$0")/.."

echo "Finding unique failures..."
(
for x in $*
for x in "$@"
do
echo -n "$x" " # "
# This subshell is a workaround to prevent the shell from printing
Expand Down
2 changes: 1 addition & 1 deletion scripts/wasm-rebuild/docker-scripts/genbytecode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ for (var optimize of [false, true])
}
EOF
chmod +x solc
./solc *.sol > /tmp/report.txt
./solc -- *.sol > /tmp/report.txt
)
rm -rf "$TMPDIR"
9 changes: 8 additions & 1 deletion scripts/wasm-rebuild/docker-scripts/rebuild_current.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ if [ -d jsoncpp ]; then
fi

set +e
scripts/*/build_emscripten.sh

if [ -e scripts/ci/build_emscripten.sh ]; then
scripts/ci/build_emscripten.sh
else
# The script used to be in scripts/ci/ in earlier versions.
scripts/travis-emscripten/build_emscripten.sh
fi

set -e

mkdir -p upload
Expand Down
Loading

0 comments on commit 093ea46

Please sign in to comment.