multiversx_sc_meta_lib/cargo_toml/
cargo_toml_deps.rsuse crate::version::FrameworkVersion;
use super::{DependencyRawValue, VersionReq};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GitCommitReference {
pub git: String,
pub rev: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GitBranchReference {
pub git: String,
pub branch: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GitTagReference {
pub git: String,
pub tag: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DependencyReference {
Version(VersionReq),
GitCommit(GitCommitReference),
GitBranch(GitBranchReference),
GitTag(GitTagReference),
Path(String),
Unsupported(String),
}
impl DependencyReference {
pub fn is_framework_version(&self, version: &FrameworkVersion) -> bool {
if let DependencyReference::Version(version_req) = self {
&version_req.semver == version
} else {
false
}
}
}
impl DependencyRawValue {
pub fn interpret(self) -> DependencyReference {
if let Some(path) = self.path {
return DependencyReference::Path(path);
}
if let Some(git) = self.git {
return match (self.rev, self.branch, self.tag) {
(Some(rev), None, None) => {
DependencyReference::GitCommit(GitCommitReference { git, rev })
},
(None, Some(branch), None) => {
DependencyReference::GitBranch(GitBranchReference { git, branch })
},
(None, None, Some(tag)) => {
DependencyReference::GitTag(GitTagReference { git, tag })
},
(None, None, None) => DependencyReference::Unsupported(
"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".to_owned(),
),
};
}
if let Some(version) = self.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".to_owned())
}
}