-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1827 from multiversx/build-git
sc-meta - dependency refactor, full support for referencing the framework by git commit
- Loading branch information
Showing
22 changed files
with
550 additions
and
265 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
mod cargo_toml_contents; | ||
mod cargo_toml_deps; | ||
mod cargo_toml_deps_raw; | ||
mod version_req; | ||
|
||
pub use cargo_toml_contents::{ | ||
change_from_base_to_adapter_path, CargoTomlContents, CARGO_TOML_DEPENDENCIES, | ||
CARGO_TOML_DEV_DEPENDENCIES, | ||
}; | ||
pub use cargo_toml_deps::{DependencyReference, GitCommitReference}; | ||
pub use cargo_toml_deps_raw::DependencyRawValue; | ||
pub use version_req::VersionReq; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use crate::version::FrameworkVersion; | ||
|
||
use super::{DependencyRawValue, VersionReq}; | ||
|
||
/// A dependency reference to a git commit. We mostly use git commits when referencing git. | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub struct GitCommitReference { | ||
pub git: String, | ||
pub rev: String, | ||
} | ||
|
||
/// A dependency reference to a git branch. | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub struct GitBranchReference { | ||
pub git: String, | ||
pub branch: String, | ||
} | ||
|
||
/// A dependency reference to a git tag. | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub struct GitTagReference { | ||
pub git: String, | ||
pub tag: String, | ||
} | ||
|
||
/// Models how a dependency is expressed in Cargo.toml. | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub enum DependencyReference { | ||
Version(VersionReq), | ||
GitCommit(GitCommitReference), | ||
GitBranch(GitBranchReference), | ||
GitTag(GitTagReference), | ||
Path(String), | ||
Unsupported(&'static str), | ||
} | ||
|
||
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 { | ||
/// Interprets the raw dependency value as one of several possible formats. | ||
pub fn interpret(self) -> DependencyReference { | ||
// path is top priority | ||
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", | ||
), | ||
_ => DependencyReference::Unsupported( | ||
"can only have one of: git commit, git brach, or git tag", | ||
), | ||
}; | ||
} | ||
|
||
// 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)); | ||
} | ||
|
||
DependencyReference::Unsupported("expected at least one of: version, git, path") | ||
} | ||
} |
Oops, something went wrong.