-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #6869 - alexcrichton:vendor, r=ehuss
Import the cargo-vendor subcommand into Cargo This commit imports the external [alexcrichton/cargo-vendor repository][repo] into Cargo itself. This means it will no longer be necessary to install the `cargo-vendor` subcommand in order to vendor dependencies. Additionally it'll always support the latest feature set of Cargo as it'll be built into Cargo! All tests were imported as part of this commit, but not all features were imported. Some flags have been left out that were added later in the lifetime of `cargo vendor` which seem like they're more questionable to stabilize. I'm hoping that they can have separate PRs adding their implementation here, and we can make a decision of their stabilization at a later date. The current man page for `cargo vendor -h` will look like: cargo-vendor Vendor all dependencies for a project locally USAGE: cargo vendor [OPTIONS] [--] [path] OPTIONS: -q, --quiet No output printed to stdout --manifest-path <PATH> Path to Cargo.toml --no-delete Don't delete older crates in the vendor directory -s, --sync <TOML>... Additional `Cargo.toml` to sync and vendor --respect-source-config Respect `[source]` config in `.cargo/config` -v, --verbose Use verbose output (-vv very verbose/build.rs output) --color <WHEN> Coloring: auto, always, never --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date -Z <FLAG>... Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details -h, --help Prints help information ARGS: <path> Where to vendor crates (`vendor` by default) This cargo subcommand will vendor all crates.io and git dependencies for a project into the specified directory at `<path>`. After this command completes the vendor directory specified by `<path>` will contain all remote sources from dependencies specified. Additionally manifest beyond the default one can be specified with the `-s` option. The `cargo vendor` command will also print out the configuration necessary to use the vendored sources, which when needed is then encoded into `.cargo/config`. Since this change is not importing 100% of the functionality of the existing `cargo vendor` this change does run a risk of being a breaking change for any folks using such functionality. Executing `cargo vendor` will favor the built-in command rather than an external subcommand, causing unimplemented features to become errors about flag usage. [repo]: https://github.com/alexcrichton/cargo-vendor
- Loading branch information
Showing
21 changed files
with
1,553 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
use crate::command_prelude::*; | ||
use cargo::ops; | ||
use std::path::PathBuf; | ||
|
||
pub fn cli() -> App { | ||
subcommand("vendor") | ||
.about("Vendor all dependencies for a project locally") | ||
.arg(opt("quiet", "No output printed to stdout").short("q")) | ||
.arg_manifest_path() | ||
.arg(Arg::with_name("path").help("Where to vendor crates (`vendor` by default)")) | ||
.arg( | ||
Arg::with_name("no-delete") | ||
.long("no-delete") | ||
.help("Don't delete older crates in the vendor directory"), | ||
) | ||
.arg( | ||
Arg::with_name("tomls") | ||
.short("s") | ||
.long("sync") | ||
.help("Additional `Cargo.toml` to sync and vendor") | ||
.value_name("TOML") | ||
.multiple(true), | ||
) | ||
.arg( | ||
Arg::with_name("respect-source-config") | ||
.long("respect-source-config") | ||
.help("Respect `[source]` config in `.cargo/config`") | ||
.multiple(true), | ||
) | ||
.arg( | ||
Arg::with_name("no-merge-sources") | ||
.long("no-merge-sources") | ||
.hidden(true), | ||
) | ||
.arg( | ||
Arg::with_name("relative-path") | ||
.long("relative-path") | ||
.hidden(true), | ||
) | ||
.arg( | ||
Arg::with_name("only-git-deps") | ||
.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") | ||
.hidden(true), | ||
) | ||
.after_help( | ||
"\ | ||
This cargo subcommand will vendor all crates.io and git dependencies for a | ||
project into the specified directory at `<path>`. After this command completes | ||
the vendor directory specified by `<path>` will contain all remote sources from | ||
dependencies specified. Additional manifests beyond the default one can be | ||
specified with the `-s` option. | ||
The `cargo vendor` command will also print out the configuration necessary | ||
to use the vendored sources, which you will need to add to `.cargo/config`. | ||
", | ||
) | ||
} | ||
|
||
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { | ||
// We're doing the vendoring operation outselves, so we don't actually want | ||
// to respect any of the `source` configuration in Cargo itself. That's | ||
// intended for other consumers of Cargo, but we want to go straight to the | ||
// source, e.g. crates.io, to fetch crates. | ||
if !args.is_present("respect-source-config") { | ||
config.values_mut()?.remove("source"); | ||
} | ||
|
||
// When we moved `cargo vendor` into Cargo itself we didn't stabilize a few | ||
// flags, so try to provide a helpful error message in that case to enusre | ||
// that users currently using the flag aren't tripped up. | ||
let crates_io_cargo_vendor_flag = if args.is_present("no-merge-sources") { | ||
Some("--no-merge-sources") | ||
} else if args.is_present("relative-path") { | ||
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 { | ||
None | ||
}; | ||
if let Some(flag) = crates_io_cargo_vendor_flag { | ||
return Err(failure::format_err!("\ | ||
the crates.io `cargo vendor` command has now been merged into Cargo itself | ||
and does not support the flag `{}` currently; to continue using the flag you | ||
can execute `cargo-vendor vendor ...`, and if you would like to see this flag | ||
supported in Cargo itself please feel free to file an issue at | ||
https://github.com/rust-lang/cargo/issues/new | ||
", flag).into()); | ||
} | ||
|
||
let ws = args.workspace(config)?; | ||
let path = args | ||
.value_of_os("path") | ||
.map(|val| PathBuf::from(val.to_os_string())) | ||
.unwrap_or(PathBuf::from("vendor")); | ||
ops::vendor( | ||
&ws, | ||
&ops::VendorOptions { | ||
no_delete: args.is_present("no-delete"), | ||
destination: &path, | ||
extra: args | ||
.values_of_os("tomls") | ||
.unwrap_or_default() | ||
.map(|s| PathBuf::from(s.to_os_string())) | ||
.collect(), | ||
}, | ||
)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.