diff --git a/scripts/build b/scripts/build index 95c535a..fc173ca 100755 --- a/scripts/build +++ b/scripts/build @@ -1,5 +1,5 @@ #!/usr/bin/env bash -export CDIR=`dirname "$0"` +export CDIR=$(dirname "$0") . "$CARGO_HOME/env" . "$CDIR/lib.sh" @@ -11,16 +11,16 @@ trap "exit" INT # This is where docker expects our substrate/polkadot repo to be cd /build -export VERSION=`cat /srtool/VERSION || echo 0.0.0` +export VERSION=$(cat /srtool/VERSION || echo 0.0.0) export GEN="srtool v$VERSION" export LATEST_VERSION=$(curl -L -s https://github.com/paritytech/srtool/raw/master/VERSION) vercomp "$LATEST_VERSION" "$VERSION" case $? in - 0) op='=';; - 1) op='>';; - 2) op='<';; +0) op='=' ;; +1) op='>' ;; +2) op='<' ;; esac if [[ "$op" == ">" && ! "$*" == *"--json"* ]]; then @@ -41,22 +41,24 @@ fi # echo "You are using srtool v$VERSION, it looks newer than the latest version :)" # fi -if [[ ! "$*" =~ --json || "$*" =~ --app ]]; then +if [[ ! "$*" =~ --json || "$*" =~ --app ]]; then echo "🧰 Substrate Runtime Toolbox - $GEN 🧰" echo " - by Chevdor -" fi if [ ! -z "$VERBOSE" ]; then echo "Checking cache size. Give it a few seconds..." - echo -e "📦 Cache size:" `du -sh $HOME/.cargo` + echo -e "📦 Cache size:" $(du -sh $HOME/.cargo) fi # The following is to prevent user's overrides to disturb srtool rustup override set $RUSTC_VERSION +rustup target add wasm32-unknown-unknown +rustup component add rust-src -export RUSTCV=`rustc -V` +export RUSTCV=$(rustc -V) -if [[ ! "$*" =~ --json || "$*" =~ --app ]]; then +if [[ ! "$*" =~ --json || "$*" =~ --app ]]; then echo -e "🏗 Building $PACKAGE as $PROFILE using $RUSTCV" echo -e "⏳ That can take a little while, be patient... subsequent builds may be faster." echo -e " Since you have to wait a little, you may want to learn more about Substrate runtimes:" @@ -74,7 +76,7 @@ fi # runtime directory itself export RUNTIME_NAME="${PACKAGE/-runtime/}" export GET_OPTS_CMD="/srtool/getBuildOpts.sh" -export GET_OPTS=`$GET_OPTS_CMD` +export GET_OPTS=$($GET_OPTS_CMD) export BUILD_OPTS="${BUILD_OPTS:-${GET_OPTS}}" export PROFILE="${PROFILE:-release}" export RUNTIME_DIR="${RUNTIME_DIR:-runtime/$RUNTIME_NAME}" @@ -89,7 +91,7 @@ if [ ! -f "/build/$RUNTIME_DIR/Cargo.toml" ]; then fi CRATE_VERSION=$(get_runtime_package_version "$PACKAGE") -CRATE_NAME=`toml get "/build/$RUNTIME_DIR/Cargo.toml" package.name | jq -r` +CRATE_NAME=$(toml get "/build/$RUNTIME_DIR/Cargo.toml" package.name | jq -r) if [[ $CRATE_NAME != "$PACKAGE" ]]; then echo "!!! The PACKAGE '$PACKAGE' does not match the crate name at '$RUNTIME_DIR'." @@ -111,27 +113,27 @@ else INT_OPTS="" fi -pushd "$RUNTIME_DIR" > /dev/null || exit 1 - # TODO: --out-dir /out would be handy but still unstable. - # See https://doc.rust-lang.org/cargo/commands/cargo-build.html#output-options - CMD="cargo build --locked ${INT_OPTS} ${BUILD_OPTS} --color=$COLOR --profile $PROFILE --target-dir target/srtool" - if [ ! -z "$VERBOSE" ]; then - echo "Command run:" - echo "$CMD" - time $CMD || exit 1 - else - if [[ "$*" == *"--json"* && ! "$*" =~ --app ]]; then - $CMD > /dev/null 2>&1 || exit 1 - else - $CMD 2>&1 || exit 1 - fi - fi - PKG_FILENAME=${PACKAGE//-/_} - WASM=`find "target/srtool/$PROFILE/wbuild/$PACKAGE" -type f -name "${PKG_FILENAME}.compact.wasm"` - Z_WASM=`find "target/srtool/$PROFILE/wbuild/$PACKAGE" -type f -name "${PKG_FILENAME}.compact.compressed.wasm"` -popd > /dev/null || exit 1 - -if [[ ! "$*" =~ --json || "$*" =~ --app ]]; then +pushd "$RUNTIME_DIR" >/dev/null || exit 1 +# TODO: --out-dir /out would be handy but still unstable. +# See https://doc.rust-lang.org/cargo/commands/cargo-build.html#output-options +CMD="cargo build --locked ${INT_OPTS} ${BUILD_OPTS} --color=$COLOR --profile $PROFILE --target-dir target/srtool" +if [ ! -z "$VERBOSE" ]; then + echo "Command run:" + echo "$CMD" + time $CMD || exit 1 +else + if [[ "$*" == *"--json"* && ! "$*" =~ --app ]]; then + $CMD >/dev/null 2>&1 || exit 1 + else + $CMD 2>&1 || exit 1 + fi +fi +PKG_FILENAME=${PACKAGE//-/_} +WASM=$(find "target/srtool/$PROFILE/wbuild/$PACKAGE" -type f -name "${PKG_FILENAME}.compact.wasm") +Z_WASM=$(find "target/srtool/$PROFILE/wbuild/$PACKAGE" -type f -name "${PKG_FILENAME}.compact.compressed.wasm") +popd >/dev/null || exit 1 + +if [[ ! "$*" =~ --json || "$*" =~ --app ]]; then echo "✨ Your Substrate WASM Runtime is ready! ✨" fi @@ -142,33 +144,33 @@ if [ "$Z_WASM" ]; then cp -f "$Z_WASM" /out/ fi -if [[ ! "$*" =~ --json || "$*" =~ --app ]]; then +if [[ ! "$*" =~ --json || "$*" =~ --app ]]; then echo "✨ WASM : $WASM" echo "✨ Z_WASM: $Z_WASM" fi Z_WASM_JSON=$(subwasm -j info "$Z_WASM") -SZ=`du -sb "$Z_WASM" | awk '{print $1}'` -TMSP=`date --utc +%FT%TZ` -SHA256=0x`shasum -a 256 "$Z_WASM" | awk '{print $1}'` -PROP=`echo "$Z_WASM_JSON" | jq -r .proposal_hash` -AUTHORIZE_UPGRADE_PROP=`echo "$Z_WASM_JSON" | jq -r .parachain_authorize_upgrade_hash` -MULTIHASH=`echo "$Z_WASM_JSON" | jq -r .ipfs_hash` +SZ=$(du -sb "$Z_WASM" | awk '{print $1}') +TMSP=$(date --utc +%FT%TZ) +SHA256=0x$(shasum -a 256 "$Z_WASM" | awk '{print $1}') +PROP=$(echo "$Z_WASM_JSON" | jq -r .proposal_hash) +AUTHORIZE_UPGRADE_PROP=$(echo "$Z_WASM_JSON" | jq -r .parachain_authorize_upgrade_hash) +MULTIHASH=$(echo "$Z_WASM_JSON" | jq -r .ipfs_hash) # If we work on a snapshot, we will NOT get a .git folder to work on if [ -d ".git" ]; then SRC='git' - GIT_TAG=`git describe --tags --abbrev=0` - GIT_COMMIT_REF=`git rev-parse HEAD` - GIT_BRANCH=`git rev-parse --abbrev-ref HEAD` + GIT_TAG=$(git describe --tags --abbrev=0) + GIT_COMMIT_REF=$(git rev-parse HEAD) + GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD) else SRC='zip' fi -COMPACT_DETAILS=`/srtool/analyse.sh "$WASM" | tail -n 1` +COMPACT_DETAILS=$(/srtool/analyse.sh "$WASM" | tail -n 1) if [ "$Z_WASM" ]; then - COMPRESSED_DETAILS=`/srtool/analyse.sh "$Z_WASM" | tail -n 1` + COMPRESSED_DETAILS=$(/srtool/analyse.sh "$Z_WASM" | tail -n 1) else COMPRESSED_DETAILS={} fi @@ -176,7 +178,7 @@ fi INFO=$(/srtool/info -cM | tail -n 1) CONTEXT=$(/srtool/getContext.sh | tail -n 1) -JSON=$( jq -n \ +JSON=$(jq -n \ --arg gen "$GEN" \ --arg cargo_version "$CRATE_VERSION" \ --arg rustc "$RUSTCV" \ @@ -221,7 +223,7 @@ JSON=$( jq -n \ compact: $compact, compressed: $compressed } - }' ) + }') if [[ "$*" =~ --json || "$*" =~ --app ]]; then # if using --app, the json output fits on a single line @@ -233,7 +235,7 @@ if [[ "$*" =~ --json || "$*" =~ --app ]]; then if [[ "$*" == *"--save"* ]]; then REPORT="./target/srtool/srtool-wasm-report-$TMSP.txt" - echo "$JSON" > $REPORT + echo "$JSON" >$REPORT echo "Report saved in $REPORT" fi else