Skip to content

Commit

Permalink
Auto merge of #6798 - ehuss:install-upgrade, r=alexcrichton
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
bors committed Apr 5, 2019
2 parents b08e4cb + 5a9ff8a commit f5b60ac
Show file tree
Hide file tree
Showing 12 changed files with 1,782 additions and 413 deletions.
1 change: 1 addition & 0 deletions src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Available unstable (nightly-only) flags:
-Z offline -- Offline mode that does not perform network requests
-Z unstable-options -- Allow the usage of unstable options such as --registry
-Z config-profile -- Read profiles from .cargo/config files
-Z install-upgrade -- `cargo install` will upgrade instead of failing
Run with 'cargo -Z [FLAG] [SUBCOMMAND]'"
);
Expand Down
11 changes: 11 additions & 0 deletions src/bin/cargo/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ pub fn cli() -> App {
))
.arg_jobs()
.arg(opt("force", "Force overwriting existing crates or binaries").short("f"))
.arg(opt(
"no-track",
"Do not save tracking information (unstable)",
))
.arg_features()
.arg(opt("debug", "Build in debug mode instead of release mode"))
.arg_targets_bins_examples(
Expand Down Expand Up @@ -147,6 +151,12 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
let version = args.value_of("version");
let root = args.value_of("root");

if args.is_present("no-track") && !config.cli_unstable().install_upgrade {
Err(failure::format_err!(
"`--no-track` flag is unstable, pass `-Z install-upgrade` to enable it"
))?;
};

if args.is_present("list") {
ops::install_list(root, config)?;
} else {
Expand All @@ -158,6 +168,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
version,
&compile_opts,
args.is_present("force"),
args.is_present("no-track"),
)?;
}
Ok(())
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ pub struct CliUnstable {
pub config_profile: bool,
pub dual_proc_macros: bool,
pub mtime_on_use: bool,
pub install_upgrade: bool,
}

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

Expand Down
Loading

0 comments on commit f5b60ac

Please sign in to comment.