From d09f6e24a2c274f0f2a55068d0e033ddcfda8921 Mon Sep 17 00:00:00 2001 From: Marek Kaput Date: Fri, 6 Oct 2023 20:24:05 +0200 Subject: [PATCH] Add `registry` field to dependency schema (#757) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Stack**: - #767 - #758 - #757 ⬅ ⚠️ *Part of a stack created by [spr](https://github.com/ejoffe/spr). Do not merge manually using the UI - doing so may have unexpected results.* --- scarb/src/core/manifest/toml_manifest.rs | 25 ++++++++++++++----- .../core/publishing/manifest_normalization.rs | 2 ++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/scarb/src/core/manifest/toml_manifest.rs b/scarb/src/core/manifest/toml_manifest.rs index 3050e0b9d..91f2e38a0 100644 --- a/scarb/src/core/manifest/toml_manifest.rs +++ b/scarb/src/core/manifest/toml_manifest.rs @@ -261,6 +261,8 @@ pub struct DetailedTomlDependency { pub branch: Option, pub tag: Option, pub rev: Option, + + pub registry: Option, } #[derive(Debug, Default, Deserialize, Serialize)] @@ -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 { @@ -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() diff --git a/scarb/src/core/publishing/manifest_normalization.rs b/scarb/src/core/publishing/manifest_normalization.rs index 7ac784d72..52c3e3446 100644 --- a/scarb/src/core/publishing/manifest_normalization.rs +++ b/scarb/src/core/publishing/manifest_normalization.rs @@ -117,6 +117,8 @@ fn generate_dependency(dep: &ManifestDependency) -> Result { branch: None, tag: None, rev: None, + // TODO(mkaput): What to do if package is mixing dependencies from different registries? + registry: None, }))) }