Skip to content

Commit

Permalink
Revert formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ntn-x2 committed Dec 2, 2024
1 parent 2dd835c commit 4a9b64f
Showing 1 changed file with 47 additions and 47 deletions.
94 changes: 47 additions & 47 deletions scripts/build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
export CDIR=$(dirname "$0")
export CDIR=`dirname "$0"`
. "$CARGO_HOME/env"
. "$CDIR/lib.sh"

Expand All @@ -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
Expand All @@ -41,23 +41,23 @@ 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

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:"
Expand All @@ -75,7 +75,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}"
Expand All @@ -90,7 +90,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'."
Expand All @@ -112,27 +112,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

Expand All @@ -143,41 +143,41 @@ 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

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" \
Expand Down Expand Up @@ -222,7 +222,7 @@ JSON=$(jq -n \
compact: $compact,
compressed: $compressed
}
}')
}' )

if [[ "$*" =~ --json || "$*" =~ --app ]]; then
# if using --app, the json output fits on a single line
Expand All @@ -234,7 +234,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
Expand Down

0 comments on commit 4a9b64f

Please sign in to comment.