Skip to content

Commit f5b60ac

Browse files
committed
Auto merge of #6798 - ehuss:install-upgrade, r=alexcrichton
Add install-upgrade. This implements the feature described in #6667. Instead of failing when `cargo install` detects a package is already installed, it will upgrade if the versions don't match, or do nothing (exit 0) if it is considered "up-to-date". Closes #6667. Notes: - This feature rejects ambiguous `--version` input (such as `1.0`). This is not required, but seemed like a reasonable time to make the change. - There is a slight change to the output on stable which reports what was installed/replaced. - Added better support for `*` in `--version` (don't show warning).
2 parents b08e4cb + 5a9ff8a commit f5b60ac

File tree

12 files changed

+1782
-413
lines changed

12 files changed

+1782
-413
lines changed

Diff for: src/bin/cargo/cli.rs

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Available unstable (nightly-only) flags:
3535
-Z offline -- Offline mode that does not perform network requests
3636
-Z unstable-options -- Allow the usage of unstable options such as --registry
3737
-Z config-profile -- Read profiles from .cargo/config files
38+
-Z install-upgrade -- `cargo install` will upgrade instead of failing
3839
3940
Run with 'cargo -Z [FLAG] [SUBCOMMAND]'"
4041
);

Diff for: src/bin/cargo/commands/install.rs

+11
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ pub fn cli() -> App {
4646
))
4747
.arg_jobs()
4848
.arg(opt("force", "Force overwriting existing crates or binaries").short("f"))
49+
.arg(opt(
50+
"no-track",
51+
"Do not save tracking information (unstable)",
52+
))
4953
.arg_features()
5054
.arg(opt("debug", "Build in debug mode instead of release mode"))
5155
.arg_targets_bins_examples(
@@ -147,6 +151,12 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
147151
let version = args.value_of("version");
148152
let root = args.value_of("root");
149153

154+
if args.is_present("no-track") && !config.cli_unstable().install_upgrade {
155+
Err(failure::format_err!(
156+
"`--no-track` flag is unstable, pass `-Z install-upgrade` to enable it"
157+
))?;
158+
};
159+
150160
if args.is_present("list") {
151161
ops::install_list(root, config)?;
152162
} else {
@@ -158,6 +168,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
158168
version,
159169
&compile_opts,
160170
args.is_present("force"),
171+
args.is_present("no-track"),
161172
)?;
162173
}
163174
Ok(())

Diff for: src/cargo/core/features.rs

+2
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ pub struct CliUnstable {
328328
pub config_profile: bool,
329329
pub dual_proc_macros: bool,
330330
pub mtime_on_use: bool,
331+
pub install_upgrade: bool,
331332
}
332333

333334
impl CliUnstable {
@@ -372,6 +373,7 @@ impl CliUnstable {
372373
"config-profile" => self.config_profile = true,
373374
"dual-proc-macros" => self.dual_proc_macros = true,
374375
"mtime-on-use" => self.mtime_on_use = true,
376+
"install-upgrade" => self.install_upgrade = true,
375377
_ => failure::bail!("unknown `-Z` flag specified: {}", k),
376378
}
377379

0 commit comments

Comments
 (0)