From 7eaa1cf70a71858a0278ff0dad2b61763a1a6c27 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 17 Dec 2018 20:35:50 -0800 Subject: [PATCH] Support alt-registry names in [patch] table. --- src/cargo/util/toml/mod.rs | 8 +++++- tests/testsuite/alt_registry.rs | 44 +++++++++++++++++++++++++++++++++ tests/testsuite/patch.rs | 3 +++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index e32aabddd01..3c691d5a465 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -1205,7 +1205,13 @@ impl TomlManifest { for (url, deps) in self.patch.iter().flat_map(|x| x) { let url = match &url[..] { CRATES_IO_REGISTRY => CRATES_IO_INDEX.parse().unwrap(), - _ => url.to_url()?, + _ => cx + .config + .get_registry_index(url) + .or_else(|_| url.to_url()) + .chain_err(|| { + format!("[patch] entry `{}` should be a URL or registry name", url) + })?, }; patch.insert( url, diff --git a/tests/testsuite/alt_registry.rs b/tests/testsuite/alt_registry.rs index 83cdcab404c..4c734234ebc 100644 --- a/tests/testsuite/alt_registry.rs +++ b/tests/testsuite/alt_registry.rs @@ -514,3 +514,47 @@ fn passwords_in_url_forbidden() { .with_stderr_contains("error: Registry URLs may not contain passwords") .run(); } + +#[test] +fn patch_alt_reg() { + Package::new("bar", "0.1.0").publish(); + let p = project() + .file( + "Cargo.toml", + r#" + cargo-features = ["alternative-registries"] + + [package] + name = "foo" + version = "0.0.1" + + [dependencies] + bar = { version = "0.1.0", registry = "alternative" } + + [patch.alternative] + bar = { path = "bar" } + "#, + ) + .file( + "src/lib.rs", + " + extern crate bar; + pub fn f() { bar::bar(); } + ", + ) + .file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0")) + .file("bar/src/lib.rs", "pub fn bar() {}") + .build(); + + p.cargo("build") + .masquerade_as_nightly_cargo() + .with_stderr( + "\ +[UPDATING] `[ROOT][..]` index +[COMPILING] bar v0.1.0 ([CWD]/bar) +[COMPILING] foo v0.0.1 ([CWD]) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +", + ) + .run(); +} diff --git a/tests/testsuite/patch.rs b/tests/testsuite/patch.rs index dc101b85117..4d4498b1140 100644 --- a/tests/testsuite/patch.rs +++ b/tests/testsuite/patch.rs @@ -734,6 +734,9 @@ fn non_crates_io() { "\ error: failed to parse manifest at `[..]` +Caused by: + [patch] entry `some-other-source` should be a URL or registry name + Caused by: invalid url `some-other-source`: relative URL without a base ",