Skip to content
Closed
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
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5514,6 +5514,7 @@ dependencies = [
"semver",
"serde",
"similar",
"tempfile",
"termcolor",
"toml 0.7.8",
"walkdir",
Expand Down
6 changes: 6 additions & 0 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,12 @@ impl Step for Tidy {
if builder.config.cmd.bless() {
cmd.arg("--bless");
}
if builder.config.cmd.pre_push() {
cmd.arg("--pre-push");
}
if builder.config.cmd.include_untracked() {
cmd.arg("--include-untracked");
}
if let Some(s) =
builder.config.cmd.extra_checks().or(builder.config.tidy_extra_checks.as_deref())
{
Expand Down
20 changes: 20 additions & 0 deletions src/bootstrap/src/core/config/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,12 @@ pub enum Subcommand {
/// whether to automatically update stderr/stdout files
bless: bool,
#[arg(long)]
/// Whether to run Tidy on the most recent commit, used in the pre-push git-hook.
pre_push: bool,
#[arg(long)]
/// Whether to include files untracked by git when running Tidy.
include_untracked: bool,
#[arg(long)]
/// comma-separated list of other files types to check (accepts py, py:lint,
/// py:fmt, shell, cpp, cpp:fmt, js, js:lint, js:typecheck, spellcheck)
///
Expand Down Expand Up @@ -571,6 +577,20 @@ impl Subcommand {
}
}

pub fn pre_push(&self) -> bool {
match *self {
Subcommand::Test { pre_push, .. } => pre_push,
_ => false,
}
}

pub fn include_untracked(&self) -> bool {
match *self {
Subcommand::Test { include_untracked, .. } => include_untracked,
_ => false,
}
}

pub fn extra_checks(&self) -> Option<&str> {
match *self {
Subcommand::Test { ref extra_checks, .. } => extra_checks.as_ref().map(String::as_str),
Expand Down
2 changes: 2 additions & 0 deletions src/etc/completions/x.fish
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ complete -c x -n "__fish_x_using_subcommand test" -l no-fail-fast -d 'run all te
complete -c x -n "__fish_x_using_subcommand test" -l no-doc -d 'do not run doc tests'
complete -c x -n "__fish_x_using_subcommand test" -l doc -d 'only run doc tests'
complete -c x -n "__fish_x_using_subcommand test" -l bless -d 'whether to automatically update stderr/stdout files'
complete -c x -n "__fish_x_using_subcommand test" -l pre-push -d 'Whether to run Tidy on the most recent commit, used in the pre-push git-hook'
complete -c x -n "__fish_x_using_subcommand test" -l include-untracked -d 'Whether to include files untracked by git when running Tidy'
complete -c x -n "__fish_x_using_subcommand test" -l force-rerun -d 'rerun tests even if the inputs are unchanged'
complete -c x -n "__fish_x_using_subcommand test" -l only-modified -d 'only run tests that result has been changed'
complete -c x -n "__fish_x_using_subcommand test" -l rustfix-coverage -d 'enable this to generate a Rustfix coverage file, which is saved in `/<build_base>/rustfix_missing_coverage.txt`'
Expand Down
2 changes: 2 additions & 0 deletions src/etc/completions/x.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ Register-ArgumentCompleter -Native -CommandName 'x' -ScriptBlock {
[CompletionResult]::new('--no-doc', '--no-doc', [CompletionResultType]::ParameterName, 'do not run doc tests')
[CompletionResult]::new('--doc', '--doc', [CompletionResultType]::ParameterName, 'only run doc tests')
[CompletionResult]::new('--bless', '--bless', [CompletionResultType]::ParameterName, 'whether to automatically update stderr/stdout files')
[CompletionResult]::new('--pre-push', '--pre-push', [CompletionResultType]::ParameterName, 'Whether to run Tidy on the most recent commit, used in the pre-push git-hook')
[CompletionResult]::new('--include-untracked', '--include-untracked', [CompletionResultType]::ParameterName, 'Whether to include files untracked by git when running Tidy')
[CompletionResult]::new('--force-rerun', '--force-rerun', [CompletionResultType]::ParameterName, 'rerun tests even if the inputs are unchanged')
[CompletionResult]::new('--only-modified', '--only-modified', [CompletionResultType]::ParameterName, 'only run tests that result has been changed')
[CompletionResult]::new('--rustfix-coverage', '--rustfix-coverage', [CompletionResultType]::ParameterName, 'enable this to generate a Rustfix coverage file, which is saved in `/<build_base>/rustfix_missing_coverage.txt`')
Expand Down
2 changes: 2 additions & 0 deletions src/etc/completions/x.py.fish
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ complete -c x.py -n "__fish_x.py_using_subcommand test" -l no-fail-fast -d 'run
complete -c x.py -n "__fish_x.py_using_subcommand test" -l no-doc -d 'do not run doc tests'
complete -c x.py -n "__fish_x.py_using_subcommand test" -l doc -d 'only run doc tests'
complete -c x.py -n "__fish_x.py_using_subcommand test" -l bless -d 'whether to automatically update stderr/stdout files'
complete -c x.py -n "__fish_x.py_using_subcommand test" -l pre-push -d 'Whether to run Tidy on the most recent commit, used in the pre-push git-hook'
complete -c x.py -n "__fish_x.py_using_subcommand test" -l include-untracked -d 'Whether to include files untracked by git when running Tidy'
complete -c x.py -n "__fish_x.py_using_subcommand test" -l force-rerun -d 'rerun tests even if the inputs are unchanged'
complete -c x.py -n "__fish_x.py_using_subcommand test" -l only-modified -d 'only run tests that result has been changed'
complete -c x.py -n "__fish_x.py_using_subcommand test" -l rustfix-coverage -d 'enable this to generate a Rustfix coverage file, which is saved in `/<build_base>/rustfix_missing_coverage.txt`'
Expand Down
2 changes: 2 additions & 0 deletions src/etc/completions/x.py.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ Register-ArgumentCompleter -Native -CommandName 'x.py' -ScriptBlock {
[CompletionResult]::new('--no-doc', '--no-doc', [CompletionResultType]::ParameterName, 'do not run doc tests')
[CompletionResult]::new('--doc', '--doc', [CompletionResultType]::ParameterName, 'only run doc tests')
[CompletionResult]::new('--bless', '--bless', [CompletionResultType]::ParameterName, 'whether to automatically update stderr/stdout files')
[CompletionResult]::new('--pre-push', '--pre-push', [CompletionResultType]::ParameterName, 'Whether to run Tidy on the most recent commit, used in the pre-push git-hook')
[CompletionResult]::new('--include-untracked', '--include-untracked', [CompletionResultType]::ParameterName, 'Whether to include files untracked by git when running Tidy')
[CompletionResult]::new('--force-rerun', '--force-rerun', [CompletionResultType]::ParameterName, 'rerun tests even if the inputs are unchanged')
[CompletionResult]::new('--only-modified', '--only-modified', [CompletionResultType]::ParameterName, 'only run tests that result has been changed')
[CompletionResult]::new('--rustfix-coverage', '--rustfix-coverage', [CompletionResultType]::ParameterName, 'enable this to generate a Rustfix coverage file, which is saved in `/<build_base>/rustfix_missing_coverage.txt`')
Expand Down
2 changes: 1 addition & 1 deletion src/etc/completions/x.py.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3875,7 +3875,7 @@ _x.py() {
return 0
;;
x.py__test)
opts="-v -i -j -h --no-fail-fast --test-args --compiletest-rustc-args --no-doc --doc --bless --extra-checks --force-rerun --only-modified --compare-mode --pass --run --rustfix-coverage --no-capture --test-codegen-backend --verbose --incremental --config --build-dir --build --host --target --exclude --skip --include-default-paths --rustc-error-format --on-fail --dry-run --dump-bootstrap-shims --stage --keep-stage --keep-stage-std --src --jobs --warnings --json-output --compile-time-deps --color --bypass-bootstrap-lock --rust-profile-generate --rust-profile-use --llvm-profile-use --llvm-profile-generate --enable-bolt-settings --skip-stage0-validation --reproducible-artifact --set --ci --skip-std-check-if-no-download-rustc --help [PATHS]... [ARGS]..."
opts="-v -i -j -h --no-fail-fast --test-args --compiletest-rustc-args --no-doc --doc --bless --pre-push --include-untracked --extra-checks --force-rerun --only-modified --compare-mode --pass --run --rustfix-coverage --no-capture --test-codegen-backend --verbose --incremental --config --build-dir --build --host --target --exclude --skip --include-default-paths --rustc-error-format --on-fail --dry-run --dump-bootstrap-shims --stage --keep-stage --keep-stage-std --src --jobs --warnings --json-output --compile-time-deps --color --bypass-bootstrap-lock --rust-profile-generate --rust-profile-use --llvm-profile-use --llvm-profile-generate --enable-bolt-settings --skip-stage0-validation --reproducible-artifact --set --ci --skip-std-check-if-no-download-rustc --help [PATHS]... [ARGS]..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down
2 changes: 2 additions & 0 deletions src/etc/completions/x.py.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ _arguments "${_arguments_options[@]}" : \
'--no-doc[do not run doc tests]' \
'--doc[only run doc tests]' \
'--bless[whether to automatically update stderr/stdout files]' \
'--pre-push[Whether to run Tidy on the most recent commit, used in the pre-push git-hook]' \
'--include-untracked[Whether to include files untracked by git when running Tidy]' \
'--force-rerun[rerun tests even if the inputs are unchanged]' \
'--only-modified[only run tests that result has been changed]' \
'--rustfix-coverage[enable this to generate a Rustfix coverage file, which is saved in \`/<build_base>/rustfix_missing_coverage.txt\`]' \
Expand Down
2 changes: 1 addition & 1 deletion src/etc/completions/x.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3875,7 +3875,7 @@ _x() {
return 0
;;
x__test)
opts="-v -i -j -h --no-fail-fast --test-args --compiletest-rustc-args --no-doc --doc --bless --extra-checks --force-rerun --only-modified --compare-mode --pass --run --rustfix-coverage --no-capture --test-codegen-backend --verbose --incremental --config --build-dir --build --host --target --exclude --skip --include-default-paths --rustc-error-format --on-fail --dry-run --dump-bootstrap-shims --stage --keep-stage --keep-stage-std --src --jobs --warnings --json-output --compile-time-deps --color --bypass-bootstrap-lock --rust-profile-generate --rust-profile-use --llvm-profile-use --llvm-profile-generate --enable-bolt-settings --skip-stage0-validation --reproducible-artifact --set --ci --skip-std-check-if-no-download-rustc --help [PATHS]... [ARGS]..."
opts="-v -i -j -h --no-fail-fast --test-args --compiletest-rustc-args --no-doc --doc --bless --pre-push --include-untracked --extra-checks --force-rerun --only-modified --compare-mode --pass --run --rustfix-coverage --no-capture --test-codegen-backend --verbose --incremental --config --build-dir --build --host --target --exclude --skip --include-default-paths --rustc-error-format --on-fail --dry-run --dump-bootstrap-shims --stage --keep-stage --keep-stage-std --src --jobs --warnings --json-output --compile-time-deps --color --bypass-bootstrap-lock --rust-profile-generate --rust-profile-use --llvm-profile-use --llvm-profile-generate --enable-bolt-settings --skip-stage0-validation --reproducible-artifact --set --ci --skip-std-check-if-no-download-rustc --help [PATHS]... [ARGS]..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down
2 changes: 2 additions & 0 deletions src/etc/completions/x.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ _arguments "${_arguments_options[@]}" : \
'--no-doc[do not run doc tests]' \
'--doc[only run doc tests]' \
'--bless[whether to automatically update stderr/stdout files]' \
'--pre-push[Whether to run Tidy on the most recent commit, used in the pre-push git-hook]' \
'--include-untracked[Whether to include files untracked by git when running Tidy]' \
'--force-rerun[rerun tests even if the inputs are unchanged]' \
'--only-modified[only run tests that result has been changed]' \
'--rustfix-coverage[enable this to generate a Rustfix coverage file, which is saved in \`/<build_base>/rustfix_missing_coverage.txt\`]' \
Expand Down
2 changes: 2 additions & 0 deletions src/etc/pre-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ cd "$ROOT_DIR"
# The env var is necessary for printing diffs in py (fmt/lint) and cpp.
TIDY_PRINT_DIFF=1 ./x test tidy \
--set build.locked-deps=true \
--pre-push \
--extra-checks auto:py,auto:cpp,auto:js

if [ $? -ne 0 ]; then
echo "You may use \`git push --no-verify\` to skip this check."
exit 1
Expand Down
4 changes: 2 additions & 2 deletions src/tools/features-status-dump/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::path::PathBuf;

use anyhow::{Context, Result};
use clap::Parser;
use tidy::diagnostics::RunningCheck;
use tidy::diagnostics::{RunningCheck, TidyFlags};
use tidy::features::{Feature, collect_lang_features, collect_lib_features};

#[derive(Debug, Parser)]
Expand All @@ -31,7 +31,7 @@ fn main() -> Result<()> {
let Cli { compiler_path, library_path, output_path } = Cli::parse();

let lang_features_status = collect_lang_features(&compiler_path, &mut RunningCheck::new_noop());
let lib_features_status = collect_lib_features(&library_path)
let lib_features_status = collect_lib_features(&library_path, &TidyFlags::default())
.into_iter()
.filter(|&(ref name, _)| !lang_features_status.contains_key(name))
.collect();
Expand Down
2 changes: 2 additions & 0 deletions src/tools/replace-version-placeholder/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::path::PathBuf;

use tidy::diagnostics::TidyFlags;
use tidy::{t, walk};

pub const VERSION_PLACEHOLDER: &str = "CURRENT_RUSTC_VERSION";
Expand All @@ -16,6 +17,7 @@ fn main() {
&root_path.join("src/doc/rustc"),
&root_path.join("src/doc/rustdoc"),
],
&TidyFlags::default(),
|path, _is_dir| walk::filter_dirs(path),
&mut |entry, contents| {
if !contents.contains(VERSION_PLACEHOLDER) {
Expand Down
3 changes: 3 additions & 0 deletions src/tools/tidy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ fluent-syntax = "0.12"
similar = "2.5.0"
toml = "0.7.8"

[dev-dependencies]
tempfile = "3"

[features]
build-metrics = ["dep:serde"]

Expand Down
11 changes: 11 additions & 0 deletions src/tools/tidy/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,20 @@ You can run tidy manually with:

`./x test tidy`

### Tidy Flags

To first run the relevant formatter and then run tidy you can add `--bless`.

`./x test tidy --bless`

To include files untracked by git you can add `--include-untracked`. This does not currently change the behavior of `--extra-checks`. To include untracked `js`, `py`, or `cpp` files you'll need to manually add them with git.

`./x test tidy --include-untracked` \

To run tidy on the `HEAD` commit (the most recent commit of your current working branch) you can add `--pre-push`. This flag is added automatically when used with the pre-push git hook.

`./x test tidy --pre-push`

### Extra Checks
[`extra_checks`](https://doc.rust-lang.org/nightly/nightly-rustc/tidy/extra_checks/index.html) are optional checks primarily focused on other file types and programming languages.

Expand Down
8 changes: 4 additions & 4 deletions src/tools/tidy/src/alphabetical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::fmt::Display;
use std::iter::Peekable;
use std::path::Path;

use crate::diagnostics::{CheckId, DiagCtx, RunningCheck};
use crate::diagnostics::{CheckId, RunningCheck, TidyCtx};
use crate::walk::{filter_dirs, walk};

#[cfg(test)]
Expand Down Expand Up @@ -130,13 +130,13 @@ fn check_lines<'a>(
}
}

pub fn check(path: &Path, diag_ctx: DiagCtx) {
let mut check = diag_ctx.start_check(CheckId::new("alphabetical").path(path));
pub fn check(path: &Path, tidy_ctx: TidyCtx) {
let mut check = tidy_ctx.start_check(CheckId::new("alphabetical").path(path));

let skip =
|path: &_, _is_dir| filter_dirs(path) || path.ends_with("tidy/src/alphabetical/tests.rs");

walk(path, skip, &mut |entry, contents| {
walk(path, &tidy_ctx.tidy_flags, skip, &mut |entry, contents| {
let file = &entry.path().display();
let lines = contents.lines().enumerate();
check_lines(file, lines, &mut check)
Expand Down
6 changes: 3 additions & 3 deletions src/tools/tidy/src/alphabetical/tests.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::path::Path;

use crate::alphabetical::check_lines;
use crate::diagnostics::DiagCtx;
use crate::diagnostics::{TidyCtx, TidyFlags};

#[track_caller]
fn test(lines: &str, name: &str, expected_msg: &str, expected_bad: bool) {
let diag_ctx = DiagCtx::new(Path::new("/"), false);
let mut check = diag_ctx.start_check("alphabetical-test");
let tidy_ctx = TidyCtx::new(Path::new("/"), TidyFlags::default(), false);
let mut check = tidy_ctx.start_check("alphabetical-test");
check_lines(&name, lines.lines().enumerate(), &mut check);

assert_eq!(expected_bad, check.is_bad());
Expand Down
12 changes: 7 additions & 5 deletions src/tools/tidy/src/bins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ pub use os_impl::*;
mod os_impl {
use std::path::Path;

use crate::diagnostics::DiagCtx;
use crate::diagnostics::TidyCtx;

pub fn check_filesystem_support(_sources: &[&Path], _output: &Path) -> bool {
return false;
}

pub fn check(_path: &Path, _diag_ctx: DiagCtx) {}
pub fn check(_path: &Path, _tidy_ctx: TidyCtx) {}
}

#[cfg(unix)]
Expand All @@ -28,6 +28,7 @@ mod os_impl {
use std::path::Path;
use std::process::{Command, Stdio};

#[cfg(unix)]
use crate::walk::{filter_dirs, walk_no_read};

enum FilesystemSupport {
Expand All @@ -38,7 +39,7 @@ mod os_impl {

use FilesystemSupport::*;

use crate::diagnostics::DiagCtx;
use crate::diagnostics::TidyCtx;

fn is_executable(path: &Path) -> std::io::Result<bool> {
Ok(path.metadata()?.mode() & 0o111 != 0)
Expand Down Expand Up @@ -110,8 +111,8 @@ mod os_impl {
}

#[cfg(unix)]
pub fn check(path: &Path, diag_ctx: DiagCtx) {
let mut check = diag_ctx.start_check("bins");
pub fn check(path: &Path, tidy_ctx: TidyCtx) {
let mut check = tidy_ctx.start_check("bins");

use std::ffi::OsStr;

Expand All @@ -127,6 +128,7 @@ mod os_impl {
// (e.g. using `git ls-files`).
walk_no_read(
&[path],
&tidy_ctx.tidy_flags,
|path, _is_dir| {
filter_dirs(path)
|| path.ends_with("src/etc")
Expand Down
7 changes: 4 additions & 3 deletions src/tools/tidy/src/debug_artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

use std::path::Path;

use crate::diagnostics::{CheckId, DiagCtx};
use crate::diagnostics::{CheckId, TidyCtx};
use crate::walk::{filter_dirs, filter_not_rust, walk};

const GRAPHVIZ_POSTFLOW_MSG: &str = "`borrowck_graphviz_postflow` attribute in test";

pub fn check(test_dir: &Path, diag_ctx: DiagCtx) {
let mut check = diag_ctx.start_check(CheckId::new("debug_artifacts").path(test_dir));
pub fn check(test_dir: &Path, tidy_ctx: TidyCtx) {
let mut check = tidy_ctx.start_check(CheckId::new("debug_artifacts").path(test_dir));

walk(
test_dir,
&tidy_ctx.tidy_flags,
|path, _is_dir| filter_dirs(path) || filter_not_rust(path),
&mut |entry, contents| {
for (i, line) in contents.lines().enumerate() {
Expand Down
7 changes: 4 additions & 3 deletions src/tools/tidy/src/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use build_helper::ci::CiEnv;
use cargo_metadata::semver::Version;
use cargo_metadata::{Metadata, Package, PackageId};

use crate::diagnostics::{DiagCtx, RunningCheck};
use crate::diagnostics::{RunningCheck, TidyCtx};

#[path = "../../../bootstrap/src/utils/proc_macro_deps.rs"]
mod proc_macro_deps;
Expand Down Expand Up @@ -666,8 +666,9 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[
///
/// `root` is path to the directory with the root `Cargo.toml` (for the workspace). `cargo` is path
/// to the cargo executable.
pub fn check(root: &Path, cargo: &Path, bless: bool, diag_ctx: DiagCtx) {
let mut check = diag_ctx.start_check("deps");
pub fn check(root: &Path, cargo: &Path, tidy_ctx: TidyCtx) {
let mut check = tidy_ctx.start_check("deps");
let bless = tidy_ctx.tidy_flags.bless;

let mut checked_runtime_licenses = false;

Expand Down
Loading
Loading