Support alt-registry names in [patch] table.

This commit is contained in:
Eric Huss 2018-12-17 20:35:50 -08:00
parent bd5b21e997
commit 7eaa1cf70a
3 changed files with 54 additions and 1 deletions

View File

@ -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,

View File

@ -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();
}

View File

@ -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
",