|
| 1 | +//! Tests for target tier policy compliance. |
| 2 | +//! |
| 3 | +//! As of writing, only checks that sanity-check assembly test for targets doesn't miss any targets. |
| 4 | +
|
| 5 | +use crate::walk::{filter_not_rust, walk}; |
| 6 | +use std::{collections::HashSet, path::Path}; |
| 7 | + |
| 8 | +const TARGET_DEFINITIONS_PATH: &str = "compiler/rustc_target/src/spec/targets/"; |
| 9 | +const ASSEMBLY_TEST_PATH: &str = "tests/assembly/targets.rs"; |
| 10 | +const REVISION_LINE_START: &str = "// revisions: "; |
| 11 | + |
| 12 | +pub fn check(root_path: &Path, bad: &mut bool) { |
| 13 | + let mut targets_to_find = HashSet::new(); |
| 14 | + |
| 15 | + let definitions_path = root_path.join(TARGET_DEFINITIONS_PATH); |
| 16 | + for defn in ignore::WalkBuilder::new(&definitions_path) |
| 17 | + .max_depth(Some(1)) |
| 18 | + .filter_entry(|e| !filter_not_rust(e.path())) |
| 19 | + .build() |
| 20 | + { |
| 21 | + let defn = defn.unwrap(); |
| 22 | + // Skip directory itself. |
| 23 | + if defn.path() == definitions_path { |
| 24 | + continue; |
| 25 | + } |
| 26 | + |
| 27 | + let path = defn.path(); |
| 28 | + let target_name = path.file_stem().unwrap().to_string_lossy().into_owned(); |
| 29 | + let _ = targets_to_find.insert(target_name); |
| 30 | + } |
| 31 | + |
| 32 | + walk(&root_path.join(ASSEMBLY_TEST_PATH), |_, _| false, &mut |_, contents| { |
| 33 | + for line in contents.lines() { |
| 34 | + let Some(_) = line.find(REVISION_LINE_START) else { |
| 35 | + continue; |
| 36 | + }; |
| 37 | + let (_, target_name) = line.split_at(REVISION_LINE_START.len()); |
| 38 | + targets_to_find.remove(target_name); |
| 39 | + } |
| 40 | + }); |
| 41 | + |
| 42 | + for target in targets_to_find { |
| 43 | + tidy_error!(bad, "{ASSEMBLY_TEST_PATH}: missing assembly test for {target}") |
| 44 | + } |
| 45 | +} |
0 commit comments