From c93db27ba8cc97cccd96dfde46d15f040afbc7f4 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Tue, 12 Dec 2023 17:27:28 -0500 Subject: [PATCH] Fix dependency-check script to support crate versions --- scripts/check-dependencies.bash | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/scripts/check-dependencies.bash b/scripts/check-dependencies.bash index 470ac65ec..7415e3950 100755 --- a/scripts/check-dependencies.bash +++ b/scripts/check-dependencies.bash @@ -8,7 +8,6 @@ if [ -z "$(sed --version 2>&1 | grep GNU)" ]; then fi CURL="curl -sL --fail-with-body" -CARGO_PACKAGE_REVISION_EXTRACT_SED_COMMAND='s/.*rev=\(.*\)#.*/\1/' if ! CARGO_OUTPUT=$(cargo tree -p soroban-env-host 2>&1); then echo "The project depends on multiple versions of the soroban-env-host Rust library, please unify them." @@ -31,9 +30,28 @@ RS_STELLAR_XDR_REVISION="" # revision of https://github.com/stellar/stellar-xdr/ used by the Rust code STELLAR_XDR_REVISION_FROM_RUST="" +function stellar_xdr_version_from_rust_dep_tree { + LINE=$(grep stellar-xdr | head -n 1) + # try to obtain a commit + COMMIT=$(echo $LINE | $SED -n 's/.*rev=\(.*\)#.*/\1/p') + if [ -n "$COMMIT" ]; then + echo "$COMMIT" + return + fi + # obtain a crate version + echo $LINE | $SED -n 's/.*stellar-xdr \(v\)\{0,1\}\([^ ]*\).*/\2/p' +} + if CARGO_OUTPUT=$(cargo tree --depth 0 -p stellar-xdr 2>&1); then - RS_STELLAR_XDR_REVISION=$(echo $CARGO_OUTPUT | head -n 1 | $SED "$CARGO_PACKAGE_REVISION_EXTRACT_SED_COMMAND") - STELLAR_XDR_REVISION_FROM_RUST=$($CURL https://raw.githubusercontent.com/stellar/rs-stellar-xdr/${RS_STELLAR_XDR_REVISION}/xdr/curr-version) + RS_STELLAR_XDR_REVISION=$(echo "$CARGO_OUTPUT" | stellar_xdr_version_from_rust_dep_tree) + if [ ${#RS_STELLAR_XDR_REVISION} -eq 40 ]; then + # revision is a git hash + STELLAR_XDR_REVISION_FROM_RUST=$($CURL https://raw.githubusercontent.com/stellar/rs-stellar-xdr/${RS_STELLAR_XDR_REVISION}/xdr/curr-version) + else + # revision is a crate version + CARGO_SRC_BASE_DIR=$(realpath ${CARGO_HOME:-$HOME/.cargo}/registry/src/index*) + STELLAR_XDR_REVISION_FROM_RUST=$(cat "${CARGO_SRC_BASE_DIR}/stellar-xdr-${RS_STELLAR_XDR_REVISION}/xdr/curr-version") + fi else echo "The project depends on multiple versions of the Rust rs-stellar-xdr library" echo "Make sure a single version of stellar-xdr is used" @@ -81,7 +99,7 @@ fi CORE_HOST_DEP_TREE_CURR=$($CURL https://raw.githubusercontent.com/stellar/stellar-core/${CORE_CONTAINER_REVISION}/src/rust/src/host-dep-tree-curr.txt) -RS_STELLAR_XDR_REVISION_FROM_CORE=$(echo "$CORE_HOST_DEP_TREE_CURR" | grep stellar-xdr | head -n 1 | $SED "$CARGO_PACKAGE_REVISION_EXTRACT_SED_COMMAND") +RS_STELLAR_XDR_REVISION_FROM_CORE=$(echo "$CORE_HOST_DEP_TREE_CURR" | stellar_xdr_version_from_rust_dep_tree) if [ "$RS_STELLAR_XDR_REVISION" != "$RS_STELLAR_XDR_REVISION_FROM_CORE" ]; then echo "The Core revision used in integration tests (${CORE_CONTAINER_REVISION}) uses a different revision of https://github.com/stellar/rs-stellar-xdr" echo