Skip to content

Commit

Permalink
Fix dependency-check script to support crate versions (#1129)
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio authored Dec 13, 2023
1 parent 397cc90 commit c1fef8f
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions scripts/check-dependencies.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c1fef8f

Please sign in to comment.