diff --git a/src/bin/cargo/commands/vendor.rs b/src/bin/cargo/commands/vendor.rs index 7b07aa0da6f..315c269e6c6 100644 --- a/src/bin/cargo/commands/vendor.rs +++ b/src/bin/cargo/commands/vendor.rs @@ -27,6 +27,11 @@ pub fn cli() -> App { .help("Respect `[source]` config in `.cargo/config`") .multiple(true), ) + .arg( + Arg::with_name("versioned-dirs") + .long("versioned-dirs") + .help("Always include version in subdir name"), + ) .arg( Arg::with_name("no-merge-sources") .long("no-merge-sources") @@ -42,12 +47,6 @@ pub fn cli() -> App { .long("only-git-deps") .hidden(true), ) - .arg( - Arg::with_name("explicit-version") - .short("-x") - .long("explicit-version") - .hidden(true), - ) .arg( Arg::with_name("disallow-duplicates") .long("disallow-duplicates") @@ -85,8 +84,6 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { Some("--relative-path") } else if args.is_present("only-git-deps") { Some("--only-git-deps") - } else if args.is_present("explicit-version") { - Some("--explicit-version") } else if args.is_present("disallow-duplicates") { Some("--disallow-duplicates") } else { @@ -116,6 +113,7 @@ https://github.com/rust-lang/cargo/issues/new &ops::VendorOptions { no_delete: args.is_present("no-delete"), destination: &path, + versioned_dirs: args.is_present("versioned-dirs"), extra: args .values_of_os("tomls") .unwrap_or_default() diff --git a/src/cargo/ops/vendor.rs b/src/cargo/ops/vendor.rs index b452ba282ad..5397d162d66 100644 --- a/src/cargo/ops/vendor.rs +++ b/src/cargo/ops/vendor.rs @@ -14,6 +14,7 @@ use std::path::{Path, PathBuf}; pub struct VendorOptions<'a> { pub no_delete: bool, + pub versioned_dirs: bool, pub destination: &'a Path, pub extra: Vec, } @@ -186,7 +187,7 @@ fn sync( .parent() .expect("manifest_path should point to a file"); let max_version = *versions[&id.name()].iter().rev().next().unwrap().0; - let dir_has_version_suffix = id.version() != max_version; + let dir_has_version_suffix = opts.versioned_dirs || id.version() != max_version; let dst_name = if dir_has_version_suffix { // Eg vendor/futures-0.1.13 format!("{}-{}", id.name(), id.version()) diff --git a/src/doc/man/cargo-vendor.adoc b/src/doc/man/cargo-vendor.adoc index d5606a8529b..068d23391f8 100644 --- a/src/doc/man/cargo-vendor.adoc +++ b/src/doc/man/cargo-vendor.adoc @@ -38,6 +38,13 @@ to use the vendored sources, which you will need to add to `.cargo/config`. Instead of ignoring `[source]` configuration by default in `.cargo/config` read it and use it when downloading crates from crates.io, for example +*--versioned-dirs*:: + Normally versions are only added to disambiguate multiple versions of the + same package. This option causes all directories in the "vendor" directory + to be versioned, which makes it easier to track the history of vendored + packages over time, and can help with the performance of re-vendoring when + only a subset of the packages have changed. + === Manifest Options include::options-manifest-path.adoc[] diff --git a/src/doc/man/generated/cargo-vendor.html b/src/doc/man/generated/cargo-vendor.html index 0834a0ccce8..134b86a77bd 100644 --- a/src/doc/man/generated/cargo-vendor.html +++ b/src/doc/man/generated/cargo-vendor.html @@ -49,6 +49,14 @@

Owner Options

Instead of ignoring [source] configuration by default in .cargo/config read it and use it when downloading crates from crates.io, for example

+
--versioned-dirs
+
+

Normally versions are only added to disambiguate multiple versions of the +same package. This option causes all directories in the "vendor" directory +to be versioned, which makes it easier to track the history of vendored +packages over time, and can help with the performance of re-vendoring when +only a subset of the packages have changed.

+
diff --git a/src/etc/man/cargo-vendor.1 b/src/etc/man/cargo-vendor.1 index b136da4d890..de260c8d2b2 100644 --- a/src/etc/man/cargo-vendor.1 +++ b/src/etc/man/cargo-vendor.1 @@ -2,12 +2,12 @@ .\" Title: cargo-vendor .\" Author: [see the "AUTHOR(S)" section] .\" Generator: Asciidoctor 2.0.10 -.\" Date: 2019-09-08 +.\" Date: 2019-12-09 .\" Manual: \ \& .\" Source: \ \& .\" Language: English .\" -.TH "CARGO\-VENDOR" "1" "2019-09-08" "\ \&" "\ \&" +.TH "CARGO\-VENDOR" "1" "2019-12-09" "\ \&" "\ \&" .ie \n(.g .ds Aq \(aq .el .ds Aq ' .ss \n[.ss] 0 @@ -62,6 +62,15 @@ existing contents of the vendor directory Instead of ignoring \fB[source]\fP configuration by default in \fB.cargo/config\fP read it and use it when downloading crates from crates.io, for example .RE +.sp +\fB\-\-versioned\-dirs\fP +.RS 4 +Normally versions are only added to disambiguate multiple versions of the +same package. This option causes all directories in the "vendor" directory +to be versioned, which makes it easier to track the history of vendored +packages over time, and can help with the performance of re\-vendoring when +only a subset of the packages have changed. +.RE .SS "Manifest Options" .sp \fB\-\-manifest\-path\fP \fIPATH\fP diff --git a/tests/testsuite/vendor.rs b/tests/testsuite/vendor.rs index 4e448602f04..3f3fb1ff0d1 100644 --- a/tests/testsuite/vendor.rs +++ b/tests/testsuite/vendor.rs @@ -88,6 +88,51 @@ fn two_versions() { p.cargo("build").run(); } +#[cargo_test] +fn two_explicit_versions() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + + [dependencies] + bitflags = "0.8.0" + bar = { path = "bar" } + "#, + ) + .file("src/lib.rs", "") + .file( + "bar/Cargo.toml", + r#" + [package] + name = "bar" + version = "0.1.0" + + [dependencies] + bitflags = "0.7.0" + "#, + ) + .file("bar/src/lib.rs", "") + .build(); + + Package::new("bitflags", "0.7.0").publish(); + Package::new("bitflags", "0.8.0").publish(); + + p.cargo("vendor --respect-source-config --versioned-dirs") + .run(); + + let lock = p.read_file("vendor/bitflags-0.8.0/Cargo.toml"); + assert!(lock.contains("version = \"0.8.0\"")); + let lock = p.read_file("vendor/bitflags-0.7.0/Cargo.toml"); + assert!(lock.contains("version = \"0.7.0\"")); + + add_vendor_config(&p); + p.cargo("build").run(); +} + #[cargo_test] fn help() { let p = project().build();