Skip to content

Commit

Permalink
fmt_override is a better name since we are also adding files to white…
Browse files Browse the repository at this point in the history
…list
  • Loading branch information
chenyukang committed Aug 1, 2023
1 parent 79709e5 commit 58bda47
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/bootstrap/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
}
let rustfmt_config = t!(std::fs::read_to_string(&rustfmt_config));
let rustfmt_config: RustfmtConfig = t!(toml::from_str(&rustfmt_config));
let mut ignore_fmt = ignore::overrides::OverrideBuilder::new(&build.src);
let mut fmt_override = ignore::overrides::OverrideBuilder::new(&build.src);
for ignore in rustfmt_config.ignore {
ignore_fmt.add(&format!("!{ignore}")).expect(&ignore);
fmt_override.add(&format!("!{ignore}")).expect(&ignore);
}
let git_available = match Command::new("git")
.arg("--version")
Expand Down Expand Up @@ -161,38 +161,38 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
// against anything like `compiler/rustc_foo/src/foo.rs`,
// preventing the latter from being formatted.
untracked_count += 1;
ignore_fmt.add(&format!("!/{untracked_path}")).expect(&untracked_path);
fmt_override.add(&format!("!/{untracked_path}")).expect(&untracked_path);
}
// Only check modified files locally to speed up runtime.
// We still check all files in CI to avoid bugs in `get_modified_rs_files` letting regressions slip through;
// we also care about CI time less since this is still very fast compared to building the compiler.
if !CiEnv::is_ci() && paths.is_empty() {
match get_modified_rs_files(build) {
Ok(Some(files)) => {
eprintln!("Found {:?} modified files", files);
if files.len() <= 10 {
for file in &files {
println!("formatting modified file {file}");
}
}
let pluralized = |count| if count > 1 { "files" } else { "file" };
let untracked_msg = if untracked_count == 0 {
"".to_string()
} else {
format!(
", skipped {} untracked {}",
untracked_count,
pluralized(untracked_count),
)
};
println!(
"formatting {} modified {}{}",
files.len(),
pluralized(files.len()),
untracked_msg
);
let pluralized = |count| if count > 1 { "files" } else { "file" };
let untracked_msg = if untracked_count == 0 {
"".to_string()
} else {
format!(
", skipped {} untracked {}",
untracked_count,
pluralized(untracked_count),
)
};
println!(
"formatting {} modified {}{}",
files.len(),
pluralized(files.len()),
untracked_msg
);
}
for file in files {
ignore_fmt.add(&format!("/{file}")).expect(&file);
fmt_override.add(&format!("/{file}")).expect(&file);
}
}
Ok(None) => {}
Expand All @@ -213,7 +213,7 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
println!("Could not find usable git. Skipping git-aware format checks");
}

let ignore_fmt = ignore_fmt.build().unwrap();
let fmt_override = fmt_override.build().unwrap();

let rustfmt_path = build.initial_rustfmt().unwrap_or_else(|| {
eprintln!("./x.py fmt is not supported on this channel");
Expand Down Expand Up @@ -269,7 +269,7 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
None => WalkBuilder::new(src.clone()),
}
.types(matcher)
.overrides(ignore_fmt)
.overrides(fmt_override)
.build_parallel();

// there is a lot of blocking involved in spawning a child process and reading files to format.
Expand Down

0 comments on commit 58bda47

Please sign in to comment.