Skip to content
Open
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
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
2 changes: 1 addition & 1 deletion src/tools/features-status-dump/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, None)
.into_iter()
.filter(|&(ref name, _)| !lang_features_status.contains_key(name))
.collect();
Expand Down
1 change: 1 addition & 0 deletions src/tools/replace-version-placeholder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fn main() {
&root_path.join("src/doc/rustc"),
&root_path.join("src/doc/rustdoc"),
],
None,
|path, _is_dir| walk::filter_dirs(path),
&mut |entry, contents| {
if !contents.contains(VERSION_PLACEHOLDER) {
Expand Down
5 changes: 3 additions & 2 deletions src/tools/tidy/src/alphabetical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use std::fmt::Display;
use std::iter::Peekable;
use std::path::Path;

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

Expand Down Expand Up @@ -130,13 +131,13 @@ fn check_lines<'a>(
}
}

pub fn check(path: &Path, diag_ctx: DiagCtx) {
pub fn check(path: &Path, tidy_ctx: Option<&TidyCtx>, diag_ctx: DiagCtx) {
let mut check = diag_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, skip, &mut |entry, contents| {
let file = &entry.path().display();
let lines = contents.lines().enumerate();
check_lines(file, lines, &mut check)
Expand Down
5 changes: 4 additions & 1 deletion src/tools/tidy/src/bins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ mod os_impl {
use std::path::Path;
use std::process::{Command, Stdio};

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

enum FilesystemSupport {
Expand Down Expand Up @@ -110,7 +112,7 @@ mod os_impl {
}

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

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

use std::path::Path;

use crate::TidyCtx;
use crate::diagnostics::{CheckId, DiagCtx};
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) {
pub fn check(test_dir: &Path, tidy_ctx: Option<&TidyCtx>, diag_ctx: DiagCtx) {
let mut check = diag_ctx.start_check(CheckId::new("debug_artifacts").path(test_dir));

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

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

#[path = "../../../bootstrap/src/utils/proc_macro_deps.rs"]
Expand Down Expand Up @@ -666,8 +667,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) {
pub fn check(root: &Path, cargo: &Path, tidy_ctx: Option<&TidyCtx>, diag_ctx: DiagCtx) {
let mut check = diag_ctx.start_check("deps");
let bless = tidy_ctx.map(|flags| flags.bless).unwrap_or(false);

let mut checked_runtime_licenses = false;

Expand Down
5 changes: 3 additions & 2 deletions src/tools/tidy/src/edition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

use std::path::Path;

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

pub fn check(path: &Path, diag_ctx: DiagCtx) {
pub fn check(path: &Path, tidy_ctx: Option<&TidyCtx>, diag_ctx: DiagCtx) {
let mut check = diag_ctx.start_check(CheckId::new("edition").path(path));
walk(path, |path, _is_dir| filter_dirs(path), &mut |entry, contents| {
walk(path, tidy_ctx, |path, _is_dir| filter_dirs(path), &mut |entry, contents| {
let file = entry.path();
let filename = file.file_name().unwrap();
if filename != "Cargo.toml" {
Expand Down
19 changes: 14 additions & 5 deletions src/tools/tidy/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use std::path::Path;

use regex::Regex;

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

Expand All @@ -36,7 +37,13 @@ const IGNORE_DOCTEST_CHECK: &[&str] = &["E0464", "E0570", "E0601", "E0602", "E07
const IGNORE_UI_TEST_CHECK: &[&str] =
&["E0461", "E0465", "E0514", "E0554", "E0640", "E0717", "E0729"];

pub fn check(root_path: &Path, search_paths: &[&Path], ci_info: &crate::CiInfo, diag_ctx: DiagCtx) {
pub fn check(
root_path: &Path,
search_paths: &[&Path],
ci_info: &crate::CiInfo,
tidy_ctx: Option<&TidyCtx>,
diag_ctx: DiagCtx,
) {
let mut check = diag_ctx.start_check("error_codes");

// Check that no error code explanation was removed.
Expand All @@ -48,13 +55,13 @@ pub fn check(root_path: &Path, search_paths: &[&Path], ci_info: &crate::CiInfo,
check.verbose_msg(format!("Highest error code: `{}`", error_codes.iter().max().unwrap()));

// Stage 2: check list has docs
let no_longer_emitted = check_error_codes_docs(root_path, &error_codes, &mut check);
let no_longer_emitted = check_error_codes_docs(root_path, &error_codes, &mut check, tidy_ctx);

// Stage 3: check list has UI tests
check_error_codes_tests(root_path, &error_codes, &mut check, &no_longer_emitted);

// Stage 4: check list is emitted by compiler
check_error_codes_used(search_paths, &error_codes, &mut check, &no_longer_emitted);
check_error_codes_used(search_paths, &error_codes, &mut check, &no_longer_emitted, tidy_ctx);
}

fn check_removed_error_code_explanation(ci_info: &crate::CiInfo, check: &mut RunningCheck) {
Expand Down Expand Up @@ -154,12 +161,13 @@ fn check_error_codes_docs(
root_path: &Path,
error_codes: &[String],
check: &mut RunningCheck,
tidy_ctx: Option<&TidyCtx>,
) -> Vec<String> {
let docs_path = root_path.join(Path::new(ERROR_DOCS_PATH));

let mut no_longer_emitted_codes = Vec::new();

walk(&docs_path, |_, _| false, &mut |entry, contents| {
walk(&docs_path, tidy_ctx, |_, _| false, &mut |entry, contents| {
let path = entry.path();

// Error if the file isn't markdown.
Expand Down Expand Up @@ -331,13 +339,14 @@ fn check_error_codes_used(
error_codes: &[String],
check: &mut RunningCheck,
no_longer_emitted: &[String],
tidy_ctx: Option<&TidyCtx>,
) {
// Search for error codes in the form `E0123`.
let regex = Regex::new(r#"\bE\d{4}\b"#).unwrap();

let mut found_codes = Vec::new();

walk_many(search_paths, |path, _is_dir| filter_dirs(path), &mut |entry, contents| {
walk_many(search_paths, tidy_ctx, |path, _is_dir| filter_dirs(path), &mut |entry, contents| {
let path = entry.path();

// Return early if we aren't looking at a source file.
Expand Down
Loading
Loading