Skip to content

Commit 4647b1d

Browse files
committed
Auto merge of #7718 - ehuss:fix-vendor-alt-reg, r=alexcrichton
vendor: support alt registries Adds support for alt registries to `cargo vendor`. It mostly worked before, but panicked when trying to display the `.cargo/config` instructions. This isn't entirely elegant, as the source replacement looks like this: ```toml [source.crates-io] replace-with = "vendored-sources" [source."file:///Users/eric/Proj/rust/cargo/target/cit/t0/alternative-registry"] registry = "file:///Users/eric/Proj/rust/cargo/target/cit/t0/alternative-registry" replace-with = "vendored-sources" [source."file:///Users/eric/Proj/rust/cargo/target/cit/t0/gitdep"] git = "file:///Users/eric/Proj/rust/cargo/target/cit/t0/gitdep" branch = "master" replace-with = "vendored-sources" [source.vendored-sources] directory = "vendor" ``` The duplication of the URLs is a little unfortunate. It could use the name of the registry, but that is not readily available and is tricky to obtain. I feel like that is a challenge for another day. Closes #7674.
2 parents 7292437 + 723748f commit 4647b1d

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src/cargo/ops/vendor.rs

+6
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@ fn sync(
258258
registry: None,
259259
replace_with: merged_source_name.to_string(),
260260
}
261+
} else if source_id.is_remote_registry() {
262+
let registry = source_id.url().to_string();
263+
VendorSource::Registry {
264+
registry: Some(registry),
265+
replace_with: merged_source_name.to_string(),
266+
}
261267
} else if source_id.is_git() {
262268
let mut branch = None;
263269
let mut tag = None;

tests/testsuite/vendor.rs

+47
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
//! Tests for the `cargo vendor` command.
2+
//!
3+
//! Note that every test here uses `--respect-source-config` so that the
4+
//! "fake" crates.io is used. Otherwise `vendor` would download the crates.io
5+
//! index from the network.
26
37
use cargo_test_support::git;
48
use cargo_test_support::registry::Package;
@@ -584,3 +588,46 @@ fn ignore_hidden() {
584588
.iter()
585589
.all(|status| status.status() == git2::Status::CURRENT));
586590
}
591+
592+
#[cargo_test]
593+
fn config_instructions_works() {
594+
// Check that the config instructions work for all dependency kinds.
595+
Package::new("dep", "0.1.0").publish();
596+
Package::new("altdep", "0.1.0").alternative(true).publish();
597+
let git_project = git::new("gitdep", |project| {
598+
project
599+
.file("Cargo.toml", &basic_lib_manifest("gitdep"))
600+
.file("src/lib.rs", "")
601+
});
602+
let p = project()
603+
.file(
604+
"Cargo.toml",
605+
&format!(
606+
r#"
607+
[package]
608+
name = "foo"
609+
version = "0.1.0"
610+
611+
[dependencies]
612+
dep = "0.1"
613+
altdep = {{version="0.1", registry="alternative"}}
614+
gitdep = {{git='{}'}}
615+
"#,
616+
git_project.url()
617+
),
618+
)
619+
.file("src/lib.rs", "")
620+
.build();
621+
let output = p
622+
.cargo("vendor --respect-source-config")
623+
.exec_with_output()
624+
.unwrap();
625+
let output = String::from_utf8(output.stdout).unwrap();
626+
p.change_file(".cargo/config", &output);
627+
628+
p.cargo("check -v")
629+
.with_stderr_contains("[..]foo/vendor/dep/src/lib.rs[..]")
630+
.with_stderr_contains("[..]foo/vendor/altdep/src/lib.rs[..]")
631+
.with_stderr_contains("[..]foo/vendor/gitdep/src/lib.rs[..]")
632+
.run();
633+
}

0 commit comments

Comments
 (0)