diff --git a/.circleci/config.yml b/.circleci/config.yml index ac1dda7dd..9ccf7a663 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -651,6 +651,19 @@ jobs: SOLTEST_FLAGS: --no-smt ASAN_OPTIONS: check_initialization_order=true:detect_stack_use_after_return=true:strict_init_order=true:strict_string_checks=true:detect_invalid_pointer_pairs=2 + t_ubu_pragma_docs_test: &t_ubu_pragma_docs_test + docker: + - image: ethereum/solidity-buildpack-deps:ubuntu1904-<< pipeline.parameters.ubuntu-1904-docker-image-rev >> + environment: + TERM: xterm + steps: + - checkout + - attach_workspace: + at: build + - run: *run_docs_version_pragma_check + - store_test_results: *store_test_results + - store_artifacts: *artifacts_test_results + t_ems_solcjs: docker: - image: ethereum/solidity-buildpack-deps:ubuntu1904 @@ -802,6 +815,7 @@ workflows: - b_ubu: *workflow_trigger_on_tags - b_ubu18: *workflow_trigger_on_tags - t_ubu_cli: *workflow_ubuntu1904 + - t_ubu_pragma_docs_test: *workflow_ubuntu1904 - t_ubu_soltest: *workflow_ubuntu1904 - b_ubu_clang: *workflow_trigger_on_tags - t_ubu_clang_soltest: *workflow_ubuntu1904_clang diff --git a/docs/examples/blind-auction.rst b/docs/examples/blind-auction.rst index 4461bfc65..f2034272a 100644 --- a/docs/examples/blind-auction.rst +++ b/docs/examples/blind-auction.rst @@ -184,7 +184,7 @@ invalid bids. :: - pragma solidity >0.4.23 <0.7.0; + pragma solidity >=0.5.0 <0.7.0; contract BlindAuction { struct Bid { diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index 12fe4b3f9..8d647a4a7 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -605,8 +605,8 @@ Assume you have the following contracts you want to update declared in ``Source. .. code-block:: none - // This will not compile - pragma solidity >0.4.23; + // This will not compile after 0.5.0 + pragma solidity >0.4.23 <0.5.0; contract Updateable { function run() public view returns (bool); diff --git a/scripts/docs_version_pragma_check.sh b/scripts/docs_version_pragma_check.sh index a66798841..c56bdc6c9 100755 --- a/scripts/docs_version_pragma_check.sh +++ b/scripts/docs_version_pragma_check.sh @@ -32,6 +32,97 @@ SOLIDITY_BUILD_DIR=${SOLIDITY_BUILD_DIR:-build} source "${REPO_ROOT}/scripts/common.sh" source "${REPO_ROOT}/scripts/common_cmdline.sh" +function versionGreater() +{ + v1=$1 + v2=$2 + ver1=( ${v1//./ } ) + ver2=( ${v2//./ } ) + + if (( ${ver1[0]} > ${ver2[0]} )) + then + return 0 + elif (( ${ver1[0]} == ${ver2[0]} )) && (( ${ver1[1]} > ${ver2[1]} )) + then + return 0 + elif (( ${ver1[0]} == ${ver2[0]} )) && (( ${ver1[1]} == ${ver2[1]} )) && (( ${ver1[2]} > ${ver2[2]} )) + then + return 0 + fi + return 1 +} + +function versionEqual() +{ + if [ "$1" == "$2" ] + then + return 0 + fi + return 1 +} + +function getAllAvailableVersions() +{ + allVersions=() + local allListedVersions=( $( + wget -q -O- https://ethereum.github.io/solc-bin/bin/list.txt | + grep -Po '(?<=soljson-v)\d+.\d+.\d+(?=\+commit)' | + sort -V + ) ) + for listed in "${allListedVersions[@]}" + do + if versionGreater "$listed" "0.4.10" + then + allVersions+=( $listed ) + 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="" + for ver in "${allVersions[@]}" + do + if versionGreater "$ver" "$pragmaVersion" + then + minVersion="$ver" + break + elif ([ $greater == false ]) && versionEqual "$ver" "$pragmaVersion" + then + version="$ver" + break + fi + done + + if [ -z version ] + then + printError "No release $sign$pragmaVersion was listed in available releases!" + fi +} + printTask "Verifying that all examples from the documentation have the correct version range..." SOLTMPDIR=$(mktemp -d) ( @@ -39,6 +130,8 @@ SOLTMPDIR=$(mktemp -d) cd "$SOLTMPDIR" "$REPO_ROOT"/scripts/isolate_tests.py "$REPO_ROOT"/docs/ docs + getAllAvailableVersions + for f in *.sol do # The contributors guide uses syntax tests, but we cannot @@ -61,27 +154,26 @@ SOLTMPDIR=$(mktemp -d) # 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")" + findMinimalVersion $f + if [ -z "$version" ] + then + continue fi opts="$opts -v $version" solc_bin="solc-$version" echo "$solc_bin" - if [[ ! -f "$solc_bin" ]]; then + 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 + if wget -q https://github.com/ethereum/solidity/releases/download/v$version/solc-static-linux >/dev/null + then + mv solc-static-linux $solc_bin + else + printError "No release $version was found on github!" + continue + fi fi ln -sf "$solc_bin" "solc"