struct Inner {
name: String,
source_id: SourceId,
+ registry_id: Option<SourceId>,
req: VersionReq,
specified_req: bool,
kind: Kind,
inner: Rc::new(Inner {
name: name.to_string(),
source_id: source_id.clone(),
+ registry_id: None,
req: VersionReq::any(),
kind: Kind::Normal,
only_match_name: true,
&self.inner.source_id
}
+ pub fn registry_id(&self) -> Option<&SourceId> {
+ self.inner.registry_id.as_ref()
+ }
+
+ pub fn set_registry_id(&mut self, registry_id: &SourceId) -> &mut Dependency {
+ Rc::make_mut(&mut self.inner).registry_id = Some(registry_id.clone());
+ self
+ }
+
pub fn kind(&self) -> Kind {
self.inner.kind
}
// If the dependency is from a different registry, then include the
// registry in the dependency.
- let dep_registry = if dep.source_id() != registry_id {
- Some(dep.source_id().url().to_string())
+ let dep_registry_id = match dep.registry_id() {
+ Some(id) => id,
+ None => bail!("dependency missing registry ID"),
+ };
+ let dep_registry = if dep_registry_id != registry_id {
+ Some(dep_registry_id.url().to_string())
} else {
None
};
- NewCrateDependency {
+ Ok(NewCrateDependency {
optional: dep.is_optional(),
default_features: dep.uses_default_features(),
name: dep.name().to_string(),
Kind::Development => "dev",
}.to_string(),
registry: dep_registry,
- }
- }).collect::<Vec<NewCrateDependency>>();
+ })
+ }).collect::<CargoResult<Vec<NewCrateDependency>>>()?;
let manifest = pkg.manifest();
let ManifestMetadata {
ref authors, ref description, ref homepage, ref documentation,
}
}
+ let registry_id = match details.registry {
+ Some(ref registry) => {
+ cx.features.require(Feature::alternative_registries())?;
+ SourceId::alt_registry(cx.config, registry)?
+ }
+ None => SourceId::crates_io(cx.config)?
+ };
+
let new_source_id = match (details.git.as_ref(), details.path.as_ref(), details.registry.as_ref()) {
(Some(_), _, Some(_)) => bail!("dependency ({}) specification is ambiguous. \
Only one of `git` or `registry` is allowed.", name),
- (_, Some(_), Some(_)) => bail!("dependency ({}) specification is ambiguous. \
- Only one of `path` or `registry` is allowed.", name),
(Some(git), maybe_path, _) => {
if maybe_path.is_some() {
let msg = format!("dependency ({}) specification is ambiguous. \
cx.source_id.clone()
}
},
- (None, None, Some(registry)) => {
- cx.features.require(Feature::alternative_registries())?;
- SourceId::alt_registry(cx.config, registry)?
- }
+ (None, None, Some(registry)) => SourceId::alt_registry(cx.config, registry)?,
(None, None, None) => SourceId::crates_io(cx.config)?,
};
.or(details.default_features2)
.unwrap_or(true))
.set_optional(details.optional.unwrap_or(false))
- .set_platform(cx.platform.clone());
+ .set_platform(cx.platform.clone())
+ .set_registry_id(®istry_id);
if let Some(kind) = kind {
dep.set_kind(kind);
}
}
#[test]
-fn registry_incompatible_with_path() {
+fn registry_and_path_dep_works() {
+ registry::init();
+
let p = project("foo")
.file("Cargo.toml", r#"
cargo-features = ["alternative-registries"]
authors = []
[dependencies.bar]
- path = ""
+ path = "bar"
registry = "alternative"
"#)
.file("src/main.rs", "fn main() {}")
+ .file("bar/Cargo.toml", r#"
+ [project]
+ name = "bar"
+ version = "0.0.1"
+ authors = []
+ "#)
+ .file("bar/src/lib.rs", "")
.build();
assert_that(p.cargo("build").masquerade_as_nightly_cargo(),
- execs().with_status(101)
- .with_stderr_contains(" dependency (bar) specification is ambiguous. Only one of `path` or `registry` is allowed."));
+ execs().with_status(0)
+ .with_stderr(&format!("\
+[COMPILING] bar v0.0.1 ({dir}/bar)
+[COMPILING] foo v0.0.1 ({dir})
+[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] secs
+",
+ dir = p.url())));
}
#[test]
fn registry_incompatible_with_git() {
+ registry::init();
+
let p = project("foo")
.file("Cargo.toml", r#"
cargo-features = ["alternative-registries"]