CI: Generate optimized and unoptimized bytecode reports in parallel

This commit is contained in:
Kamil Śliwak 2023-06-23 10:27:21 +02:00
parent dabecb600f
commit 92816eb6c5
3 changed files with 77 additions and 25 deletions

View File

@ -37,21 +37,23 @@ interfaces=(
standard-json standard-json
) )
report_files=() for preset in "$@"; do
for platform in "${no_cli_platforms[@]}"; do report_files=()
report_files+=("bytecode-report-${platform}.txt") for platform in "${no_cli_platforms[@]}"; do
done report_files+=("bytecode-report-${platform}-${preset}.txt")
for platform in "${native_platforms[@]}"; do
for interface in "${interfaces[@]}"; do
report_files+=("bytecode-report-${platform}-${interface}.txt")
done done
for platform in "${native_platforms[@]}"; do
for interface in "${interfaces[@]}"; do
report_files+=("bytecode-report-${platform}-${interface}-${preset}.txt")
done
done
echo "Reports to compare:"
printf -- "- %s\n" "${report_files[@]}"
if ! diff --brief --report-identical-files --from-file "${report_files[@]}"; then
diff --unified=0 --report-identical-files --from-file "${report_files[@]}" | head --lines 50
zip "bytecode-reports-${preset}.zip" "${report_files[@]}"
exit 1
fi
done done
echo "Reports to compare:"
printf -- "- %s\n" "${report_files[@]}"
if ! diff --brief --report-identical-files --from-file "${report_files[@]}"; then
diff --unified=0 --report-identical-files --from-file "${report_files[@]}" | head --lines 50
zip "all-bytecode-reports.zip" "${report_files[@]}"
exit 1
fi

View File

@ -83,6 +83,8 @@ commands:
- native - native
binary_path: binary_path:
type: string type: string
preset:
type: string
steps: steps:
- run: - run:
name: Generate bytecode reports for the selected preset name: Generate bytecode reports for the selected preset
@ -90,13 +92,14 @@ commands:
.circleci/parallel_bytecode_report.sh \ .circleci/parallel_bytecode_report.sh \
"<< parameters.label >>" \ "<< parameters.label >>" \
"<< parameters.binary_type >>" \ "<< parameters.binary_type >>" \
"${PWD}/<< parameters.binary_path >>" "${PWD}/<< parameters.binary_path >>" \
"<< parameters.preset >>"
- store_artifacts: - store_artifacts:
path: bytecode-report-<< parameters.label >>-standard-json.txt path: bytecode-report-<< parameters.label >>-standard-json-<< parameters.preset >>.txt
- store_artifacts: - store_artifacts:
path: bytecode-report-<< parameters.label >>-cli.txt path: bytecode-report-<< parameters.label >>-cli-<< parameters.preset >>.txt
- store_artifacts: - store_artifacts:
path: bytecode-report-<< parameters.label >>.txt path: bytecode-report-<< parameters.label >>-<< parameters.preset >>.txt
- persist_to_workspace: - persist_to_workspace:
root: . root: .
paths: paths:
@ -217,6 +220,21 @@ defaults:
name: docs pragma version check name: docs pragma version check
command: ./scripts/docs_version_pragma_check.sh command: ./scripts/docs_version_pragma_check.sh
# --------------------------------------------------------------------------
# Matrix templates
- bytecode_compare_env_presets: &bytecode_compare_env_presets
PRESETS:
legacy-optimize
legacy-no-optimize
- bytecode_compare_preset_matrix: &bytecode_compare_preset_matrix
parameters:
preset:
# NOTE: Keep in sync with preset list in bytecode_compare_env_presets
- legacy-optimize
- legacy-no-optimize
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
# Artifacts Templates # Artifacts Templates
@ -1481,6 +1499,9 @@ jobs:
# are currently built on different Ubuntu base images. # are currently built on different Ubuntu base images.
# 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:
parameters:
preset:
type: string
<<: *base_ubuntu2004_small <<: *base_ubuntu2004_small
parallelism: 2 # For prepare_bytecode_report parallelism: 2 # For prepare_bytecode_report
steps: steps:
@ -1491,8 +1512,12 @@ jobs:
label: "ubuntu2004-static" label: "ubuntu2004-static"
binary_type: native binary_type: native
binary_path: "build/solc/solc-static-linux" binary_path: "build/solc/solc-static-linux"
preset: "<< parameters.preset >>"
b_bytecode_ubu: b_bytecode_ubu:
parameters:
preset:
type: string
<<: *base_ubuntu2204_small <<: *base_ubuntu2204_small
parallelism: 2 # For prepare_bytecode_report parallelism: 2 # For prepare_bytecode_report
steps: steps:
@ -1503,8 +1528,12 @@ jobs:
label: "ubuntu" label: "ubuntu"
binary_type: native binary_type: native
binary_path: "build/solc/solc" binary_path: "build/solc/solc"
preset: "<< parameters.preset >>"
b_bytecode_osx: b_bytecode_osx:
parameters:
preset:
type: string
<<: *base_osx <<: *base_osx
parallelism: 2 # For prepare_bytecode_report parallelism: 2 # For prepare_bytecode_report
steps: steps:
@ -1515,8 +1544,12 @@ jobs:
label: "osx" label: "osx"
binary_type: native binary_type: native
binary_path: "build/solc/solc" binary_path: "build/solc/solc"
preset: "<< parameters.preset >>"
b_bytecode_win: b_bytecode_win:
parameters:
preset:
type: string
<<: *base_win <<: *base_win
parallelism: 2 # For prepare_bytecode_report parallelism: 2 # For prepare_bytecode_report
steps: steps:
@ -1532,8 +1565,12 @@ jobs:
label: "windows" label: "windows"
binary_type: native binary_type: native
binary_path: "build/solc/Release/solc.exe" binary_path: "build/solc/Release/solc.exe"
preset: "<< parameters.preset >>"
b_bytecode_ems: b_bytecode_ems:
parameters:
preset:
type: string
<<: *base_node_small <<: *base_node_small
steps: steps:
- checkout - checkout
@ -1543,18 +1580,23 @@ jobs:
label: "emscripten" label: "emscripten"
binary_type: solcjs binary_type: solcjs
binary_path: "emscripten_build/libsolc/soljson.js" binary_path: "emscripten_build/libsolc/soljson.js"
preset: "<< parameters.preset >>"
t_bytecode_compare: t_bytecode_compare:
<<: *base_ubuntu2204_small <<: *base_ubuntu2204_small
environment:
<<: *bytecode_compare_env_presets
TERM: xterm
MAKEFLAGS: -j 2
steps: steps:
- checkout - checkout
- attach_workspace: - attach_workspace:
at: . at: .
- run: .circleci/compare_bytecode_reports.sh - run: .circleci/compare_bytecode_reports.sh $PRESETS
- store_artifacts: - store_artifacts:
# NOTE: store_artifacts does not support the 'when' attribute. # NOTE: store_artifacts does not support the 'when' attribute.
# Fortunately when the artifact does not exist it just says "No artifact files found" and ignores it. # Fortunately when the artifact does not exist it just says "No artifact files found" and ignores it.
path: all-bytecode-reports.zip path: bytecode-reports-*.zip
- matrix_notify_failure_unless_pr - matrix_notify_failure_unless_pr
c_release_binaries: c_release_binaries:
@ -1704,22 +1746,27 @@ workflows:
# Bytecode comparison: # Bytecode comparison:
- b_bytecode_ubu_static: - b_bytecode_ubu_static:
<<: *on_all_tags_and_branches <<: *on_all_tags_and_branches
matrix: *bytecode_compare_preset_matrix
requires: requires:
- b_ubu_static - b_ubu_static
- b_bytecode_ubu: - b_bytecode_ubu:
<<: *on_all_tags_and_branches <<: *on_all_tags_and_branches
matrix: *bytecode_compare_preset_matrix
requires: requires:
- b_ubu - b_ubu
- b_bytecode_win: - b_bytecode_win:
<<: *on_all_tags_and_branches <<: *on_all_tags_and_branches
matrix: *bytecode_compare_preset_matrix
requires: requires:
- b_win - b_win
- b_bytecode_osx: - b_bytecode_osx:
<<: *on_all_tags_and_branches <<: *on_all_tags_and_branches
matrix: *bytecode_compare_preset_matrix
requires: requires:
- b_osx - b_osx
- b_bytecode_ems: - b_bytecode_ems:
<<: *on_all_tags_and_branches <<: *on_all_tags_and_branches
matrix: *bytecode_compare_preset_matrix
requires: requires:
- b_ems - b_ems
- t_bytecode_compare: - t_bytecode_compare:

View File

@ -27,10 +27,11 @@ set -euo pipefail
# (c) 2023 solidity contributors. # (c) 2023 solidity contributors.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
(( $# == 3 )) || { >&2 echo "Wrong number of arguments."; exit 1; } (( $# == 4 )) || { >&2 echo "Wrong number of arguments."; exit 1; }
label="$1" label="$1"
binary_type="$2" binary_type="$2"
binary_path="$3" # This path must be absolute binary_path="$3" # This path must be absolute
preset="$4"
[[ $binary_type == native || $binary_type == solcjs ]] || { >&2 echo "Invalid binary type: ${binary_type}"; exit 1; } [[ $binary_type == native || $binary_type == solcjs ]] || { >&2 echo "Invalid binary type: ${binary_type}"; exit 1; }
@ -51,7 +52,8 @@ if [[ $binary_type == native ]]; then
python3 ../scripts/bytecodecompare/prepare_report.py \ python3 ../scripts/bytecodecompare/prepare_report.py \
"$binary_path" \ "$binary_path" \
--interface "$interface" \ --interface "$interface" \
--report-file "../bytecode-report-${label}-${interface}.txt" --preset "$preset" \
--report-file "../bytecode-report-${label}-${interface}-${preset}.txt"
else else
echo "Installing solc-js" echo "Installing solc-js"
git clone --depth 1 https://github.com/ethereum/solc-js.git solc-js git clone --depth 1 https://github.com/ethereum/solc-js.git solc-js
@ -69,5 +71,6 @@ else
echo "Generating bytecode reports" echo "Generating bytecode reports"
# shellcheck disable=SC2035 # shellcheck disable=SC2035
./prepare_report.js \ ./prepare_report.js \
*.sol > "../bytecode-report-${label}.txt" --preset "$preset" \
*.sol > "../bytecode-report-${label}-${preset}.txt"
fi fi