Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/ci/docker/host-x86_64/tidy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,4 @@ COPY host-x86_64/pr-check-1/validate-toolstate.sh /scripts/

# NOTE: intentionally uses python2 for x.py so we can test it still works.
# validate-toolstate only runs in our CI, so it's ok for it to only support python3.
ENV SCRIPT="TIDY_PRINT_DIFF=1 python2.7 ../x.py test \
src/tools/tidy tidyselftest --extra-checks=py,cpp,js,spellcheck"
ENV SCRIPT="python2.7 ../x.py test src/tools/tidy tidyselftest --extra-checks=py,cpp,js,spellcheck"
3 changes: 1 addition & 2 deletions src/etc/pre-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ ROOT_DIR="$(git rev-parse --show-toplevel)"
echo "Running pre-push script $ROOT_DIR/x test tidy"

cd "$ROOT_DIR"
# The env var is necessary for printing diffs in py (fmt/lint) and cpp.
TIDY_PRINT_DIFF=1 ./x test tidy \
./x test tidy \
--set build.locked-deps=true \
--extra-checks auto:py,auto:cpp,auto:js
if [ $? -ne 0 ]; then
Expand Down
3 changes: 3 additions & 0 deletions src/tools/tidy/src/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,9 @@ pub fn check(root: &Path, cargo: &Path, tidy_ctx: TidyCtx) {

/// Ensure the list of proc-macro crate transitive dependencies is up to date
fn check_proc_macro_dep_list(root: &Path, cargo: &Path, bless: bool, check: &mut RunningCheck) {
if std::env::var("RUSTC").is_err() {
panic!("tidy must be run under bootstrap (./x test tidy), not as a standalone command");
}
let mut cmd = cargo_metadata::MetadataCommand::new();
cmd.cargo_path(cargo)
.manifest_path(root.join("Cargo.toml"))
Expand Down
39 changes: 17 additions & 22 deletions src/tools/tidy/src/extra_checks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
//! configuration after a double dash (`--extra-checks=py -- foo.py`)
//! 2. Build configuration based on args/environment:
//! - Formatters by default are in check only mode
//! - If in CI (TIDY_PRINT_DIFF=1 is set), check and print the diff
//! - If `--bless` is provided, formatters may run
//! - Pass any additional config after the `--`. If no files are specified,
//! use a default.
//! 3. Print the output of the given command. If it fails and `TIDY_PRINT_DIFF`
//! is set, rerun the tool to print a suggestion diff (for e.g. CI)
//! 3. Print the output of the given command. If it fails, rerun the tool to print a suggestion
//! diff.

use std::ffi::{OsStr, OsString};
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -200,14 +199,12 @@ fn js_prepare(root_path: &Path, outdir: &Path, npm: &Path, tidy_ctx: &TidyCtx) -

fn show_bless_help(mode: &str, action: &str, bless: bool) {
if !bless {
eprintln!("rerun tidy with `--extra-checks={mode} --bless` to {action}");
eprintln!(
"rerun with `--bless` to {action}: `./x.py test tidy --extra-checks={mode} --bless`"
);
}
}

fn show_diff() -> bool {
std::env::var("TIDY_PRINT_DIFF").is_ok_and(|v| v.eq_ignore_ascii_case("true") || v == "1")
}

fn check_spellcheck(root_path: &Path, outdir: &Path, cargo: &Path, tidy_ctx: &TidyCtx) {
let mut check = tidy_ctx.start_check("extra_checks:spellcheck");

Expand Down Expand Up @@ -314,7 +311,7 @@ fn check_python_lint(

let res = run_ruff(root_path, outdir, py_path, &cfg_args, &file_args, args);

if res.is_err() && !bless && show_diff() {
if res.is_err() && !bless {
eprintln!("\npython linting failed! Printing diff suggestions:");

let diff_res = run_ruff(
Expand Down Expand Up @@ -358,18 +355,16 @@ fn check_python_fmt(
let res = run_ruff(root_path, outdir, py_path, &cfg_args, &file_args, &args);

if res.is_err() && !bless {
if show_diff() {
eprintln!("\npython formatting does not match! Printing diff:");

let _ = run_ruff(
root_path,
outdir,
py_path,
&cfg_args,
&file_args,
&["format".as_ref(), "--diff".as_ref()],
);
}
eprintln!("\npython formatting does not match! Printing diff:");

let _ = run_ruff(
root_path,
outdir,
py_path,
&cfg_args,
&file_args,
&["format".as_ref(), "--diff".as_ref()],
);
show_bless_help("py:fmt", "reformat Python code", bless);
}

Expand Down Expand Up @@ -421,7 +416,7 @@ fn check_cpp_fmt(
let args = merge_args(&cfg_args_clang_format, &file_args_clang_format);
let res = py_runner(py_path, false, None, "clang-format", &args);

if res.is_err() && !bless && show_diff() {
if res.is_err() && !bless {
eprintln!("\nclang-format linting failed! Printing diff suggestions:");

let mut cfg_args_diff = cfg_args.clone();
Expand Down
Loading