Skip to content

Commit cdd97ba

Browse files
authoredMar 9, 2025
Rollup merge of #137885 - klensy:tidy-triagebot, r=jieyouxu
tidy: add triagebot checks Validates triagebot.toml to have existing paths: `[mentions."*"]` sections, i.e. ```toml [mentions."compiler/rustc_const_eval/src/"] ``` or ```toml [assign.owners] "/.github/workflows" = ["infra-ci"] ``` or ```toml trigger_files = [ "src/librustdoc/html/static/js/search.js", "tests/rustdoc-js", "tests/rustdoc-js-std", ] ``` Looked at #137876 and implemented check.
2 parents eade7e9 + aa72de9 commit cdd97ba

File tree

6 files changed

+103
-11
lines changed

6 files changed

+103
-11
lines changed
 

‎Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -5271,6 +5271,7 @@ dependencies = [
52715271
"serde",
52725272
"similar",
52735273
"termcolor",
5274+
"toml 0.7.8",
52745275
"walkdir",
52755276
]
52765277

‎src/tools/tidy/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ termcolor = "1.1.3"
1717
rustc-hash = "2.0.0"
1818
fluent-syntax = "0.11.1"
1919
similar = "2.5.0"
20+
toml = "0.7.8"
2021

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

‎src/tools/tidy/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ pub mod target_policy;
8787
pub mod target_specific_tests;
8888
pub mod tests_placement;
8989
pub mod tests_revision_unpaired_stdout_stderr;
90+
pub mod triagebot;
9091
pub mod ui_tests;
9192
pub mod unit_tests;
9293
pub mod unknown_revision;

‎src/tools/tidy/src/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ fn main() {
144144

145145
check!(x_version, &root_path, &cargo);
146146

147+
check!(triagebot, &root_path);
148+
147149
let collected = {
148150
drain_handles(&mut handles);
149151

‎src/tools/tidy/src/triagebot.rs

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
//! Tidy check to ensure paths mentioned in triagebot.toml exist in the project.
2+
3+
use std::path::Path;
4+
5+
use toml::Value;
6+
7+
pub fn check(path: &Path, bad: &mut bool) {
8+
let triagebot_path = path.join("triagebot.toml");
9+
if !triagebot_path.exists() {
10+
tidy_error!(bad, "triagebot.toml file not found");
11+
return;
12+
}
13+
14+
let contents = std::fs::read_to_string(&triagebot_path).unwrap();
15+
let config: Value = toml::from_str(&contents).unwrap();
16+
17+
// Check [mentions."*"] sections, i.e. [mentions."compiler/rustc_const_eval/src/"]
18+
if let Some(Value::Table(mentions)) = config.get("mentions") {
19+
for path_str in mentions.keys() {
20+
// Remove quotes from the path
21+
let clean_path = path_str.trim_matches('"');
22+
let full_path = path.join(clean_path);
23+
24+
if !full_path.exists() {
25+
tidy_error!(
26+
bad,
27+
"triagebot.toml [mentions.*] contains path '{}' which doesn't exist",
28+
clean_path
29+
);
30+
}
31+
}
32+
} else {
33+
tidy_error!(
34+
bad,
35+
"triagebot.toml missing [mentions.*] section, this wrong for rust-lang/rust repo."
36+
);
37+
}
38+
39+
// Check [assign.owners] sections, i.e.
40+
// [assign.owners]
41+
// "/.github/workflows" = ["infra-ci"]
42+
if let Some(Value::Table(assign)) = config.get("assign") {
43+
if let Some(Value::Table(owners)) = assign.get("owners") {
44+
for path_str in owners.keys() {
45+
// Remove quotes and leading slash from the path
46+
let clean_path = path_str.trim_matches('"').trim_start_matches('/');
47+
let full_path = path.join(clean_path);
48+
49+
if !full_path.exists() {
50+
tidy_error!(
51+
bad,
52+
"triagebot.toml [assign.owners] contains path '{}' which doesn't exist",
53+
clean_path
54+
);
55+
}
56+
}
57+
} else {
58+
tidy_error!(
59+
bad,
60+
"triagebot.toml missing [assign.owners] section, this wrong for rust-lang/rust repo."
61+
);
62+
}
63+
}
64+
65+
// Verify that trigger_files in [autolabel."*"] exist in the project, i.e.
66+
// [autolabel."A-rustdoc-search"]
67+
// trigger_files = [
68+
// "src/librustdoc/html/static/js/search.js",
69+
// "tests/rustdoc-js",
70+
// "tests/rustdoc-js-std",
71+
// ]
72+
if let Some(Value::Table(autolabels)) = config.get("autolabel") {
73+
for (label, content) in autolabels {
74+
if let Some(trigger_files) = content.get("trigger_files").and_then(|v| v.as_array()) {
75+
for file in trigger_files {
76+
if let Some(file_str) = file.as_str() {
77+
let full_path = path.join(file_str);
78+
79+
// Handle both file and directory paths
80+
if !full_path.exists() {
81+
tidy_error!(
82+
bad,
83+
"triagebot.toml [autolabel.{}] contains trigger_files path '{}' which doesn't exist",
84+
label,
85+
file_str
86+
);
87+
}
88+
}
89+
}
90+
}
91+
}
92+
}
93+
}

‎triagebot.toml

+5-11
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ trigger_files = [
253253
"compiler/rustc_passes/src/check_attr.rs",
254254
"compiler/rustc_attr_parsing",
255255
"compiler/rustc_attr_data_structures",
256-
"compiler/rustc_attr_validation",
257256
]
258257

259258
[autolabel."T-rustdoc-frontend"]
@@ -317,7 +316,6 @@ trigger_files = [
317316
"library/panic_unwind",
318317
"library/std",
319318
"library/stdarch",
320-
"library/term",
321319
"library/test",
322320
]
323321
exclude_labels = [
@@ -332,7 +330,7 @@ trigger_files = [
332330
[autolabel."O-apple"]
333331
trigger_files = [
334332
"library/std/src/os/darwin",
335-
"library/std/src/sys/pal/unix/thread_parking/darwin.rs",
333+
"library/std/src/sys/sync/thread_parking/darwin.rs",
336334
"compiler/rustc_target/src/spec/base/apple",
337335
]
338336

@@ -409,7 +407,8 @@ trigger_files = [
409407
[autolabel."O-wasm"]
410408
trigger_files = [
411409
"library/std/src/sys/pal/wasm",
412-
"library/std/src/os/wasm"
410+
"library/std/src/os/wasi",
411+
"library/std/src/os/wasip2"
413412
]
414413

415414
[autolabel."O-windows"]
@@ -500,7 +499,6 @@ trigger_files = [
500499
"CONTRIBUTING.md",
501500
"INSTALL.md",
502501
"REUSE.toml",
503-
".reuse",
504502
".mailmap",
505503
".git-blame-ignore-revs",
506504
".editorconfig"
@@ -525,7 +523,6 @@ exclude_labels = [
525523

526524
[autolabel."WG-trait-system-refactor"]
527525
trigger_files = [
528-
"compiler/rustc_middle/src/traits/solve",
529526
"compiler/rustc_next_trait_solver",
530527
"compiler/rustc_trait_selection/src/solve",
531528
"compiler/rustc_type_ir/src/solve",
@@ -795,7 +792,7 @@ cc = ["@Nadrieril"]
795792
message = "Some changes occurred in cfg and check-cfg configuration"
796793
cc = ["@Urgau"]
797794

798-
[mentions."compiler/rustc_lint/src/context/diagnostics/check_cfg.rs"]
795+
[mentions."compiler/rustc_lint/src/early/diagnostics/check_cfg.rs"]
799796
message = "Some changes occurred in check-cfg diagnostics"
800797
cc = ["@Urgau"]
801798

@@ -961,7 +958,7 @@ If appropriate, please update `CONFIG_CHANGE_HISTORY` in `src/bootstrap/src/util
961958
[mentions."src/bootstrap/src/core/build_steps/llvm.rs"]
962959
message = "This PR changes how LLVM is built. Consider updating src/bootstrap/download-ci-llvm-stamp."
963960

964-
[mentions."test/crashes"]
961+
[mentions."tests/crashes"]
965962
message = "This PR changes a file inside `tests/crashes`. If a crash was fixed, please move into the corresponding `ui` subdir and add 'Fixes #<issueNr>' to the PR description to autoclose the issue upon merge."
966963

967964
[mentions."tests/rustdoc-json"]
@@ -1075,8 +1072,6 @@ cc = ["@jdonszelmann"]
10751072
cc = ["@jdonszelmann"]
10761073
[mentions."compiler/rustc_attr_data_structures"]
10771074
cc = ["@jdonszelmann"]
1078-
[mentions."compiler/rustc_attr_validation"]
1079-
cc = ["@jdonszelmann"]
10801075

10811076
[assign]
10821077
warn_non_default_branch.enable = true
@@ -1265,7 +1260,6 @@ project-exploit-mitigations = [
12651260
"/compiler/rustc_middle/src/traits" = ["compiler", "types"]
12661261
"/compiler/rustc_middle/src/ty" = ["compiler", "types"]
12671262
"/compiler/rustc_const_eval/src/interpret" = ["compiler", "mir"]
1268-
"/compiler/rustc_const_eval/src/transform" = ["compiler", "mir-opt"]
12691263
"/compiler/rustc_mir_build/src/builder" = ["compiler", "mir"]
12701264
"/compiler/rustc_mir_transform" = ["compiler", "mir", "mir-opt"]
12711265
"/compiler/rustc_smir" = ["project-stable-mir"]

0 commit comments

Comments
 (0)