@@ -12,12 +12,16 @@ const COMPILE_FLAGS_HEADER: &str = "compile-flags:";
12
12
13
13
#[ derive( Default , Debug ) ]
14
14
struct RevisionInfo < ' a > {
15
- target_arch : Option < & ' a str > ,
15
+ target_arch : Option < Option < & ' a str > > ,
16
16
llvm_components : Option < Vec < & ' a str > > ,
17
17
}
18
18
19
19
pub fn check ( tests_path : & Path , bad : & mut bool ) {
20
20
crate :: walk:: walk ( tests_path, |path, _is_dir| filter_not_rust ( path) , & mut |entry, content| {
21
+ if content. contains ( "// ignore-tidy-target-specific-tests" ) {
22
+ return ;
23
+ }
24
+
21
25
let file = entry. path ( ) . display ( ) ;
22
26
let mut header_map = BTreeMap :: new ( ) ;
23
27
iter_header ( content, & mut |HeaderLine { revision, directive, .. } | {
@@ -34,10 +38,11 @@ pub fn check(tests_path: &Path, bad: &mut bool) {
34
38
&& let Some ( ( _, v) ) = compile_flags. split_once ( "--target" )
35
39
{
36
40
let v = v. trim_start_matches ( [ ' ' , '=' ] ) ;
37
- let v = if v == "{{target}}" { Some ( ( v, v) ) } else { v. split_once ( "-" ) } ;
38
- if let Some ( ( arch, _) ) = v {
39
- let info = header_map. entry ( revision) . or_insert ( RevisionInfo :: default ( ) ) ;
40
- info. target_arch . replace ( arch) ;
41
+ let info = header_map. entry ( revision) . or_insert ( RevisionInfo :: default ( ) ) ;
42
+ if v. starts_with ( "{{" ) {
43
+ info. target_arch . replace ( None ) ;
44
+ } else if let Some ( ( arch, _) ) = v. split_once ( "-" ) {
45
+ info. target_arch . replace ( Some ( arch) ) ;
41
46
} else {
42
47
eprintln ! ( "{file}: seems to have a malformed --target value" ) ;
43
48
* bad = true ;
@@ -54,9 +59,11 @@ pub fn check(tests_path: &Path, bad: &mut bool) {
54
59
let rev = rev. unwrap_or ( "[unspecified]" ) ;
55
60
match ( target_arch, llvm_components) {
56
61
( None , None ) => { }
57
- ( Some ( _) , None ) => {
62
+ ( Some ( target_arch) , None ) => {
63
+ let llvm_component =
64
+ target_arch. map_or_else ( || "<arch>" . to_string ( ) , arch_to_llvm_component) ;
58
65
eprintln ! (
59
- "{file}: revision {rev} should specify `{LLVM_COMPONENTS_HEADER}` as it has `--target` set"
66
+ "{file}: revision {rev} should specify `{LLVM_COMPONENTS_HEADER} {llvm_component} ` as it has `--target` set"
60
67
) ;
61
68
* bad = true ;
62
69
}
@@ -66,11 +73,45 @@ pub fn check(tests_path: &Path, bad: &mut bool) {
66
73
) ;
67
74
* bad = true ;
68
75
}
69
- ( Some ( _) , Some ( _) ) => {
70
- // FIXME: check specified components against the target architectures we
71
- // gathered.
76
+ ( Some ( target_arch) , Some ( llvm_components) ) => {
77
+ if let Some ( target_arch) = target_arch {
78
+ let llvm_component = arch_to_llvm_component ( target_arch) ;
79
+ if !llvm_components. contains ( & llvm_component. as_str ( ) ) {
80
+ eprintln ! (
81
+ "{file}: revision {rev} should specify `{LLVM_COMPONENTS_HEADER} {llvm_component}` as it has `--target` set"
82
+ ) ;
83
+ * bad = true ;
84
+ }
85
+ }
72
86
}
73
87
}
74
88
}
75
89
} ) ;
76
90
}
91
+
92
+ fn arch_to_llvm_component ( arch : & str ) -> String {
93
+ // NOTE: This is an *approximate* mapping of Rust's `--target` architecture to LLVM component
94
+ // names. It is not intended to be an authoritative source, but rather a best-effort that's good
95
+ // enough for the purpose of this tidy check.
96
+ match arch {
97
+ "amdgcn" => "amdgpu" . into ( ) ,
98
+ "aarch64_be" | "arm64_32" | "arm64e" | "arm64ec" => "aarch64" . into ( ) ,
99
+ "i386" | "i586" | "i686" | "x86" | "x86_64" | "x86_64h" => "x86" . into ( ) ,
100
+ "loongarch32" | "loongarch64" => "loongarch" . into ( ) ,
101
+ "nvptx64" => "nvptx" . into ( ) ,
102
+ "s390x" => "systemz" . into ( ) ,
103
+ "sparc64" | "sparcv9" => "sparc" . into ( ) ,
104
+ "wasm32" | "wasm32v1" | "wasm64" => "webassembly" . into ( ) ,
105
+ _ if arch. starts_with ( "armeb" )
106
+ || arch. starts_with ( "armv" )
107
+ || arch. starts_with ( "thumbv" ) =>
108
+ {
109
+ "arm" . into ( )
110
+ }
111
+ _ if arch. starts_with ( "bpfe" ) => "bpf" . into ( ) ,
112
+ _ if arch. starts_with ( "mips" ) => "mips" . into ( ) ,
113
+ _ if arch. starts_with ( "powerpc" ) => "powerpc" . into ( ) ,
114
+ _ if arch. starts_with ( "riscv" ) => "riscv" . into ( ) ,
115
+ _ => arch. to_ascii_lowercase ( ) ,
116
+ }
117
+ }
0 commit comments