mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Adds script which compiles docs example with minimum compiler version.
This commit is contained in:
committed by
Djordje Mijovic
parent
1587486334
commit
50c22f0800
@@ -0,0 +1,79 @@
|
||||
# ------------------------------------------------------------------------------
|
||||
# vim:ts=4:et
|
||||
# This file is part of solidity.
|
||||
#
|
||||
# solidity is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# solidity is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with solidity. If not, see <http://www.gnu.org/licenses/>
|
||||
#
|
||||
# (c) 2016-2019 solidity contributors.
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
FULLARGS="--optimize --ignore-missing --combined-json abi,asm,ast,bin,bin-runtime,compact-format,devdoc,hashes,interface,metadata,opcodes,srcmap,srcmap-runtime,userdoc"
|
||||
OLDARGS="--optimize --combined-json abi,asm,ast,bin,bin-runtime,devdoc,interface,metadata,opcodes,srcmap,srcmap-runtime,userdoc"
|
||||
function compileFull()
|
||||
{
|
||||
local expected_exit_code=0
|
||||
local expect_output=0
|
||||
if [[ $1 = '-e' ]]; then
|
||||
expected_exit_code=1
|
||||
expect_output=1
|
||||
shift;
|
||||
fi
|
||||
if [[ $1 = '-w' ]]; then
|
||||
expect_output=1
|
||||
shift;
|
||||
fi
|
||||
if [[ $1 = '-o' ]]; then
|
||||
expect_output=2
|
||||
shift;
|
||||
fi
|
||||
local args=$FULLARGS
|
||||
if [[ $1 = '-v' ]]; then
|
||||
if (echo $2 | grep -Po '(?<=0.4.)\d+' >/dev/null); then
|
||||
patch=$(echo $2 | grep -Po '(?<=0.4.)\d+')
|
||||
if (( patch < 22 )); then
|
||||
args=$OLDARGS
|
||||
fi
|
||||
fi
|
||||
shift 2
|
||||
fi
|
||||
|
||||
local files="$*"
|
||||
local output
|
||||
|
||||
local 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")
|
||||
set -e
|
||||
rm "$stderr_path"
|
||||
|
||||
if [[ \
|
||||
("$exit_code" -ne "$expected_exit_code" || \
|
||||
( $expect_output -eq 0 && -n "$errors" ) || \
|
||||
( $expect_output -ne 0 && $expected_exit_code -eq 0 && $expect_output -ne 2 && -z "$errors" ))
|
||||
]]
|
||||
then
|
||||
printError "Unexpected compilation result:"
|
||||
printError "Expected failure: $expected_exit_code - Expected warning / error output: $expect_output"
|
||||
printError "Was failure: $exit_code"
|
||||
echo "$errors"
|
||||
printError "While calling:"
|
||||
echo "\"$SOLC\" $ARGS $files"
|
||||
printError "Inside directory:"
|
||||
pwd
|
||||
false
|
||||
fi
|
||||
}
|
||||
Executable
+95
@@ -0,0 +1,95 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# This file is part of solidity.
|
||||
#
|
||||
# solidity is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# solidity is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with solidity. If not, see <http://www.gnu.org/licenses/>
|
||||
#
|
||||
# (c) 2016 solidity contributors.
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
# This script verifies that the examples compile with the oldest version mentioned in the pragma.
|
||||
# It does not verify that it cannot be compiled with an older version
|
||||
# and it also does not verify that it can be compiled with the newest version compatible with the pragma.
|
||||
|
||||
set -e
|
||||
|
||||
## GLOBAL VARIABLES
|
||||
|
||||
REPO_ROOT=$(cd $(dirname "$0")/.. && pwd)
|
||||
SOLIDITY_BUILD_DIR=${SOLIDITY_BUILD_DIR:-build}
|
||||
source "${REPO_ROOT}/scripts/common.sh"
|
||||
source "${REPO_ROOT}/scripts/common_cmdline.sh"
|
||||
|
||||
printTask "Verifying that all examples from the documentation have the correct version range..."
|
||||
SOLTMPDIR=$(mktemp -d)
|
||||
(
|
||||
set -e
|
||||
cd "$SOLTMPDIR"
|
||||
"$REPO_ROOT"/scripts/isolate_tests.py "$REPO_ROOT"/docs/ docs
|
||||
|
||||
for f in *.sol
|
||||
do
|
||||
# The contributors guide uses syntax tests, but we cannot
|
||||
# really handle them here.
|
||||
if grep -E 'DeclarationError:|// ----' "$f" >/dev/null
|
||||
then
|
||||
continue
|
||||
fi
|
||||
echo "$f"
|
||||
|
||||
opts=''
|
||||
# We expect errors if explicitly stated, or if imports
|
||||
# are used (in the style guide)
|
||||
if ( ! grep -E "This will not compile after" "$f" >/dev/null && \
|
||||
grep -E "This will not compile|import \"" "$f" >/dev/null )
|
||||
then
|
||||
opts="-e"
|
||||
fi
|
||||
|
||||
# ignore warnings in this case
|
||||
opts="$opts -o"
|
||||
|
||||
# Get minimum compiler version defined by pragma
|
||||
if (grep -Po '(?<=pragma solidity >=)\d+.\d+.\d+' "$f" >/dev/null); then
|
||||
version="$(grep -Po '(?<=pragma solidity >=)\d+.\d+.\d+' "$f")"
|
||||
if (echo $version | grep -Po '(?<=0.4.)\d+' >/dev/null); then
|
||||
patch=$(echo $version | grep -Po '(?<=0.4.)\d+')
|
||||
if (( patch < 11 )); then
|
||||
version="0.4.11" # first available release on github
|
||||
fi
|
||||
fi
|
||||
elif (grep -Po '(?<=pragma solidity \^)\d+.\d+.\d+' "$f" >/dev/null); then
|
||||
version="$(grep -Po '(?<=pragma solidity \^)\d+.\d+.\d+' "$f")"
|
||||
fi
|
||||
|
||||
opts="$opts -v $version"
|
||||
|
||||
solc_bin="solc-$version"
|
||||
echo "$solc_bin"
|
||||
if [[ ! -f "$solc_bin" ]]; then
|
||||
echo "Downloading release from github..."
|
||||
wget https://github.com/ethereum/solidity/releases/download/v$version/solc-static-linux
|
||||
mv solc-static-linux $solc_bin
|
||||
fi
|
||||
|
||||
ln -sf "$solc_bin" "solc"
|
||||
chmod a+x solc
|
||||
|
||||
SOLC="$SOLTMPDIR/solc"
|
||||
compileFull $opts "$SOLTMPDIR/$f"
|
||||
done
|
||||
)
|
||||
rm -rf "$SOLTMPDIR"
|
||||
echo "Done."
|
||||
Reference in New Issue
Block a user