1use std::collections::HashSet;
6use std::path::Path;
7
8use crate::diagnostics::DiagCtx;
9use crate::walk::{filter_not_rust, walk};
10
11const TARGET_DEFINITIONS_PATH: &str = "compiler/rustc_target/src/spec/targets/";
12const ASSEMBLY_LLVM_TEST_PATH: &str = "tests/assembly-llvm/targets/";
13const REVISION_LINE_START: &str = "//@ revisions: ";
14const EXCEPTIONS: &[&str] = &[
15 "csky_unknown_linux_gnuabiv2",
17 "csky_unknown_linux_gnuabiv2hf",
18 "xtensa_esp32_none_elf",
20 "xtensa_esp32_espidf",
21 "xtensa_esp32s2_none_elf",
22 "xtensa_esp32s2_espidf",
23 "xtensa_esp32s3_none_elf",
24 "xtensa_esp32s3_espidf",
25];
26
27pub fn check(root_path: &Path, diag_ctx: DiagCtx) {
28 let mut check = diag_ctx.start_check("target_policy");
29
30 let mut targets_to_find = HashSet::new();
31
32 let definitions_path = root_path.join(TARGET_DEFINITIONS_PATH);
33 for defn in ignore::WalkBuilder::new(&definitions_path)
34 .max_depth(Some(1))
35 .filter_entry(|e| !filter_not_rust(e.path()))
36 .build()
37 {
38 let defn = defn.unwrap();
39 if defn.path() == definitions_path {
41 continue;
42 }
43
44 let path = defn.path();
45 let target_name = path.file_stem().unwrap().to_string_lossy().into_owned();
46 let _ = targets_to_find.insert(target_name);
47 }
48
49 walk(&root_path.join(ASSEMBLY_LLVM_TEST_PATH), |_, _| false, &mut |_, contents| {
50 for line in contents.lines() {
51 let Some(_) = line.find(REVISION_LINE_START) else {
52 continue;
53 };
54 let (_, target_name) = line.split_at(REVISION_LINE_START.len());
55 targets_to_find.remove(target_name);
56 }
57 });
58
59 for target in targets_to_find {
60 if !EXCEPTIONS.contains(&target.as_str()) {
61 check.error(format!("{ASSEMBLY_LLVM_TEST_PATH}: missing assembly test for {target}"));
62 }
63 }
64}