Add support for tidy linting via external tools for non-rust files

This change adds the flag `--check-extras` to `tidy`. It accepts a comma
separated list of any of the options:

- py (test everything applicable for python files)
- py:lint (lint python files using `ruff`)
- py:fmt (check formatting for python files using `black`)
- shell or shell:lint (lint shell files using `shellcheck`)

Specific files to check can also be specified via positional args.
Examples:

- `./x test tidy --check-extras=shell,py`
- `./x test tidy --check-extras=py:fmt -- src/bootstrap/bootstrap.py`
- `./x test tidy --check-extras=shell -- src/ci/*.sh`
- Python formatting can be applied with bless:
  `./x test tidy --ckeck-extras=py:fmt --bless`

`ruff` and `black` need to be installed via pip; this tool manages these
within a virtual environment at `build/venv`. `shellcheck` needs to be
installed on the system already.
This commit is contained in:
Trevor Gross 2023-06-09 02:41:34 -04:00
parent 7a5d2d0138
commit efc49e4dfa
14 changed files with 662 additions and 6 deletions

View file

@ -587,6 +587,7 @@ mod dist {
run: None,
only_modified: false,
skip: vec![],
extra_checks: None,
};
let build = Build::new(config);
@ -658,6 +659,7 @@ mod dist {
pass: None,
run: None,
only_modified: false,
extra_checks: None,
};
// Make sure rustfmt binary not being found isn't an error.
config.channel = "beta".to_string();

View file

@ -336,6 +336,10 @@ pub enum Subcommand {
/// whether to automatically update stderr/stdout files
bless: bool,
#[arg(long)]
/// comma-separated list of other files types to check (accepts py, py:lint,
/// py:fmt, shell)
extra_checks: Option<String>,
#[arg(long)]
/// rerun tests even if the inputs are unchanged
force_rerun: bool,
#[arg(long)]
@ -473,6 +477,13 @@ impl Subcommand {
}
}
pub fn extra_checks(&self) -> Option<&str> {
match *self {
Subcommand::Test { ref extra_checks, .. } => extra_checks.as_ref().map(String::as_str),
_ => None,
}
}
pub fn only_modified(&self) -> bool {
match *self {
Subcommand::Test { only_modified, .. } => only_modified,

View file

@ -4,6 +4,7 @@
//! our CI.
use std::env;
use std::ffi::OsStr;
use std::ffi::OsString;
use std::fs;
use std::iter;
@ -1094,6 +1095,14 @@ impl Step for Tidy {
if builder.config.cmd.bless() {
cmd.arg("--bless");
}
if let Some(s) = builder.config.cmd.extra_checks() {
cmd.arg(format!("--extra-checks={s}"));
}
let mut args = std::env::args_os();
if let Some(_) = args.find(|arg| arg == OsStr::new("--")) {
cmd.arg("--");
cmd.args(args);
}
if builder.config.channel == "dev" || builder.config.channel == "nightly" {
builder.info("fmt check");