From f525e1f383fc0d0a7adbdfb1bac6d6228ae79b33 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 22 Feb 2024 10:55:27 -0600 Subject: [PATCH] fix(context): Configure Shell before emitting messages --- src/cargo/util/config/mod.rs | 66 ++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/cargo/util/config/mod.rs b/src/cargo/util/config/mod.rs index cf9402c7bc4..30536b1adf9 100644 --- a/src/cargo/util/config/mod.rs +++ b/src/cargo/util/config/mod.rs @@ -1018,41 +1018,14 @@ impl GlobalContext { unstable_flags: &[String], cli_config: &[String], ) -> CargoResult<()> { - for warning in self - .unstable_flags - .parse(unstable_flags, self.nightly_features_allowed)? - { - self.shell().warn(warning)?; - } - if !unstable_flags.is_empty() { - // store a copy of the cli flags separately for `load_unstable_flags_from_config` - // (we might also need it again for `reload_rooted_at`) - self.unstable_flags_cli = Some(unstable_flags.to_vec()); - } - if !cli_config.is_empty() { - self.cli_config = Some(cli_config.iter().map(|s| s.to_string()).collect()); - self.merge_cli_args()?; - } - if self.unstable_flags.config_include { - // If the config was already loaded (like when fetching the - // `[alias]` table), it was loaded with includes disabled because - // the `unstable_flags` hadn't been set up, yet. Any values - // fetched before this step will not process includes, but that - // should be fine (`[alias]` is one of the only things loaded - // before configure). This can be removed when stabilized. - self.reload_rooted_at(self.cwd.clone())?; - } - let extra_verbose = verbose >= 2; - let verbose = verbose != 0; - // Ignore errors in the configuration files. We don't want basic // commands like `cargo version` to error out due to config file // problems. let term = self.get::("term").unwrap_or_default(); - let color = color.or_else(|| term.color.as_deref()); - // The command line takes precedence over configuration. + let extra_verbose = verbose >= 2; + let verbose = verbose != 0; let verbosity = match (verbose, quiet) { (true, true) => bail!("cannot set both --verbose and --quiet"), (true, false) => Verbosity::Verbose, @@ -1066,16 +1039,17 @@ impl GlobalContext { _ => Verbosity::Normal, }, }; - - let cli_target_dir = target_dir.as_ref().map(|dir| Filesystem::new(dir.clone())); - self.shell().set_verbosity(verbosity); + self.extra_verbose = extra_verbose; + + let color = color.or_else(|| term.color.as_deref()); self.shell().set_color_choice(color)?; if let Some(hyperlinks) = term.hyperlinks { self.shell().set_hyperlinks(hyperlinks)?; } + self.progress_config = term.progress.unwrap_or_default(); - self.extra_verbose = extra_verbose; + self.frozen = frozen; self.locked = locked; self.offline = offline @@ -1084,8 +1058,34 @@ impl GlobalContext { .ok() .and_then(|n| n.offline) .unwrap_or(false); + let cli_target_dir = target_dir.as_ref().map(|dir| Filesystem::new(dir.clone())); self.target_dir = cli_target_dir; + for warning in self + .unstable_flags + .parse(unstable_flags, self.nightly_features_allowed)? + { + self.shell().warn(warning)?; + } + if !unstable_flags.is_empty() { + // store a copy of the cli flags separately for `load_unstable_flags_from_config` + // (we might also need it again for `reload_rooted_at`) + self.unstable_flags_cli = Some(unstable_flags.to_vec()); + } + if !cli_config.is_empty() { + self.cli_config = Some(cli_config.iter().map(|s| s.to_string()).collect()); + self.merge_cli_args()?; + } + if self.unstable_flags.config_include { + // If the config was already loaded (like when fetching the + // `[alias]` table), it was loaded with includes disabled because + // the `unstable_flags` hadn't been set up, yet. Any values + // fetched before this step will not process includes, but that + // should be fine (`[alias]` is one of the only things loaded + // before configure). This can be removed when stabilized. + self.reload_rooted_at(self.cwd.clone())?; + } + self.load_unstable_flags_from_config()?; Ok(())