Skip to content

Commit

Permalink
Add registry field to dependency schema
Browse files Browse the repository at this point in the history
commit-id:3dd75c42
  • Loading branch information
mkaput committed Oct 6, 2023
1 parent 0088929 commit 9ea3f37
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
25 changes: 19 additions & 6 deletions scarb/src/core/manifest/toml_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ pub struct DetailedTomlDependency {
pub branch: Option<String>,
pub tag: Option<String>,
pub rev: Option<String>,

pub registry: Option<Url>,
}

#[derive(Debug, Default, Deserialize, Serialize)]
Expand Down Expand Up @@ -881,25 +883,35 @@ impl DetailedTomlDependency {
only one of `branch`, `tag` or `rev` is allowed"
);
}
let source_id = match (self.version.as_ref(), self.git.as_ref(), self.path.as_ref()) {
(None, None, None) => bail!(
let source_id = match (
self.version.as_ref(),
self.git.as_ref(),
self.path.as_ref(),
self.registry.as_ref(),
) {
(None, None, None, _) => bail!(
"dependency ({name}) must be specified providing a local path, Git repository, \
or version to use"
),

(_, Some(_), Some(_)) => bail!(
(_, Some(_), Some(_), _) => bail!(
"dependency ({name}) specification is ambiguous, \
only one of `git` or `path` is allowed"
),

(_, None, Some(path)) => {
(_, Some(_), _, Some(_)) => bail!(
"dependency ({name}) specification is ambiguous, \
only one of `git` or `registry` is allowed"
),

(_, None, Some(path), _) => {
let path = path
.relative_to_file(manifest_path)?
.join(MANIFEST_FILE_NAME);
SourceId::for_path(&path)?
}

(_, Some(git), None) => {
(_, Some(git), None, None) => {
let reference = if let Some(branch) = &self.branch {
GitReference::Branch(branch.into())
} else if let Some(tag) = &self.tag {
Expand All @@ -913,7 +925,8 @@ impl DetailedTomlDependency {
SourceId::for_git(git, &reference)?
}

(Some(_), None, None) => SourceId::default(),
(Some(_), None, None, Some(url)) => SourceId::for_registry(url)?,
(Some(_), None, None, None) => SourceId::default(),
};

Ok(ManifestDependency::builder()
Expand Down
2 changes: 2 additions & 0 deletions scarb/src/core/publishing/manifest_normalization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ fn generate_dependency(dep: &ManifestDependency) -> Result<TomlDependency> {
branch: None,
tag: None,
rev: None,
// TODO(mkaput): What to do if package is mixing dependencies from different registries?
registry: None,
})))
}

Expand Down

0 comments on commit 9ea3f37

Please sign in to comment.