Skip to content

Commit 2c60ee2

Browse files
committed
fix: replace regex with semver crate
1 parent 0f6955c commit 2c60ee2

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

crates/stellar-scaffold-cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ mockito = "0.31"
8989
[build-dependencies]
9090
crate-git-revision = "0.0.6"
9191
toml = "0.9"
92+
semver = "1"
9293

9394
[features]
9495
integration-tests = []

crates/stellar-scaffold-cli/build.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,16 @@ fn emit_local_protocol_version() {
4444
let version = parsed["workspace"]["dependencies"]["stellar-cli"]["version"]
4545
.as_str()
4646
.expect("stellar-cli workspace dependency must pin a version string");
47-
// Strip any semver-requirement prefix (e.g. "=27.0.0") before taking the major.
48-
let major = version
49-
.trim_start_matches(['=', '^', '~', '>', '<', ' '])
50-
.split('.')
51-
.next()
52-
.expect("stellar-cli version is empty");
53-
assert!(
54-
major.chars().all(|c| c.is_ascii_digit()),
55-
"could not parse a protocol major version from stellar-cli = \"{version}\""
56-
);
47+
// The pin is a semver requirement (e.g. "=27.0.0"); take the major from its
48+
// first comparator. stellar-cli's major version tracks the protocol.
49+
let req = semver::VersionReq::parse(version)
50+
.unwrap_or_else(|e| panic!("invalid stellar-cli version requirement \"{version}\": {e}"));
51+
let major = req
52+
.comparators
53+
.first()
54+
.unwrap_or_else(|| {
55+
panic!("stellar-cli version requirement \"{version}\" has no comparator")
56+
})
57+
.major;
5758
println!("cargo:rustc-env=LOCAL_PROTOCOL_VERSION={major}");
5859
}

0 commit comments

Comments
 (0)