-
Notifications
You must be signed in to change notification settings - Fork 1k
fix(cli/rustup_mode)!: skip auto-installation in some rustup commands
#4840
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
base: main
Are you sure you want to change the base?
Changes from all commits
d53fccf
bc01f23
3aea072
17ed4db
42b4bea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -631,15 +631,41 @@ pub async fn main( | |
|
|
||
| update_console_filter(process, &console_filter, matches.quiet, matches.verbose); | ||
|
|
||
| let cfg = &mut Cfg::from_env(current_dir, matches.quiet, process)?; | ||
| cfg.toolchain_override = matches.plus_toolchain; | ||
|
|
||
| let Some(subcmd) = matches.subcmd else { | ||
| let help = Rustup::command().render_long_help(); | ||
| writeln!(process.stderr().lock(), "{}", help.ansi())?; | ||
| return Ok(ExitCode::FAILURE); | ||
| }; | ||
|
|
||
| let allow_auto_install = match subcmd { | ||
| // These subcommands execute or rely on the active toolchain, so auto-installing it when | ||
| // missing may be reasonable depending on the user's decision. | ||
| #[cfg(not(windows))] | ||
| RustupSubcmd::Man { .. } => true, | ||
| RustupSubcmd::Doc { .. } | RustupSubcmd::Run { .. } => true, | ||
|
|
||
| // These subcommands don't require the active toolchain, so auto-installing it should be | ||
| // disabled to avoid surprises. | ||
| RustupSubcmd::Check { .. } | ||
| | RustupSubcmd::Completions { .. } | ||
| | RustupSubcmd::Component { .. } | ||
| | RustupSubcmd::Default { .. } | ||
| | RustupSubcmd::DumpTestament | ||
| | RustupSubcmd::Install { .. } | ||
| | RustupSubcmd::Override { .. } | ||
| | RustupSubcmd::Self_ { .. } | ||
| | RustupSubcmd::Set { .. } | ||
| | RustupSubcmd::Show { .. } | ||
| | RustupSubcmd::Target { .. } | ||
| | RustupSubcmd::Toolchain { .. } | ||
| | RustupSubcmd::Uninstall { .. } | ||
| | RustupSubcmd::Update { .. } | ||
| | RustupSubcmd::Which { .. } => false, | ||
| }; | ||
|
|
||
|
Comment on lines
+640
to
+665
|
||
| let cfg = &mut Cfg::from_env(current_dir, matches.quiet, allow_auto_install, process)?; | ||
| cfg.toolchain_override = matches.plus_toolchain; | ||
|
|
||
| match subcmd { | ||
| RustupSubcmd::DumpTestament => common::dump_testament(process), | ||
| RustupSubcmd::Install { opts } => update(cfg, opts, true).await, | ||
|
|
@@ -1146,21 +1172,6 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result<ExitCode> { | |
| .map(|atar| (&atar.0, &atar.1)) | ||
| .unzip(); | ||
|
|
||
| let active_toolchain_targets = match active_toolchain_name { | ||
| Some(ToolchainName::Official(desc)) => DistributableToolchain::new(cfg, desc.clone())? | ||
| .components()? | ||
| .into_iter() | ||
| .filter_map(|c| { | ||
| (c.installed && c.component.short_name() == "rust-std") | ||
| .then(|| c.component.target.expect("rust-std should have a target")) | ||
| }) | ||
| .collect(), | ||
| Some(ToolchainName::Custom(name)) => { | ||
| Toolchain::new(cfg, LocalToolchainName::Named(name.into()))?.installed_targets()? | ||
| } | ||
| None => Vec::new(), | ||
| }; | ||
|
|
||
| // show installed toolchains | ||
| { | ||
| let mut t = cfg.process.stdout(); | ||
|
|
@@ -1207,23 +1218,51 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result<ExitCode> { | |
|
|
||
| match active_toolchain_and_source { | ||
| Some((active_toolchain_name, active_source)) => { | ||
| let active_toolchain = Toolchain::with_source( | ||
| cfg, | ||
| active_toolchain_name.clone().into(), | ||
| &active_source, | ||
| )?; | ||
| writeln!(t.lock(), "name: {}", active_toolchain.name())?; | ||
| writeln!(t.lock(), "name: {active_toolchain_name}")?; | ||
| writeln!(t.lock(), "active because: {}", active_source.to_reason())?; | ||
| if verbose { | ||
| writeln!(t.lock(), "compiler: {}", active_toolchain.rustc_version())?; | ||
| writeln!(t.lock(), "path: {}", active_toolchain.path().display())?; | ||
| } | ||
|
|
||
| // show installed targets for the active toolchain | ||
| writeln!(t.lock(), "installed targets:")?; | ||
|
|
||
|
Comment on lines
+1195
to
+1197
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change looks more or less unrelated, but feels related, maybe split it into a separate commit? |
||
| for target in active_toolchain_targets { | ||
| writeln!(t.lock(), " {target}")?; | ||
| match Toolchain::new(cfg, active_toolchain_name.clone().into()) { | ||
| Ok(active_toolchain) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, get this case out of the |
||
| if verbose { | ||
| writeln!(t.lock(), "compiler: {}", active_toolchain.rustc_version())?; | ||
| writeln!(t.lock(), "path: {}", active_toolchain.path().display())?; | ||
| } | ||
|
|
||
| // show installed targets for the active toolchain | ||
| writeln!(t.lock(), "installed targets:")?; | ||
|
|
||
| let active_toolchain_targets = match active_toolchain_name { | ||
| ToolchainName::Official(desc) => { | ||
| DistributableToolchain::new(cfg, desc.clone())? | ||
| .components()? | ||
| .into_iter() | ||
| .filter_map(|c| { | ||
| (c.installed && c.component.short_name() == "rust-std") | ||
| .then(|| { | ||
| c.component | ||
| .target | ||
| .expect("rust-std should have a target") | ||
| }) | ||
| }) | ||
| .collect() | ||
| } | ||
| ToolchainName::Custom(name) => { | ||
| Toolchain::new(cfg, LocalToolchainName::Named(name.into()))? | ||
| .installed_targets()? | ||
| } | ||
| }; | ||
|
|
||
| for target in active_toolchain_targets { | ||
| writeln!(t.lock(), " {target}")?; | ||
| } | ||
| } | ||
| Err( | ||
| RustupError::ToolchainNotInstalled { .. } | ||
| | RustupError::PathToolchainNotInstalled(..), | ||
| ) => { | ||
| info!("the active toolchain `{active_toolchain_name}` is not installed"); | ||
| } | ||
| Err(e) => return Err(e.into()), | ||
| } | ||
| } | ||
| None => { | ||
|
|
@@ -1973,8 +2012,8 @@ fn output_completion_script( | |
| } | ||
|
|
||
| async fn display_version(current_dir: PathBuf, process: &Process) -> Result<()> { | ||
| info!("This is the version for the rustup toolchain manager, not the rustc compiler."); | ||
| let mut cfg = Cfg::from_env(current_dir, true, process)?; | ||
| info!("this is the version for the rustup toolchain manager, not the rustc compiler"); | ||
| let mut cfg = Cfg::from_env(current_dir, true, false, process)?; | ||
| cfg.toolchain_override = cfg | ||
| .process | ||
| .args() | ||
|
|
@@ -1987,6 +2026,12 @@ async fn display_version(current_dir: PathBuf, process: &Process) -> Result<()> | |
| "the currently active `rustc` version is `{}`", | ||
| tc.rustc_version() | ||
| ), | ||
| Err(RustupError::ToolchainNotInstalled { | ||
| name, | ||
| is_active: true, | ||
| }) => { | ||
| info!("the active toolchain `{name}` is not installed"); | ||
| } | ||
| Err(err) => error!("failed to display the current `rustc` version: {err}"), | ||
| }, | ||
| Ok(None) => info!("no `rustc` is currently active"), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: suggest moving this into a method attached to
RustupSubCmd?