Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sc-meta - version fixes #1874

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion framework/derive/src/format/semver_tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ fn convert_token_tree(token: &proc_macro2::TokenTree) -> proc_macro2::TokenStrea
}

fn u64_literal_from_str(s: &str) -> proc_macro2::TokenTree {
// For some reason a space creeps in at the end,
// but only when running from rust-analyzer,
// therefore also calling a trim()
proc_macro2::TokenTree::Literal(proc_macro2::Literal::u64_suffixed(
s.parse().expect("failed to parse token as u64"),
s.trim()
.parse()
.unwrap_or_else(|err| panic!("failed to parse token as u64 '{s}': {err}")),
))
}
24 changes: 12 additions & 12 deletions framework/meta-lib/src/cargo_toml/cargo_toml_contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,10 @@ mod tests {

const CARGO_TOML_RAW: &str = r#"
[dependencies.by-version-1]
version = "1.2.30"
version = "0.54.0"

[dependencies.by-version-1-strict]
version = "=1.2.31"
version = "=0.54.1"

[dependencies.by-git-commit-1]
git = "https://github.com/multiversx/repo1"
Expand All @@ -371,8 +371,8 @@ rev = "85c31b9ce730bd5ffe41589c353d935a14baaa96"
path = "a/b/c"

[dependencies]
by-version-2 = "4.5.60"
by-version-2-strict = "=4.5.61"
by-version-2 = "0.54.2"
by-version-2-strict = "=0.54.3"
by-path-2 = { path = "d/e/f" }
by-git-commit-2 = { git = "https://github.com/multiversx/repo2", rev = "e990be823f26d1e7f59c71536d337b7240dc3fa2" }
"#;
Expand All @@ -386,13 +386,13 @@ by-git-commit-2 = { git = "https://github.com/multiversx/repo2", rev = "e990be82
assert_eq!(
raw_value,
DependencyRawValue {
version: Some("1.2.30".to_owned()),
version: Some("0.54.0".to_owned()),
..Default::default()
},
);
assert_eq!(
raw_value.interpret(),
DependencyReference::Version(VersionReq::from_version_str("1.2.30")),
DependencyReference::Version(VersionReq::from_version_str("0.54.0").unwrap()),
);

// version, strict
Expand All @@ -402,27 +402,27 @@ by-git-commit-2 = { git = "https://github.com/multiversx/repo2", rev = "e990be82
assert_eq!(
raw_value,
DependencyRawValue {
version: Some("=1.2.31".to_owned()),
version: Some("=0.54.1".to_owned()),
..Default::default()
},
);
assert_eq!(
raw_value.interpret(),
DependencyReference::Version(VersionReq::from_version_str("1.2.31").strict()),
DependencyReference::Version(VersionReq::from_version_str("0.54.1").unwrap().strict()),
);

// version, compact
let raw_value = cargo_toml.dependency_raw_value("by-version-2").unwrap();
assert_eq!(
raw_value,
DependencyRawValue {
version: Some("4.5.60".to_owned()),
version: Some("0.54.2".to_owned()),
..Default::default()
},
);
assert_eq!(
raw_value.interpret(),
DependencyReference::Version(VersionReq::from_version_str("4.5.60")),
DependencyReference::Version(VersionReq::from_version_str("0.54.2").unwrap()),
);

// version, compact, strict
Expand All @@ -432,13 +432,13 @@ by-git-commit-2 = { git = "https://github.com/multiversx/repo2", rev = "e990be82
assert_eq!(
raw_value,
DependencyRawValue {
version: Some("=4.5.61".to_owned()),
version: Some("=0.54.3".to_owned()),
..Default::default()
},
);
assert_eq!(
raw_value.interpret(),
DependencyReference::Version(VersionReq::from_version_str("4.5.61").strict()),
DependencyReference::Version(VersionReq::from_version_str("0.54.3").unwrap().strict()),
);

// git
Expand Down
16 changes: 11 additions & 5 deletions framework/meta-lib/src/cargo_toml/cargo_toml_deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum DependencyReference {
GitBranch(GitBranchReference),
GitTag(GitTagReference),
Path(String),
Unsupported(&'static str),
Unsupported(String),
}

impl DependencyReference {
Expand Down Expand Up @@ -66,20 +66,26 @@ impl DependencyRawValue {
},

(None, None, None) => DependencyReference::Unsupported(
"need at least one of: git commit, git brach, or git tag",
"need at least one of: git commit, git brach, or git tag".to_owned(),
),
_ => DependencyReference::Unsupported(
"can only have one of: git commit, git brach, or git tag",
"can only have one of: git commit, git brach, or git tag".to_owned(),
),
};
}

// explicit version = "..."
// handled last, because it has the lowest priority, both path and git fields override it
if let Some(version) = self.version {
return DependencyReference::Version(VersionReq::from_version_str(&version));
if let Some(version_req) = VersionReq::from_version_str(&version) {
return DependencyReference::Version(version_req);
} else {
return DependencyReference::Unsupported(format!(
"unknown framework version: {version}"
));
}
}

DependencyReference::Unsupported("expected at least one of: version, git, path")
DependencyReference::Unsupported("expected at least one of: version, git, path".to_owned())
}
}
16 changes: 15 additions & 1 deletion framework/meta-lib/src/cargo_toml/version_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,21 @@ pub struct VersionReq {
pub is_strict: bool,
}
impl VersionReq {
pub fn from_version_str(raw: &str) -> Self {
pub fn from_version_str(raw: &str) -> Option<Self> {
if let Some(stripped_version) = raw.strip_prefix('=') {
Some(VersionReq {
semver: find_version_by_str(stripped_version)?.clone(),
is_strict: true,
})
} else {
Some(VersionReq {
semver: find_version_by_str(raw)?.clone(),
is_strict: false,
})
}
}

pub fn from_version_str_or_latest(raw: &str) -> Self {
if let Some(stripped_version) = raw.strip_prefix('=') {
VersionReq {
semver: find_version_by_str(stripped_version)
Expand Down
7 changes: 3 additions & 4 deletions framework/meta-lib/src/version_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ pub const VERSIONS: &[FrameworkVersion] = framework_versions![
0.53.1,
0.53.2,
0.54.0,
0.54.1,
0.54.2,
0.54.3,
0.54.4,
];

Expand Down Expand Up @@ -114,10 +117,6 @@ pub const CHECK_AFTER_UPGRADE_TO: &[FrameworkVersion] = framework_versions![
0.51.1,
0.52.3,
0.53.2,
0.54.0,
0.54.1,
0.54.2,
0.54.3,
0.54.4,
];

Expand Down
2 changes: 1 addition & 1 deletion framework/meta/src/cmd/upgrade/upgrade_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ fn change_version_string(
framework_crate_name: &str,
) {
let version_string_before = version_string.clone();
let mut version_spec = VersionReq::from_version_str(&std::mem::take(version_string));
let mut version_spec = VersionReq::from_version_str_or_latest(&std::mem::take(version_string));
if version_spec.semver == *from_version {
version_spec.semver = to_version.clone();
}
Expand Down
Loading