Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vendor: implement --versioned-dirs #7631

Merged
merged 5 commits into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/bin/cargo/commands/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
jsgf marked this conversation as resolved.
Show resolved Hide resolved
)
.arg(
Arg::with_name("no-merge-sources")
.long("no-merge-sources")
Expand All @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/ops/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,
}
Expand Down Expand Up @@ -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())
Expand Down
7 changes: 7 additions & 0 deletions src/doc/man/cargo-vendor.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
8 changes: 8 additions & 0 deletions src/doc/man/generated/cargo-vendor.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ <h3 id="cargo_vendor_owner_options">Owner Options</h3>
<p>Instead of ignoring <code>[source]</code> configuration by default in <code>.cargo/config</code>
read it and use it when downloading crates from crates.io, for example</p>
</dd>
<dt class="hdlist1"><strong>--versioned-dirs</strong></dt>
<dd>
<p>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.</p>
</dd>
</dl>
</div>
</div>
Expand Down
13 changes: 11 additions & 2 deletions src/etc/man/cargo-vendor.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
joshtriplett marked this conversation as resolved.
Show resolved Hide resolved
.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
Expand Down
45 changes: 45 additions & 0 deletions tests/testsuite/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down