Skip to content

Commit

Permalink
Revert "fix(context): Configure Shell before emitting messages"
Browse files Browse the repository at this point in the history
This reverts commit f525e1f.

This removes color control from warnings for unstable features.
For some reason this removed color support from `cargo -Zhelp` in the
tests but I can't reproduce it locally.

I had looked into finding the right balance to not have any downsides
but ran out my time box and having a working config is a higher
priority.

Fixes rust-lang#13991
  • Loading branch information
epage committed May 31, 2024
1 parent c0a7957 commit a9aff29
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 63 deletions.
50 changes: 25 additions & 25 deletions src/cargo/util/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,31 @@ 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())?;
}

// Ignore errors in the configuration files. We don't want basic
// commands like `cargo version` to error out due to config file
// problems.
Expand Down Expand Up @@ -1066,31 +1091,6 @@ impl GlobalContext {
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(())
Expand Down
69 changes: 33 additions & 36 deletions tests/testsuite/cargo/z_help/stdout.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/testsuite/config_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn basic() {
.config_arg("net.git-fetch-with-cli=true")
.build();
assert_eq!(gctx.get::<String>("foo").unwrap(), "bar");
assert_eq!(gctx.net_config().unwrap().git_fetch_with_cli, None);
assert_eq!(gctx.net_config().unwrap().git_fetch_with_cli, Some(true));
}

#[cargo_test]
Expand Down Expand Up @@ -52,7 +52,7 @@ fn cli_priority() {
assert_eq!(gctx.get::<i32>("build.jobs").unwrap(), 1);
assert_eq!(gctx.get::<String>("build.rustc").unwrap(), "cli");
assert_eq!(gctx.get::<bool>("term.verbose").unwrap(), true);
assert_eq!(gctx.net_config().unwrap().git_fetch_with_cli, Some(false));
assert_eq!(gctx.net_config().unwrap().git_fetch_with_cli, Some(true));

// Setting both term.verbose and term.quiet is invalid and is tested
// in the run test suite.
Expand Down

0 comments on commit a9aff29

Please sign in to comment.