From affdc18113942549e72c71edab6d1d5adc230600 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Thu, 20 Jul 2023 16:06:53 +0100 Subject: [PATCH 1/5] Script to print sizes of all integration test contracts --- scripts/contract_sizes.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100755 scripts/contract_sizes.sh diff --git a/scripts/contract_sizes.sh b/scripts/contract_sizes.sh new file mode 100755 index 0000000000..94548f1bb9 --- /dev/null +++ b/scripts/contract_sizes.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# `find` will recursively list all the `Cargo.toml` manifests in the supplied dir. +# The first -exec command will attempt to build using the discovered Cargo.toml file. If it fails the second -exec +# command will not be run. This allows us to filter out any manifests for in the tree for non-contract crates. + +find ./integration-tests/ -name "Cargo.toml" \ + -exec sh -c 'cargo contract build --manifest-path "$1" --release --quiet 2>/dev/null' _ {} \; \ + -exec sh -c 'cargo contract build --manifest-path "$1" --release --output-json | jq .dest_wasm' _ {} \; \ + -exec sh -c 'cargo contract build --manifest-path "$1" --release --output-json | jq .dest_wasm | xargs stat -c %s' _ {} \; From 0315e14699558bff5642c5ac4914364a1a671680 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Thu, 20 Jul 2023 16:12:27 +0100 Subject: [PATCH 2/5] print only filename of wasm --- scripts/contract_sizes.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/contract_sizes.sh b/scripts/contract_sizes.sh index 94548f1bb9..a82f1d1d18 100755 --- a/scripts/contract_sizes.sh +++ b/scripts/contract_sizes.sh @@ -6,5 +6,5 @@ find ./integration-tests/ -name "Cargo.toml" \ -exec sh -c 'cargo contract build --manifest-path "$1" --release --quiet 2>/dev/null' _ {} \; \ - -exec sh -c 'cargo contract build --manifest-path "$1" --release --output-json | jq .dest_wasm' _ {} \; \ + -exec sh -c 'cargo contract build --manifest-path "$1" --release --output-json | jq .dest_wasm | xargs basename' _ {} \; \ -exec sh -c 'cargo contract build --manifest-path "$1" --release --output-json | jq .dest_wasm | xargs stat -c %s' _ {} \; From adb8d2b99f5358d754479674c2b1160d284b6fee Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Fri, 21 Jul 2023 09:24:50 +0100 Subject: [PATCH 3/5] Process a single contract per script invocation --- scripts/contract_sizes.sh | 43 +++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/scripts/contract_sizes.sh b/scripts/contract_sizes.sh index a82f1d1d18..dd5c7acef8 100755 --- a/scripts/contract_sizes.sh +++ b/scripts/contract_sizes.sh @@ -1,10 +1,37 @@ #!/bin/bash -# `find` will recursively list all the `Cargo.toml` manifests in the supplied dir. -# The first -exec command will attempt to build using the discovered Cargo.toml file. If it fails the second -exec -# command will not be run. This allows us to filter out any manifests for in the tree for non-contract crates. - -find ./integration-tests/ -name "Cargo.toml" \ - -exec sh -c 'cargo contract build --manifest-path "$1" --release --quiet 2>/dev/null' _ {} \; \ - -exec sh -c 'cargo contract build --manifest-path "$1" --release --output-json | jq .dest_wasm | xargs basename' _ {} \; \ - -exec sh -c 'cargo contract build --manifest-path "$1" --release --output-json | jq .dest_wasm | xargs stat -c %s' _ {} \; +SCRIPT_NAME="${BASH_SOURCE[0]}" +MANIFEST_PATH=$1 + +function usage { + cat << EOF +Usage: ${SCRIPT_NAME} MANIFEST_PATH + +Build and print the contract name and size for the given manifest path, if it is a valid ink! contract project. +Use with `find` (see EXAMPLES) to print the contract name and size for all ink! contracts in a directory. + +MANIFEST_PATH + Path to the Cargo.toml manifest file for a contract project + +EXAMPLES + ${SCRIPT_NAME} ./Cargo.toml + find ./integration-tests/ -name "Cargo.toml" -exec ${SCRIPT_NAME} {} \; + +EOF +} + +if [ -z "$MANIFEST_PATH" ]; then + usage + exit 1 +fi + +BUILD_RESULT=$(cargo contract build --manifest-path "$MANIFEST_PATH" --release --quiet --output-json 2>/dev/null) + +if [ $? -eq 0 ]; then + # only print the contract name and size if the build was successful + DEST_WASM=$(echo "$BUILD_RESULT" | jq -r .dest_wasm) + CONTRACT_NAME=$(basename "$DEST_WASM") + CONTRACT_SIZE=$(stat -c %s "$DEST_WASM") + + echo "$CONTRACT_NAME" "$CONTRACT_SIZE" +fi From 3352b3c3ee71f1b62b7a68a160b4a5ca9f127b95 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Fri, 21 Jul 2023 09:25:59 +0100 Subject: [PATCH 4/5] Rename --- scripts/{contract_sizes.sh => contract_size.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts/{contract_sizes.sh => contract_size.sh} (100%) diff --git a/scripts/contract_sizes.sh b/scripts/contract_size.sh similarity index 100% rename from scripts/contract_sizes.sh rename to scripts/contract_size.sh From 14f0392d3218d62e2f4b9939ff9da451e2abfa5b Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Fri, 21 Jul 2023 09:28:10 +0100 Subject: [PATCH 5/5] Remove extension --- scripts/contract_size.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/contract_size.sh b/scripts/contract_size.sh index dd5c7acef8..fde80638ba 100755 --- a/scripts/contract_size.sh +++ b/scripts/contract_size.sh @@ -30,7 +30,7 @@ BUILD_RESULT=$(cargo contract build --manifest-path "$MANIFEST_PATH" --release - if [ $? -eq 0 ]; then # only print the contract name and size if the build was successful DEST_WASM=$(echo "$BUILD_RESULT" | jq -r .dest_wasm) - CONTRACT_NAME=$(basename "$DEST_WASM") + CONTRACT_NAME=$(basename "$DEST_WASM" .wasm) CONTRACT_SIZE=$(stat -c %s "$DEST_WASM") echo "$CONTRACT_NAME" "$CONTRACT_SIZE"