Skip to content
Open
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
14 changes: 9 additions & 5 deletions crates/build/src/config/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub enum Dependency {
pub enum GitRef {
Rev(String),
Tag(String),
Branch(String),
}

#[derive(Deserialize, Default)]
Expand All @@ -51,6 +52,8 @@ struct RawDependency {
rev: Option<String>,
/// The specific tag to download (only applicable if `git` is provided).
tag: Option<String>,
/// The specific branch to download (only applicable if `branch` is provided)
branch: Option<String>,
}

impl DependencyConfig {
Expand Down Expand Up @@ -144,17 +147,18 @@ impl RawDependency {
(Some(_), Some(_)) => Err(DependencyValidationError::Conflicting(name.into())),
(None, None) => Err(DependencyValidationError::Missing(name.into())),
(Some(p), None) => {
if self.rev.is_some() || self.tag.is_some() {
if self.rev.is_some() || self.tag.is_some() || self.branch.is_some() {
return Err(DependencyValidationError::PathWithGitField(name.into()));
}

Ok(Dependency::Path(p))
}
(None, Some(url)) => {
let reference = match (self.rev, self.tag) {
(None, None) => None,
(Some(v), None) => Some(GitRef::Rev(v)),
(None, Some(t)) => Some(GitRef::Tag(t)),
let reference = match (self.rev, self.tag, self.branch) {
(None, None, None) => None,
(Some(v), None, None) => Some(GitRef::Rev(v)),
(None, Some(t), None) => Some(GitRef::Tag(t)),
(None, None, Some(b)) => Some(GitRef::Branch(b)),
_ => return Err(DependencyValidationError::ConflictingGitRef(name.into())),
};

Expand Down
4 changes: 2 additions & 2 deletions crates/build/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ pub enum DependencyValidationError {
#[error("Invalid dependency '{0}': cannot specify both 'path' and 'git', choose one")]
Conflicting(String),

#[error("Invalid dependency '{0}': `path` cannot be combined with git-only fields (rev/tag)")]
#[error("Invalid dependency '{0}': `path` cannot be combined with git-only fields (rev/tag/branch)")]
PathWithGitField(String),

#[error("Invalid dependency '{0}': only one of `rev`, `tag` may be set")]
#[error("Invalid dependency '{0}': only one of `rev`, `tag`, `branch` may be set")]
ConflictingGitRef(String),
}

Expand Down
7 changes: 4 additions & 3 deletions crates/build/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ impl ArtifactsResolver {
let repo_name = clean_url.split('/').next_back()?;

let tag = match reference {
Some(GitRef::Rev(rev)) => rev.as_str(),
Some(GitRef::Tag(tag)) => tag.as_str(),
None => "HEAD",
Some(GitRef::Rev(rev)) => format!("rev={rev}"),
Some(GitRef::Tag(tag)) => format!("tag={tag}"),
Some(GitRef::Branch(branch)) => format!("branch={branch}"),
None => "HEAD".into(),
};
let url = format!("{url}@{tag}");

Expand Down
2 changes: 1 addition & 1 deletion crates/cli/assets/Simplex.default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# out_dir = "./src/artifacts"

# [dependencies]
# some_dep = { git = "<git url>", path = "<or relative path>", <tag | rev> = "<tag name | commit>" }
# some_dep = { git = "<git url>", path = "<or relative path>", <tag | rev | branch> = "<tag name | commit | branch>" }

# [regtest]
# mnemonic = "exist carry drive collect lend cereal occur much tiger just involve mean"
Expand Down
3 changes: 3 additions & 0 deletions crates/cli/src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ impl Install {
execute_git(&["clone", url, target_str])?;
execute_git(&["-C", target_str, "checkout", rev.as_str()])?;
}
Some(GitRef::Branch(branch)) => {
execute_git(&["clone", "--depth", "1", "--branch", branch.as_str(), url, target_str])?;
}
None => {
execute_git(&["clone", "--depth", "1", url, target_str])?;
}
Expand Down