CI: Merge prepare_bytecode_report and storebytecode.sh script into a new script and use it for all platforms in CI

This commit is contained in:
Kamil Śliwak 2023-06-23 10:24:15 +02:00
parent 69ffcfc242
commit 45c2ffcd55
3 changed files with 98 additions and 118 deletions

View File

@ -76,34 +76,31 @@ commands:
parameters: parameters:
label: label:
type: string type: string
binary_type:
type: enum
enum:
- solcjs
- native
binary_path: binary_path:
type: string type: string
steps: steps:
- run: mkdir test-cases/
- run: - run:
name: Prepare input files name: Generate bytecode reports for the selected preset
command: | command: |
cd test-cases/ .circleci/parallel_bytecode_report.sh \
python3 ../scripts/isolate_tests.py ../test/ "<< parameters.label >>" \
- run: "<< parameters.binary_type >>" \
name: Generate bytecode report "${PWD}/<< parameters.binary_path >>"
command: |
cd test-cases/
interface=$(echo -e "standard-json\ncli" | circleci tests split)
echo "Selected interface: ${interface}"
python3 ../scripts/bytecodecompare/prepare_report.py \
<< parameters.binary_path >> \
--interface "$interface" \
--report-file "../bytecode-report-<< parameters.label >>-${interface}.txt"
- store_artifacts: - store_artifacts:
path: bytecode-report-<< parameters.label >>-standard-json.txt path: bytecode-report-<< parameters.label >>-standard-json.txt
- store_artifacts: - store_artifacts:
path: bytecode-report-<< parameters.label >>-cli.txt path: bytecode-report-<< parameters.label >>-cli.txt
- store_artifacts:
path: bytecode-report-<< parameters.label >>.txt
- persist_to_workspace: - persist_to_workspace:
root: . root: .
paths: paths:
- bytecode-report-<< parameters.label >>-*.txt - bytecode-report-<< parameters.label >>*.txt
- matrix_notify_failure_unless_pr - matrix_notify_failure_unless_pr
install_python3: install_python3:
@ -1485,10 +1482,6 @@ jobs:
# It can be safely removed once we move both to the same Ubuntu version. # It can be safely removed once we move both to the same Ubuntu version.
b_bytecode_ubu_static: b_bytecode_ubu_static:
<<: *base_ubuntu2004_small <<: *base_ubuntu2004_small
environment:
TERM: xterm
MAKEFLAGS: -j 2
LC_ALL: C
parallelism: 2 # For prepare_bytecode_report parallelism: 2 # For prepare_bytecode_report
steps: steps:
- checkout - checkout
@ -1496,14 +1489,11 @@ jobs:
at: build at: build
- prepare_bytecode_report: - prepare_bytecode_report:
label: "ubuntu2004-static" label: "ubuntu2004-static"
binary_path: "../build/solc/solc-static-linux" binary_type: native
binary_path: "build/solc/solc-static-linux"
b_bytecode_ubu: b_bytecode_ubu:
<<: *base_ubuntu2204_small <<: *base_ubuntu2204_small
environment:
TERM: xterm
MAKEFLAGS: -j 2
LC_ALL: C
parallelism: 2 # For prepare_bytecode_report parallelism: 2 # For prepare_bytecode_report
steps: steps:
- checkout - checkout
@ -1511,14 +1501,11 @@ jobs:
at: build at: build
- prepare_bytecode_report: - prepare_bytecode_report:
label: "ubuntu" label: "ubuntu"
binary_path: "../build/solc/solc" binary_type: native
binary_path: "build/solc/solc"
b_bytecode_osx: b_bytecode_osx:
<<: *base_osx <<: *base_osx
environment:
TERM: xterm
MAKEFLAGS: -j 5
LC_ALL: C
parallelism: 2 # For prepare_bytecode_report parallelism: 2 # For prepare_bytecode_report
steps: steps:
- checkout - checkout
@ -1526,12 +1513,11 @@ jobs:
at: . at: .
- prepare_bytecode_report: - prepare_bytecode_report:
label: "osx" label: "osx"
binary_path: "../build/solc/solc" binary_type: native
binary_path: "build/solc/solc"
b_bytecode_win: b_bytecode_win:
<<: *base_win <<: *base_win
environment:
LC_ALL: C
parallelism: 2 # For prepare_bytecode_report parallelism: 2 # For prepare_bytecode_report
steps: steps:
# NOTE: For bytecode generation we need the input files to be byte-for-byte identical on all # NOTE: For bytecode generation we need the input files to be byte-for-byte identical on all
@ -1544,25 +1530,19 @@ jobs:
at: build at: build
- prepare_bytecode_report: - prepare_bytecode_report:
label: "windows" label: "windows"
binary_path: "../build/solc/Release/solc.exe" binary_type: native
binary_path: "build/solc/Release/solc.exe"
b_bytecode_ems: b_bytecode_ems:
<<: *base_node_small <<: *base_node_small
environment:
SOLC_EMSCRIPTEN: "On"
LC_ALL: C
steps: steps:
- checkout - checkout
- attach_workspace: - attach_workspace:
at: emscripten_build/libsolc at: emscripten_build/libsolc
- run: scripts/bytecodecompare/storebytecode.sh && mv -v report.txt bytecode-report-emscripten.txt - prepare_bytecode_report:
- store_artifacts: label: "emscripten"
path: bytecode-report-emscripten.txt binary_type: solcjs
- persist_to_workspace: binary_path: "emscripten_build/libsolc/soljson.js"
root: .
paths:
- bytecode-report-emscripten.txt
- matrix_notify_failure_unless_pr
t_bytecode_compare: t_bytecode_compare:
<<: *base_ubuntu2204_small <<: *base_ubuntu2204_small

View File

@ -0,0 +1,73 @@
#!/usr/bin/env bash
set -euo pipefail
#------------------------------------------------------------------------------
# Splits all test source code into multiple files, generates bytecode and metadata
# for each file and combines it into a single report.txt file.
#
# The script is meant to be executed in CI on all supported platforms. All generated
# reports must be identical for a given compiler version.
#
# ------------------------------------------------------------------------------
# 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) 2023 solidity contributors.
#------------------------------------------------------------------------------
(( $# == 3 )) || { >&2 echo "Wrong number of arguments."; exit 1; }
label="$1"
binary_type="$2"
binary_path="$3" # This path must be absolute
[[ $binary_type == native || $binary_type == solcjs ]] || { >&2 echo "Invalid binary type: ${binary_type}"; exit 1; }
# NOTE: Locale affects the order of the globbed files.
export LC_ALL=C
mkdir test-cases/
cd test-cases/
echo "Preparing input files"
python3 ../scripts/isolate_tests.py ../test/
if [[ $binary_type == native ]]; then
interface=$(echo -e "standard-json\ncli" | circleci tests split)
echo "Selected interface: ${interface}"
echo "Generating bytecode reports"
python3 ../scripts/bytecodecompare/prepare_report.py \
"$binary_path" \
--interface "$interface" \
--report-file "../bytecode-report-${label}-${interface}.txt"
else
echo "Installing solc-js"
git clone --depth 1 https://github.com/ethereum/solc-js.git solc-js
cp "$binary_path" solc-js/soljson.js
cd solc-js/
npm install
npm run build
cd ..
npm install ./solc-js/dist
cp ../scripts/bytecodecompare/prepare_report.js .
echo "Generating bytecode reports"
# shellcheck disable=SC2035
./prepare_report.js \
*.sol > "../bytecode-report-${label}.txt"
fi

View File

@ -1,73 +0,0 @@
#!/usr/bin/env bash
#------------------------------------------------------------------------------
# Script used for cross-platform comparison of the bytecode generated by the compiler.
# Splits all test source code into multiple files, generates bytecode and metadata
# for each file and combines it into a single report.txt file.
#
# The script is meant to be executed in CI on all supported platforms. All generated
# reports must be identical for a given compiler version.
#
# ------------------------------------------------------------------------------
# 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) 2017 solidity contributors.
#------------------------------------------------------------------------------
set -e
REPO_ROOT="$(dirname "$0")"/../..
cd "$REPO_ROOT"
REPO_ROOT=$(pwd) # make it absolute
BUILD_DIR="${1:-${REPO_ROOT}/build}"
# Set locale to C to prevent it from affecting glob sort order.
export LC_ALL=C
echo "Compiling all test contracts into bytecode..."
TMPDIR=$(mktemp -d)
(
cd "$TMPDIR"
"$REPO_ROOT"/scripts/isolate_tests.py "$REPO_ROOT"/test/
if [[ "$SOLC_EMSCRIPTEN" = "On" ]]
then
echo "Installing solc-js..."
# npm install solc
git clone --depth 1 https://github.com/ethereum/solc-js.git solc-js
cp "$REPO_ROOT/emscripten_build/libsolc/soljson.js" solc-js/
pushd solc-js/
npm install
npm run build
popd
cp "$REPO_ROOT/scripts/bytecodecompare/prepare_report.js" .
npm install ./solc-js/dist
echo "Running the compiler..."
# shellcheck disable=SC2035
./prepare_report.js *.sol > report.txt
echo "Finished running the compiler."
else
"$REPO_ROOT/scripts/bytecodecompare/prepare_report.py" "$BUILD_DIR/solc/solc"
fi
cp report.txt "$REPO_ROOT"
)
rm -rf "$TMPDIR"
echo "Storebytecode finished."