|
| 1 | +use crate::command_prelude::*; |
| 2 | +use cargo::ops; |
| 3 | +use std::path::PathBuf; |
| 4 | + |
| 5 | +pub fn cli() -> App { |
| 6 | + subcommand("vendor") |
| 7 | + .about("Vendor all dependencies for a project locally") |
| 8 | + .arg(opt("quiet", "No output printed to stdout").short("q")) |
| 9 | + .arg_manifest_path() |
| 10 | + .arg(Arg::with_name("path").help("Where to vendor crates (`vendor` by default)")) |
| 11 | + .arg( |
| 12 | + Arg::with_name("no-delete") |
| 13 | + .long("no-delete") |
| 14 | + .help("Don't delete older crates in the vendor directory"), |
| 15 | + ) |
| 16 | + .arg( |
| 17 | + Arg::with_name("tomls") |
| 18 | + .short("s") |
| 19 | + .long("sync") |
| 20 | + .help("Additional `Cargo.toml` to sync and vendor") |
| 21 | + .value_name("TOML") |
| 22 | + .multiple(true), |
| 23 | + ) |
| 24 | + .arg( |
| 25 | + Arg::with_name("respect-source-config") |
| 26 | + .long("respect-source-config") |
| 27 | + .help("Respect `[source]` config in `.cargo/config`") |
| 28 | + .multiple(true), |
| 29 | + ) |
| 30 | + .arg( |
| 31 | + Arg::with_name("no-merge-sources") |
| 32 | + .long("no-merge-sources") |
| 33 | + .hidden(true), |
| 34 | + ) |
| 35 | + .arg( |
| 36 | + Arg::with_name("relative-path") |
| 37 | + .long("relative-path") |
| 38 | + .hidden(true), |
| 39 | + ) |
| 40 | + .arg( |
| 41 | + Arg::with_name("only-git-deps") |
| 42 | + .long("only-git-deps") |
| 43 | + .hidden(true), |
| 44 | + ) |
| 45 | + .arg( |
| 46 | + Arg::with_name("explicit-version") |
| 47 | + .short("-x") |
| 48 | + .long("explicit-version") |
| 49 | + .hidden(true), |
| 50 | + ) |
| 51 | + .arg( |
| 52 | + Arg::with_name("disallow-duplicates") |
| 53 | + .long("disallow-duplicates") |
| 54 | + .hidden(true), |
| 55 | + ) |
| 56 | + .after_help( |
| 57 | + "\ |
| 58 | +This cargo subcommand will vendor all crates.io and git dependencies for a |
| 59 | +project into the specified directory at `<path>`. After this command completes |
| 60 | +the vendor directory specified by `<path>` will contain all remote sources from |
| 61 | +dependencies specified. Additional manifests beyond the default one can be |
| 62 | +specified with the `-s` option. |
| 63 | +
|
| 64 | +The `cargo vendor` command will also print out the configuration necessary |
| 65 | +to use the vendored sources, which you will need to add to `.cargo/config`. |
| 66 | +", |
| 67 | + ) |
| 68 | +} |
| 69 | + |
| 70 | +pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { |
| 71 | + // We're doing the vendoring operation outselves, so we don't actually want |
| 72 | + // to respect any of the `source` configuration in Cargo itself. That's |
| 73 | + // intended for other consumers of Cargo, but we want to go straight to the |
| 74 | + // source, e.g. crates.io, to fetch crates. |
| 75 | + if !args.is_present("respect-source-config") { |
| 76 | + config.values_mut()?.remove("source"); |
| 77 | + } |
| 78 | + |
| 79 | + // When we moved `cargo vendor` into Cargo itself we didn't stabilize a few |
| 80 | + // flags, so try to provide a helpful error message in that case to enusre |
| 81 | + // that users currently using the flag aren't tripped up. |
| 82 | + let crates_io_cargo_vendor_flag = if args.is_present("no-merge-sources") { |
| 83 | + Some("--no-merge-sources") |
| 84 | + } else if args.is_present("relative-path") { |
| 85 | + Some("--relative-path") |
| 86 | + } else if args.is_present("only-git-deps") { |
| 87 | + Some("--only-git-deps") |
| 88 | + } else if args.is_present("explicit-version") { |
| 89 | + Some("--explicit-version") |
| 90 | + } else if args.is_present("disallow-duplicates") { |
| 91 | + Some("--disallow-duplicates") |
| 92 | + } else { |
| 93 | + None |
| 94 | + }; |
| 95 | + if let Some(flag) = crates_io_cargo_vendor_flag { |
| 96 | + return Err(failure::format_err!("\ |
| 97 | +the crates.io `cargo vendor` command has now been merged into Cargo itself |
| 98 | +and does not support the flag `{}` currently; to continue using the flag you |
| 99 | +can execute `cargo-vendor vendor ...`, and if you would like to see this flag |
| 100 | +supported in Cargo itself please feel free to file an issue at |
| 101 | +https://github.com/rust-lang/cargo/issues/new |
| 102 | +", flag).into()); |
| 103 | + } |
| 104 | + |
| 105 | + let ws = args.workspace(config)?; |
| 106 | + let path = args |
| 107 | + .value_of_os("path") |
| 108 | + .map(|val| PathBuf::from(val.to_os_string())) |
| 109 | + .unwrap_or(PathBuf::from("vendor")); |
| 110 | + ops::vendor( |
| 111 | + &ws, |
| 112 | + &ops::VendorOptions { |
| 113 | + no_delete: args.is_present("no-delete"), |
| 114 | + destination: &path, |
| 115 | + extra: args |
| 116 | + .values_of_os("tomls") |
| 117 | + .unwrap_or_default() |
| 118 | + .map(|s| PathBuf::from(s.to_os_string())) |
| 119 | + .collect(), |
| 120 | + }, |
| 121 | + )?; |
| 122 | + Ok(()) |
| 123 | +} |
0 commit comments