Skip to content

Commit 9887e63

Browse files
committed
tidy: add auto: prefix to --extra-checks syntax
currently this just uses a very simple extension-based heirustic.
1 parent 2d0f2ab commit 9887e63

File tree

9 files changed

+57
-12
lines changed

9 files changed

+57
-12
lines changed

src/bootstrap/src/core/config/flags.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,10 @@ pub enum Subcommand {
382382
bless: bool,
383383
#[arg(long)]
384384
/// comma-separated list of other files types to check (accepts py, py:lint,
385-
/// py:fmt, shell)
385+
/// py:fmt, cpp, shell)
386+
///
387+
/// Any argument can be prefixed with "auto:" to only run if
388+
/// relevant files are modified (eg. "auto:py").
386389
extra_checks: Option<String>,
387390
#[arg(long)]
388391
/// rerun tests even if the inputs are unchanged

src/etc/completions/x.fish

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ complete -c x -n "__fish_x_using_subcommand doc" -l skip-std-check-if-no-downloa
293293
complete -c x -n "__fish_x_using_subcommand doc" -s h -l help -d 'Print help (see more with \'--help\')'
294294
complete -c x -n "__fish_x_using_subcommand test" -l test-args -d 'extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)' -r
295295
complete -c x -n "__fish_x_using_subcommand test" -l compiletest-rustc-args -d 'extra options to pass the compiler when running compiletest tests' -r
296-
complete -c x -n "__fish_x_using_subcommand test" -l extra-checks -d 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell)' -r
296+
complete -c x -n "__fish_x_using_subcommand test" -l extra-checks -d 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, cpp, shell)' -r
297297
complete -c x -n "__fish_x_using_subcommand test" -l compare-mode -d 'mode describing what file the actual ui output will be compared to' -r
298298
complete -c x -n "__fish_x_using_subcommand test" -l pass -d 'force {check,build,run}-pass tests to this mode' -r
299299
complete -c x -n "__fish_x_using_subcommand test" -l run -d 'whether to execute run-* tests' -r

src/etc/completions/x.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ Register-ArgumentCompleter -Native -CommandName 'x' -ScriptBlock {
339339
'x;test' {
340340
[CompletionResult]::new('--test-args', '--test-args', [CompletionResultType]::ParameterName, 'extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)')
341341
[CompletionResult]::new('--compiletest-rustc-args', '--compiletest-rustc-args', [CompletionResultType]::ParameterName, 'extra options to pass the compiler when running compiletest tests')
342-
[CompletionResult]::new('--extra-checks', '--extra-checks', [CompletionResultType]::ParameterName, 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell)')
342+
[CompletionResult]::new('--extra-checks', '--extra-checks', [CompletionResultType]::ParameterName, 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, cpp, shell)')
343343
[CompletionResult]::new('--compare-mode', '--compare-mode', [CompletionResultType]::ParameterName, 'mode describing what file the actual ui output will be compared to')
344344
[CompletionResult]::new('--pass', '--pass', [CompletionResultType]::ParameterName, 'force {check,build,run}-pass tests to this mode')
345345
[CompletionResult]::new('--run', '--run', [CompletionResultType]::ParameterName, 'whether to execute run-* tests')

src/etc/completions/x.py.fish

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ complete -c x.py -n "__fish_x.py_using_subcommand doc" -l skip-std-check-if-no-d
293293
complete -c x.py -n "__fish_x.py_using_subcommand doc" -s h -l help -d 'Print help (see more with \'--help\')'
294294
complete -c x.py -n "__fish_x.py_using_subcommand test" -l test-args -d 'extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)' -r
295295
complete -c x.py -n "__fish_x.py_using_subcommand test" -l compiletest-rustc-args -d 'extra options to pass the compiler when running compiletest tests' -r
296-
complete -c x.py -n "__fish_x.py_using_subcommand test" -l extra-checks -d 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell)' -r
296+
complete -c x.py -n "__fish_x.py_using_subcommand test" -l extra-checks -d 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, cpp, shell)' -r
297297
complete -c x.py -n "__fish_x.py_using_subcommand test" -l compare-mode -d 'mode describing what file the actual ui output will be compared to' -r
298298
complete -c x.py -n "__fish_x.py_using_subcommand test" -l pass -d 'force {check,build,run}-pass tests to this mode' -r
299299
complete -c x.py -n "__fish_x.py_using_subcommand test" -l run -d 'whether to execute run-* tests' -r

src/etc/completions/x.py.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ Register-ArgumentCompleter -Native -CommandName 'x.py' -ScriptBlock {
339339
'x.py;test' {
340340
[CompletionResult]::new('--test-args', '--test-args', [CompletionResultType]::ParameterName, 'extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)')
341341
[CompletionResult]::new('--compiletest-rustc-args', '--compiletest-rustc-args', [CompletionResultType]::ParameterName, 'extra options to pass the compiler when running compiletest tests')
342-
[CompletionResult]::new('--extra-checks', '--extra-checks', [CompletionResultType]::ParameterName, 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, shell)')
342+
[CompletionResult]::new('--extra-checks', '--extra-checks', [CompletionResultType]::ParameterName, 'comma-separated list of other files types to check (accepts py, py:lint, py:fmt, cpp, shell)')
343343
[CompletionResult]::new('--compare-mode', '--compare-mode', [CompletionResultType]::ParameterName, 'mode describing what file the actual ui output will be compared to')
344344
[CompletionResult]::new('--pass', '--pass', [CompletionResultType]::ParameterName, 'force {check,build,run}-pass tests to this mode')
345345
[CompletionResult]::new('--run', '--run', [CompletionResultType]::ParameterName, 'whether to execute run-* tests')

src/etc/completions/x.py.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ _arguments "${_arguments_options[@]}" : \
338338
_arguments "${_arguments_options[@]}" : \
339339
'*--test-args=[extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)]:ARGS:_default' \
340340
'*--compiletest-rustc-args=[extra options to pass the compiler when running compiletest tests]:ARGS:_default' \
341-
'--extra-checks=[comma-separated list of other files types to check (accepts py, py\:lint, py\:fmt, shell)]:EXTRA_CHECKS:_default' \
341+
'--extra-checks=[comma-separated list of other files types to check (accepts py, py\:lint, py\:fmt, cpp, shell)]:EXTRA_CHECKS:_default' \
342342
'--compare-mode=[mode describing what file the actual ui output will be compared to]:COMPARE MODE:_default' \
343343
'--pass=[force {check,build,run}-pass tests to this mode]:check | build | run:_default' \
344344
'--run=[whether to execute run-* tests]:auto | always | never:_default' \

src/etc/completions/x.zsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ _arguments "${_arguments_options[@]}" : \
338338
_arguments "${_arguments_options[@]}" : \
339339
'*--test-args=[extra arguments to be passed for the test tool being used (e.g. libtest, compiletest or rustdoc)]:ARGS:_default' \
340340
'*--compiletest-rustc-args=[extra options to pass the compiler when running compiletest tests]:ARGS:_default' \
341-
'--extra-checks=[comma-separated list of other files types to check (accepts py, py\:lint, py\:fmt, shell)]:EXTRA_CHECKS:_default' \
341+
'--extra-checks=[comma-separated list of other files types to check (accepts py, py\:lint, py\:fmt, cpp, shell)]:EXTRA_CHECKS:_default' \
342342
'--compare-mode=[mode describing what file the actual ui output will be compared to]:COMPARE MODE:_default' \
343343
'--pass=[force {check,build,run}-pass tests to this mode]:check | build | run:_default' \
344344
'--run=[whether to execute run-* tests]:auto | always | never:_default' \

src/tools/tidy/src/ext_tool_checks.rs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ use std::process::Command;
2323
use std::str::FromStr;
2424
use std::{fmt, fs, io};
2525

26+
use crate::CiInfo;
27+
2628
const MIN_PY_REV: (u32, u32) = (3, 9);
2729
const MIN_PY_REV_STR: &str = "≥3.9";
2830

@@ -40,19 +42,21 @@ const PIP_REQ_PATH: &[&str] = &["src", "tools", "tidy", "config", "requirements.
4042
pub fn check(
4143
root_path: &Path,
4244
outdir: &Path,
45+
ci_info: &CiInfo,
4346
bless: bool,
4447
extra_checks: Option<&str>,
4548
pos_args: &[String],
4649
bad: &mut bool,
4750
) {
48-
if let Err(e) = check_impl(root_path, outdir, bless, extra_checks, pos_args) {
51+
if let Err(e) = check_impl(root_path, outdir, ci_info, bless, extra_checks, pos_args) {
4952
tidy_error!(bad, "{e}");
5053
}
5154
}
5255

5356
fn check_impl(
5457
root_path: &Path,
5558
outdir: &Path,
59+
ci_info: &CiInfo,
5660
bless: bool,
5761
extra_checks: Option<&str>,
5862
pos_args: &[String],
@@ -68,7 +72,13 @@ fn check_impl(
6872
.split(',')
6973
.map(|s| (ExtraCheckArg::from_str(s), s))
7074
.filter_map(|(res, src)| match res {
71-
Ok(x) => Some(x),
75+
Ok(arg) => {
76+
if arg.is_inactive_auto(ci_info) {
77+
None
78+
} else {
79+
Some(arg)
80+
}
81+
}
7282
Err(err) => {
7383
eprintln!("warning: bad extra check argument {src:?}: {err:?}");
7484
None
@@ -606,9 +616,12 @@ enum ExtraCheckParseError {
606616
TooManyParts,
607617
/// Tried to parse the empty string
608618
Empty,
619+
/// `auto` specified without lang part.
620+
AutoRequiresLang,
609621
}
610622

611623
struct ExtraCheckArg {
624+
auto: bool,
612625
lang: ExtraCheckLang,
613626
/// None = run all extra checks for the given lang
614627
kind: Option<ExtraCheckKind>,
@@ -618,21 +631,42 @@ impl ExtraCheckArg {
618631
fn matches(&self, lang: ExtraCheckLang, kind: ExtraCheckKind) -> bool {
619632
self.lang == lang && self.kind.map(|k| k == kind).unwrap_or(true)
620633
}
634+
635+
/// Returns `true` if this is an auto arg and the relevant files are not modified.
636+
fn is_inactive_auto(&self, ci_info: &CiInfo) -> bool {
637+
if !self.auto {
638+
return false;
639+
}
640+
let ext = match self.lang {
641+
ExtraCheckLang::Py => ".py",
642+
ExtraCheckLang::Cpp => ".cpp",
643+
ExtraCheckLang::Shell => ".sh",
644+
};
645+
!crate::files_modified(ci_info, |s| s.ends_with(ext))
646+
}
621647
}
622648

623649
impl FromStr for ExtraCheckArg {
624650
type Err = ExtraCheckParseError;
625651

626652
fn from_str(s: &str) -> Result<Self, Self::Err> {
653+
let mut auto = false;
627654
let mut parts = s.split(':');
628-
let Some(first) = parts.next() else {
655+
let Some(mut first) = parts.next() else {
629656
return Err(ExtraCheckParseError::Empty);
630657
};
658+
if first == "auto" {
659+
let Some(part) = parts.next() else {
660+
return Err(ExtraCheckParseError::AutoRequiresLang);
661+
};
662+
auto = true;
663+
first = part;
664+
}
631665
let second = parts.next();
632666
if parts.next().is_some() {
633667
return Err(ExtraCheckParseError::TooManyParts);
634668
}
635-
Ok(Self { lang: first.parse()?, kind: second.map(|s| s.parse()).transpose()? })
669+
Ok(Self { auto, lang: first.parse()?, kind: second.map(|s| s.parse()).transpose()? })
636670
}
637671
}
638672

src/tools/tidy/src/main.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,15 @@ fn main() {
173173
};
174174
check!(unstable_book, &src_path, collected);
175175

176-
check!(ext_tool_checks, &root_path, &output_directory, bless, extra_checks, pos_args);
176+
check!(
177+
ext_tool_checks,
178+
&root_path,
179+
&output_directory,
180+
&ci_info,
181+
bless,
182+
extra_checks,
183+
pos_args
184+
);
177185
});
178186

179187
if bad.load(Ordering::Relaxed) {

0 commit comments

Comments
 (0)