Skip to content

Commit c86e523

Browse files
committed
compiletest: match ignores on target family
This primarily is so that `ignore-wasm` works as expected (ignores all wasm-like targets).
1 parent fab8996 commit c86e523

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/tools/compiletest/src/common.rs

+8
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,10 @@ impl Config {
411411
self.target_cfg().abi == abi
412412
}
413413

414+
pub fn matches_family(&self, family: &str) -> bool {
415+
self.target_cfg().families.iter().any(|f| f == family)
416+
}
417+
414418
pub fn is_big_endian(&self) -> bool {
415419
self.target_cfg().endian == Endian::Big
416420
}
@@ -436,6 +440,7 @@ pub struct TargetCfg {
436440
os: String,
437441
env: String,
438442
abi: String,
443+
families: Vec<String>,
439444
pointer_width: u32,
440445
endian: Endian,
441446
}
@@ -470,6 +475,7 @@ impl TargetCfg {
470475
let mut os = None;
471476
let mut env = None;
472477
let mut abi = None;
478+
let mut families = Vec::new();
473479
let mut pointer_width = None;
474480
let mut endian = None;
475481
for line in print_cfg.lines() {
@@ -480,6 +486,7 @@ impl TargetCfg {
480486
"target_os" => os = Some(value),
481487
"target_env" => env = Some(value),
482488
"target_abi" => abi = Some(value),
489+
"target_family" => families.push(value.to_string()),
483490
"target_pointer_width" => pointer_width = Some(value.parse().unwrap()),
484491
"target_endian" => {
485492
endian = Some(match value {
@@ -497,6 +504,7 @@ impl TargetCfg {
497504
os: os.unwrap().to_string(),
498505
env: env.unwrap().to_string(),
499506
abi: abi.unwrap().to_string(),
507+
families,
500508
pointer_width: pointer_width.unwrap(),
501509
endian: endian.unwrap(),
502510
}

src/tools/compiletest/src/header.rs

+1
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ impl Config {
682682
self.matches_os(name) ||
683683
self.matches_env(name) ||
684684
self.matches_abi(name) ||
685+
self.matches_family(name) ||
685686
self.target.ends_with(name) || // target and env
686687
self.matches_arch(name) ||
687688
matches_wasm32_alias() ||

src/tools/compiletest/src/header/tests.rs

+20
Original file line numberDiff line numberDiff line change
@@ -421,3 +421,23 @@ fn wasm_special() {
421421
);
422422
}
423423
}
424+
425+
#[test]
426+
fn families() {
427+
let families = [
428+
("x86_64-unknown-linux-gnu", "unix"),
429+
("x86_64-pc-windows-gnu", "windows"),
430+
("wasm32-unknown-unknown", "wasm"),
431+
("wasm32-unknown-emscripten", "wasm"),
432+
("wasm32-unknown-emscripten", "unix"),
433+
];
434+
for (target, family) in families {
435+
let mut config = config();
436+
config.target = target.to_string();
437+
assert!(config.matches_family(family));
438+
let other = if family == "windows" { "unix" } else { "windows" };
439+
assert!(!config.matches_family(other));
440+
assert!(check_ignore(&config, &format!("// ignore-{family}")));
441+
assert!(!check_ignore(&config, &format!("// ignore-{other}")));
442+
}
443+
}

0 commit comments

Comments
 (0)