@@ -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 compile_flags = & directive[ COMPILE_FLAGS_HEADER . len ( ) ..] ;
35
39
if let Some ( ( _, v) ) = compile_flags. split_once ( "--target" ) {
36
40
let v = v. trim_start_matches ( |c| c == ' ' || c == '=' ) ;
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 ;
@@ -55,10 +60,12 @@ pub fn check(tests_path: &Path, bad: &mut bool) {
55
60
let rev = rev. unwrap_or ( "[unspecified]" ) ;
56
61
match ( target_arch, llvm_components) {
57
62
( None , None ) => { }
58
- ( Some ( _) , None ) => {
63
+ ( Some ( target_arch) , None ) => {
64
+ let llvm_component =
65
+ target_arch. map_or_else ( || "<arch>" . to_string ( ) , arch_to_llvm_component) ;
59
66
eprintln ! (
60
- "{}: revision {} should specify `{}` as it has `--target` set" ,
61
- file, rev, LLVM_COMPONENTS_HEADER
67
+ "{}: revision {} should specify `{} {} ` as it has `--target` set" ,
68
+ file, rev, LLVM_COMPONENTS_HEADER , llvm_component
62
69
) ;
63
70
* bad = true ;
64
71
}
@@ -69,11 +76,43 @@ pub fn check(tests_path: &Path, bad: &mut bool) {
69
76
) ;
70
77
* bad = true ;
71
78
}
72
- ( Some ( _) , Some ( _) ) => {
73
- // FIXME: check specified components against the target architectures we
74
- // gathered.
79
+ ( Some ( target_arch) , Some ( llvm_components) ) => {
80
+ if let Some ( target_arch) = target_arch {
81
+ let llvm_component = arch_to_llvm_component ( target_arch) ;
82
+ if !llvm_components. contains ( & llvm_component. as_str ( ) ) {
83
+ eprintln ! (
84
+ "{}: revision {} should specify `{} {}` as it has `--target` set" ,
85
+ file, rev, LLVM_COMPONENTS_HEADER , llvm_component
86
+ ) ;
87
+ * bad = true ;
88
+ }
89
+ }
75
90
}
76
91
}
77
92
}
78
93
} ) ;
79
94
}
95
+
96
+ fn arch_to_llvm_component ( arch : & str ) -> String {
97
+ match arch {
98
+ "amdgcn" => "amdgpu" . into ( ) ,
99
+ "aarch64_be" | "arm64_32" | "arm64e" | "arm64ec" => "aarch64" . into ( ) ,
100
+ "i386" | "i586" | "i686" | "x86" | "x86_64" | "x86_64h" => "x86" . into ( ) ,
101
+ "loongarch32" | "loongarch64" => "loongarch" . into ( ) ,
102
+ "nvptx64" => "nvptx" . into ( ) ,
103
+ "s390x" => "systemz" . into ( ) ,
104
+ "sparc64" | "sparcv9" => "sparc" . into ( ) ,
105
+ "wasm32" | "wasm32v1" | "wasm64" => "webassembly" . into ( ) ,
106
+ _ if arch. starts_with ( "armeb" )
107
+ || arch. starts_with ( "armv" )
108
+ || arch. starts_with ( "thumbv" ) =>
109
+ {
110
+ "arm" . into ( )
111
+ }
112
+ _ if arch. starts_with ( "bpfe" ) => "bpf" . into ( ) ,
113
+ _ if arch. starts_with ( "mips" ) => "mips" . into ( ) ,
114
+ _ if arch. starts_with ( "powerpc" ) => "powerpc" . into ( ) ,
115
+ _ if arch. starts_with ( "riscv" ) => "riscv" . into ( ) ,
116
+ _ => arch. to_ascii_lowercase ( ) ,
117
+ }
118
+ }
0 commit comments