| 1 |
#!/usr/bin/env bash |
| 2 |
# |
| 3 |
# Copyright 2024 The Fuchsia Authors |
| 4 |
# |
| 5 |
# Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 |
| 6 |
# <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT |
| 7 |
# license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. |
| 8 |
# This file may not be copied, modified, or distributed except according to |
| 9 |
# those terms. |
| 10 |
|
| 11 |
set -eo pipefail |
| 12 |
cd "$(dirname "$0")/.." |
| 13 |
|
| 14 |
# Usage: version <crate-name> |
| 15 |
function version { |
| 16 |
cargo metadata -q --format-version 1 | jq -r ".packages[] | select(.name == \"$1\").version" |
| 17 |
} |
| 18 |
|
| 19 |
ver_zerocopy=$(version zerocopy) |
| 20 |
ver_zerocopy_derive=$(version zerocopy-derive) |
| 21 |
|
| 22 |
# Usage: dependency-version <kind> <target> |
| 23 |
function dependency-version { |
| 24 |
KIND="$1" |
| 25 |
TARGET="$2" |
| 26 |
cargo metadata -q --format-version 1 \ |
| 27 |
| jq -r ".packages[] | select(.name == \"zerocopy\").dependencies[] | select((.name == \"zerocopy-derive\") and .kind == $KIND and .target == $TARGET).req" |
| 28 |
} |
| 29 |
|
| 30 |
# The non-dev dependency version (kind `null` filters out the dev |
| 31 |
# dependency, and target `null` filters out the targeted version). |
| 32 |
zerocopy_derive_dep_ver=$(dependency-version null null) |
| 33 |
|
| 34 |
# The non-dev dependency, targeted version (kind `null` filters out |
| 35 |
# the dev dependency). |
| 36 |
zerocopy_derive_targeted_ver=$(dependency-version null '"cfg(any())"') |
| 37 |
|
| 38 |
# The dev dependency version (kind `"dev"` selects only the dev |
| 39 |
# dependency). |
| 40 |
zerocopy_derive_dev_dep_ver=$(dependency-version '"dev"' null) |
| 41 |
|
| 42 |
function assert-match { |
| 43 |
VER_A="$1" |
| 44 |
VER_B="$2" |
| 45 |
SUCCESS_MSG="$3" |
| 46 |
FAILURE_MSG="$4" |
| 47 |
if [[ "$VER_A" == "$VER_B" ]]; then |
| 48 |
echo "$SUCCESS_MSG" | tee -a $GITHUB_STEP_SUMMARY |
| 49 |
else |
| 50 |
echo "$FAILURE_MSG" | tee -a $GITHUB_STEP_SUMMARY >&2 |
| 51 |
exit 1 |
| 52 |
fi |
| 53 |
} |
| 54 |
|
| 55 |
assert-match "$ver_zerocopy" "$ver_zerocopy_derive" \ |
| 56 |
"Same crate version ($ver_zerocopy) found for zerocopy and zerocopy-derive." \ |
| 57 |
"Different crate versions found for zerocopy ($ver_zerocopy) and zerocopy-derive ($ver_zerocopy_derive)." |
| 58 |
|
| 59 |
# Note the leading `=` sign - the dependency needs to be an exact one. |
| 60 |
assert-match "=$ver_zerocopy_derive" "$zerocopy_derive_dep_ver" \ |
| 61 |
"zerocopy depends upon same version of zerocopy-derive in-tree ($zerocopy_derive_dep_ver)." \ |
| 62 |
"zerocopy depends upon different version of zerocopy-derive ($zerocopy_derive_dep_ver) than the one in-tree ($ver_zerocopy_derive)." |
| 63 |
|
| 64 |
# Note the leading `=` sign - the dependency needs to be an exact one. |
| 65 |
assert-match "=$ver_zerocopy_derive" "$zerocopy_derive_dev_dep_ver" \ |
| 66 |
"In dev mode, zerocopy depends upon same version of zerocopy-derive in-tree ($zerocopy_derive_dev_dep_ver)." \ |
| 67 |
"In dev mode, zerocopy depends upon different version of zerocopy-derive ($zerocopy_derive_dev_dep_ver) than the one in-tree ($ver_zerocopy_derive)." |
| 68 |
|
| 69 |
assert-match "$zerocopy_derive_dep_ver" "$zerocopy_derive_targeted_ver" \ |
| 70 |
"Same crate version ($zerocopy_derive_dep_ver) found for optional and targeted zerocopy-derive dependency." \ |
| 71 |
"Different crate versions found for optional ($zerocopy_derive_dep_ver) and targeted ($zerocopy_derive_targeted_ver) dependency." |