@@ -12,12 +12,16 @@ const COMPILE_FLAGS_HEADER: &str = "compile-flags:";
1212
1313#[ derive( Default , Debug ) ]
1414struct RevisionInfo < ' a > {
15- target_arch : Option < & ' a str > ,
15+ target_arch : Option < Option < & ' a str > > ,
1616 llvm_components : Option < Vec < & ' a str > > ,
1717}
1818
1919pub fn check ( tests_path : & Path , bad : & mut bool ) {
2020 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+
2125 let file = entry. path ( ) . display ( ) ;
2226 let mut header_map = BTreeMap :: new ( ) ;
2327 iter_header ( content, & mut |HeaderLine { revision, directive, .. } | {
@@ -34,10 +38,11 @@ pub fn check(tests_path: &Path, bad: &mut bool) {
3438 let compile_flags = & directive[ COMPILE_FLAGS_HEADER . len ( ) ..] ;
3539 if let Some ( ( _, v) ) = compile_flags. split_once ( "--target" ) {
3640 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) ) ;
4146 } else {
4247 eprintln ! ( "{file}: seems to have a malformed --target value" ) ;
4348 * bad = true ;
@@ -55,10 +60,12 @@ pub fn check(tests_path: &Path, bad: &mut bool) {
5560 let rev = rev. unwrap_or ( "[unspecified]" ) ;
5661 match ( target_arch, llvm_components) {
5762 ( 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) ;
5966 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
6269 ) ;
6370 * bad = true ;
6471 }
@@ -69,11 +76,43 @@ pub fn check(tests_path: &Path, bad: &mut bool) {
6976 ) ;
7077 * bad = true ;
7178 }
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+ }
7590 }
7691 }
7792 }
7893 } ) ;
7994}
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