Skip to content

Commit

Permalink
Default urls in [replace] to crates.io
Browse files Browse the repository at this point in the history
The intention was to do this, and it mistakenly didn't happen!

Closes #3235
  • Loading branch information
alexcrichton committed Nov 3, 2016
1 parent 7823422 commit 0d038a9
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/cargo/core/package_id_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ impl PackageIdSpec {
pub fn version(&self) -> Option<&Version> { self.version.as_ref() }
pub fn url(&self) -> Option<&Url> { self.url.as_ref() }

pub fn set_url(&mut self, url: Url) {
self.url = Some(url);
}

pub fn matches(&self, package_id: &PackageId) -> bool {
if self.name() != package_id.name() { return false }

Expand Down
6 changes: 5 additions & 1 deletion src/cargo/util/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use core::{EitherManifest, VirtualManifest};
use core::dependency::{Kind, Platform};
use core::manifest::{LibKind, Profile, ManifestMetadata};
use core::package_id::Metadata;
use sources::CRATES_IO;
use util::{self, CargoResult, human, ToUrl, ToSemver, ChainError, Config};

/// Representation of the projects file layout.
Expand Down Expand Up @@ -740,11 +741,14 @@ impl TomlManifest {
-> CargoResult<Vec<(PackageIdSpec, Dependency)>> {
let mut replace = Vec::new();
for (spec, replacement) in self.replace.iter().flat_map(|x| x) {
let spec = try!(PackageIdSpec::parse(spec).chain_error(|| {
let mut spec = try!(PackageIdSpec::parse(spec).chain_error(|| {
human(format!("replacements must specify a valid semver \
version to replace, but `{}` does not",
spec))
}));
if spec.url().is_none() {
spec.set_url(CRATES_IO.parse().unwrap());
}

let version_specified = match *replacement {
TomlDependency::Detailed(ref d) => d.version.is_some(),
Expand Down
56 changes: 53 additions & 3 deletions tests/overrides.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn missing_version() {
error: failed to parse manifest at `[..]`
Caused by:
replacements must specify a version to replace, but `foo` does not
replacements must specify a version to replace, but `[..]foo` does not
"));
}

Expand Down Expand Up @@ -468,7 +468,7 @@ fn override_wrong_name() {
execs().with_status(101).with_stderr("\
[UPDATING] registry [..]
[UPDATING] git repository [..]
error: no matching package for override `foo:0.1.0` found
error: no matching package for override `[..]foo:0.1.0` found
location searched: file://[..]
version required: = 0.1.0
"));
Expand Down Expand Up @@ -530,7 +530,7 @@ fn override_wrong_version() {
error: failed to parse manifest at `[..]`
Caused by:
replacements cannot specify a version requirement, but found one for `foo:0.1.0`
replacements cannot specify a version requirement, but found one for `[..]foo:0.1.0`
"));
}

Expand Down Expand Up @@ -875,3 +875,53 @@ fn override_an_override() {
assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(0));
}

#[test]
fn overriding_nonexistent_no_spurious() {
Package::new("foo", "0.1.0").dep("bar", "0.1").publish();
Package::new("bar", "0.1.0").publish();

let foo = git::repo(&paths::root().join("override"))
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.1.0"
authors = []
[dependencies]
bar = { path = "bar" }
"#)
.file("src/lib.rs", "pub fn foo() {}")
.file("bar/Cargo.toml", r#"
[package]
name = "bar"
version = "0.1.0"
authors = []
"#)
.file("bar/src/lib.rs", "pub fn foo() {}");
foo.build();


let p = project("local")
.file("Cargo.toml", &format!(r#"
[package]
name = "local"
version = "0.0.1"
authors = []
[dependencies]
foo = "0.1.0"
[replace]
"foo:0.1.0" = {{ git = '{url}' }}
"bar:0.1.0" = {{ git = '{url}' }}
"#, url = foo.url()))
.file("src/lib.rs", "");

assert_that(p.cargo_process("build"),
execs().with_status(0));
assert_that(p.cargo("build"),
execs().with_status(0).with_stderr("\
[FINISHED] [..]
").with_stdout(""));
}

0 comments on commit 0d038a9

Please sign in to comment.