Skip to content

Commit

Permalink
Auto merge of #7718 - ehuss:fix-vendor-alt-reg, r=alexcrichton
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Dec 19, 2019
2 parents 7292437 + 723748f commit 4647b1d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/cargo/ops/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ fn sync(
registry: None,
replace_with: merged_source_name.to_string(),
}
} else if source_id.is_remote_registry() {
let registry = source_id.url().to_string();
VendorSource::Registry {
registry: Some(registry),
replace_with: merged_source_name.to_string(),
}
} else if source_id.is_git() {
let mut branch = None;
let mut tag = None;
Expand Down
47 changes: 47 additions & 0 deletions tests/testsuite/vendor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
//! Tests for the `cargo vendor` command.
//!
//! Note that every test here uses `--respect-source-config` so that the
//! "fake" crates.io is used. Otherwise `vendor` would download the crates.io
//! index from the network.

use cargo_test_support::git;
use cargo_test_support::registry::Package;
Expand Down Expand Up @@ -584,3 +588,46 @@ fn ignore_hidden() {
.iter()
.all(|status| status.status() == git2::Status::CURRENT));
}

#[cargo_test]
fn config_instructions_works() {
// Check that the config instructions work for all dependency kinds.
Package::new("dep", "0.1.0").publish();
Package::new("altdep", "0.1.0").alternative(true).publish();
let git_project = git::new("gitdep", |project| {
project
.file("Cargo.toml", &basic_lib_manifest("gitdep"))
.file("src/lib.rs", "")
});
let p = project()
.file(
"Cargo.toml",
&format!(
r#"
[package]
name = "foo"
version = "0.1.0"
[dependencies]
dep = "0.1"
altdep = {{version="0.1", registry="alternative"}}
gitdep = {{git='{}'}}
"#,
git_project.url()
),
)
.file("src/lib.rs", "")
.build();
let output = p
.cargo("vendor --respect-source-config")
.exec_with_output()
.unwrap();
let output = String::from_utf8(output.stdout).unwrap();
p.change_file(".cargo/config", &output);

p.cargo("check -v")
.with_stderr_contains("[..]foo/vendor/dep/src/lib.rs[..]")
.with_stderr_contains("[..]foo/vendor/altdep/src/lib.rs[..]")
.with_stderr_contains("[..]foo/vendor/gitdep/src/lib.rs[..]")
.run();
}

0 comments on commit 4647b1d

Please sign in to comment.