2020-01-28 15:34:38 +00:00
|
|
|
#!/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
|
|
|
|
|
2020-12-11 17:19:53 +00:00
|
|
|
REPO_ROOT=$(cd "$(dirname "$0")/.." && pwd)
|
2020-04-17 13:02:40 +00:00
|
|
|
SOLIDITY_BUILD_DIR=${SOLIDITY_BUILD_DIR:-${REPO_ROOT}/build}
|
2020-12-12 00:46:21 +00:00
|
|
|
# shellcheck source=scripts/common.sh
|
2020-01-28 15:34:38 +00:00
|
|
|
source "${REPO_ROOT}/scripts/common.sh"
|
2020-12-12 00:46:21 +00:00
|
|
|
# shellcheck source=scripts/common_cmdline.sh
|
2020-01-28 15:34:38 +00:00
|
|
|
source "${REPO_ROOT}/scripts/common_cmdline.sh"
|
|
|
|
|
2021-01-14 13:39:41 +00:00
|
|
|
developmentVersion=$("$REPO_ROOT/scripts/get_version.sh")
|
|
|
|
|
2020-03-28 23:02:44 +00:00
|
|
|
function versionGreater()
|
|
|
|
{
|
|
|
|
v1=$1
|
|
|
|
v2=$2
|
2020-12-11 17:28:19 +00:00
|
|
|
# shellcheck disable=SC2206
|
2020-03-28 23:02:44 +00:00
|
|
|
ver1=( ${v1//./ } )
|
2020-12-11 17:28:19 +00:00
|
|
|
# shellcheck disable=SC2206
|
2020-03-28 23:02:44 +00:00
|
|
|
ver2=( ${v2//./ } )
|
|
|
|
|
2020-12-11 17:19:53 +00:00
|
|
|
if (( "${ver1[0]}" > "${ver2[0]}" ))
|
2020-03-28 23:02:44 +00:00
|
|
|
then
|
|
|
|
return 0
|
2020-12-11 17:19:53 +00:00
|
|
|
elif (( "${ver1[0]}" == "${ver2[0]}" )) && (( "${ver1[1]}" > "${ver2[1]}" ))
|
2020-03-28 23:02:44 +00:00
|
|
|
then
|
|
|
|
return 0
|
2020-12-11 17:19:53 +00:00
|
|
|
elif (( "${ver1[0]}" == "${ver2[0]}" )) && (( "${ver1[1]}" == "${ver2[1]}" )) && (( "${ver1[2]}" > "${ver2[2]}" ))
|
2020-03-28 23:02:44 +00:00
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
function versionEqual()
|
|
|
|
{
|
2021-01-14 13:40:50 +00:00
|
|
|
if [[ "$1" == "$2" ]]
|
2020-03-28 23:02:44 +00:00
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAllAvailableVersions()
|
|
|
|
{
|
|
|
|
allVersions=()
|
2020-12-12 02:05:06 +00:00
|
|
|
local allListedVersions
|
|
|
|
mapfile -t allListedVersions <<< "$(
|
2020-12-12 03:29:20 +00:00
|
|
|
wget -q -O- https://binaries.soliditylang.org/bin/list.txt |
|
2020-03-28 23:02:44 +00:00
|
|
|
grep -Po '(?<=soljson-v)\d+.\d+.\d+(?=\+commit)' |
|
|
|
|
sort -V
|
2020-12-12 02:05:06 +00:00
|
|
|
)"
|
2020-03-28 23:02:44 +00:00
|
|
|
for listed in "${allListedVersions[@]}"
|
|
|
|
do
|
|
|
|
if versionGreater "$listed" "0.4.10"
|
|
|
|
then
|
2020-12-11 17:19:53 +00:00
|
|
|
allVersions+=( "$listed" )
|
2020-03-28 23:02:44 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
function findMinimalVersion()
|
|
|
|
{
|
|
|
|
local f=$1
|
|
|
|
local greater=false
|
|
|
|
local pragmaVersion
|
|
|
|
|
|
|
|
# Get minimum compiler version defined by pragma
|
|
|
|
if (grep -Po '(?<=pragma solidity >=)\d+.\d+.\d+' "$f" >/dev/null)
|
|
|
|
then
|
|
|
|
pragmaVersion="$(grep -Po '(?<=pragma solidity >=)\d+.\d+.\d+' "$f")"
|
|
|
|
sign=">="
|
|
|
|
elif (grep -Po '(?<=pragma solidity \^)\d+.\d+.\d+' "$f" >/dev/null)
|
|
|
|
then
|
|
|
|
pragmaVersion="$(grep -Po '(?<=pragma solidity \^)\d+.\d+.\d+' "$f")"
|
|
|
|
sign="^"
|
|
|
|
elif (grep -Po '(?<=pragma solidity >)\d+.\d+.\d+' "$f" >/dev/null)
|
|
|
|
then
|
|
|
|
pragmaVersion="$(grep -Po '(?<=pragma solidity >)\d+.\d+.\d+' "$f")"
|
|
|
|
sign=">"
|
|
|
|
greater=true;
|
|
|
|
else
|
|
|
|
printError "No valid pragma statement in file. Skipping..."
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
version=""
|
2021-01-14 13:39:41 +00:00
|
|
|
for ver in "${allVersions[@]}" "$developmentVersion"
|
2020-03-28 23:02:44 +00:00
|
|
|
do
|
|
|
|
if versionGreater "$ver" "$pragmaVersion"
|
|
|
|
then
|
2020-12-12 03:32:22 +00:00
|
|
|
version="$ver"
|
2020-03-28 23:02:44 +00:00
|
|
|
break
|
2021-01-14 13:40:50 +00:00
|
|
|
elif [[ "$greater" == false ]] && versionEqual "$ver" "$pragmaVersion"
|
2020-03-28 23:02:44 +00:00
|
|
|
then
|
|
|
|
version="$ver"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2021-01-14 13:40:50 +00:00
|
|
|
if [[ "$version" == "" ]]
|
2020-03-28 23:02:44 +00:00
|
|
|
then
|
2021-01-14 13:44:11 +00:00
|
|
|
printError "No release ${sign}${pragmaVersion} was listed in available releases!"
|
|
|
|
exit 1
|
2020-03-28 23:02:44 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-01-28 15:34:38 +00:00
|
|
|
printTask "Verifying that all examples from the documentation have the correct version range..."
|
|
|
|
SOLTMPDIR=$(mktemp -d)
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
cd "$SOLTMPDIR"
|
2021-07-01 13:19:38 +00:00
|
|
|
"$REPO_ROOT"/scripts/isolate_tests.py "$REPO_ROOT"/docs/
|
2020-01-28 15:34:38 +00:00
|
|
|
|
2020-03-28 23:02:44 +00:00
|
|
|
getAllAvailableVersions
|
|
|
|
|
2020-01-28 15:34:38 +00:00
|
|
|
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"
|
|
|
|
|
2020-12-11 20:34:55 +00:00
|
|
|
opts=()
|
2020-01-28 15:34:38 +00:00
|
|
|
# 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
|
2020-12-11 20:34:55 +00:00
|
|
|
opts=(-e)
|
2020-01-28 15:34:38 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# ignore warnings in this case
|
2020-12-11 20:34:55 +00:00
|
|
|
opts+=(-o)
|
2020-01-28 15:34:38 +00:00
|
|
|
|
2020-12-11 17:19:53 +00:00
|
|
|
findMinimalVersion "$f"
|
2021-01-14 13:40:50 +00:00
|
|
|
if [[ "$version" == "" ]]
|
2020-03-28 23:02:44 +00:00
|
|
|
then
|
|
|
|
continue
|
2020-01-28 15:34:38 +00:00
|
|
|
fi
|
2021-01-14 13:39:41 +00:00
|
|
|
if [[ "$version" == "$developmentVersion" ]]
|
|
|
|
then
|
|
|
|
printWarning "Skipping unreleased development version $developmentVersion"
|
|
|
|
continue
|
|
|
|
fi
|
2020-01-28 15:34:38 +00:00
|
|
|
|
2020-12-11 20:34:55 +00:00
|
|
|
opts+=(-v "$version")
|
2020-01-28 15:34:38 +00:00
|
|
|
|
|
|
|
solc_bin="solc-$version"
|
|
|
|
echo "$solc_bin"
|
2020-03-28 23:02:44 +00:00
|
|
|
if [[ ! -f "$solc_bin" ]]
|
|
|
|
then
|
2020-01-28 15:34:38 +00:00
|
|
|
echo "Downloading release from github..."
|
2020-12-11 17:19:53 +00:00
|
|
|
if wget -q "https://github.com/ethereum/solidity/releases/download/v$version/solc-static-linux" >/dev/null
|
2020-03-28 23:02:44 +00:00
|
|
|
then
|
2020-12-11 17:19:53 +00:00
|
|
|
mv solc-static-linux "$solc_bin"
|
2020-03-28 23:02:44 +00:00
|
|
|
else
|
|
|
|
printError "No release $version was found on github!"
|
|
|
|
continue
|
|
|
|
fi
|
2020-01-28 15:34:38 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
ln -sf "$solc_bin" "solc"
|
|
|
|
chmod a+x solc
|
|
|
|
|
2020-12-12 02:06:27 +00:00
|
|
|
SOLC="$SOLTMPDIR/solc" compileFull "${opts[@]}" "$SOLTMPDIR/$f"
|
2020-01-28 15:34:38 +00:00
|
|
|
done
|
|
|
|
)
|
|
|
|
rm -rf "$SOLTMPDIR"
|
2020-04-17 12:32:38 +00:00
|
|
|
echo "Done."
|