]> git.proxmox.com Git - cargo.git/commitdiff
Default urls in [replace] to crates.io
authorAlex Crichton <alex@alexcrichton.com>
Wed, 2 Nov 2016 17:32:35 +0000 (10:32 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 3 Nov 2016 16:02:12 +0000 (09:02 -0700)
The intention was to do this, and it mistakenly didn't happen!

Closes #3235

src/cargo/core/package_id_spec.rs
src/cargo/util/toml.rs
tests/overrides.rs

index 3299ada5738c9c4a6870e30584e5efbfc292d73f..a07b69e49f7ad0318c8f44232a733782c1ca163b 100644 (file)
@@ -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 }
 
index bc72b5ee99bce26324b2ee11f64a01b82b6343d7..dc5f92870e6a64a028beef7c6d67b6faeefc9352 100644 (file)
@@ -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.
@@ -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(),
index c7d56799f60beb300c00f4687e6b89e1bd0e36be..ba17e0f3253b72a04d6cdc4c7877e8aec7216a37 100644 (file)
@@ -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
 "));
 }
 
@@ -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
 "));
@@ -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`
 "));
 }
 
@@ -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(""));
+}