Skip to content

Commit

Permalink
Auto merge of #9831 - ehuss:fix-debug, r=Eh2406
Browse files Browse the repository at this point in the history
Add some debug logging for `cargo fix`

This adds some debug logging to the `cargo fix` command to give better insight into what it is actually doing. I've needed to try to debug some things recently where this would have been useful, since cargo runs rustc many times with different arguments.  I think this will be useful if other people report problems, we can ask them to run with `CARGO_LOG=cargo::ops::fix=trace` to gather more information.
  • Loading branch information
bors committed Aug 23, 2021
2 parents 835d557 + 9fe4a4e commit d28ca0b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/cargo/ops/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ pub fn fix_maybe_exec_rustc(config: &Config) -> CargoResult<bool> {
let mut cmd = rustc.build_command();
args.apply(&mut cmd, config);
cmd.arg("--error-format=json");
debug!("calling rustc for final verification: {:?}", cmd);
let output = cmd.output().context("failed to spawn rustc")?;

if output.status.success() {
Expand All @@ -389,6 +390,7 @@ pub fn fix_maybe_exec_rustc(config: &Config) -> CargoResult<bool> {
if !output.status.success() {
if env::var_os(BROKEN_CODE_ENV).is_none() {
for (path, file) in fixes.files.iter() {
debug!("reverting {:?} due to errors", path);
paths::write(path, &file.original_code)?;
}
}
Expand All @@ -407,6 +409,7 @@ pub fn fix_maybe_exec_rustc(config: &Config) -> CargoResult<bool> {
// things like colored output to work correctly.
cmd.arg(arg);
}
debug!("calling rustc to display remaining diagnostics: {:?}", cmd);
exit_with(cmd.status().context("failed to spawn rustc")?);
}

Expand Down Expand Up @@ -545,6 +548,10 @@ fn rustfix_and_fix(
let mut cmd = rustc.build_command();
cmd.arg("--error-format=json");
args.apply(&mut cmd, config);
debug!(
"calling rustc to collect suggestions and validate previous fixes: {:?}",
cmd
);
let output = cmd.output().with_context(|| {
format!(
"failed to execute `{}`",
Expand Down Expand Up @@ -609,6 +616,7 @@ fn rustfix_and_fix(
continue;
}

trace!("adding suggestion for {:?}: {:?}", file_name, suggestion);
file_map
.entry(file_name)
.or_insert_with(Vec::new)
Expand Down

0 comments on commit d28ca0b

Please sign in to comment.