Skip to content

Commit

Permalink
compiletest: match ignores on target family
Browse files Browse the repository at this point in the history
This primarily is so that `ignore-wasm` works as expected (ignores all wasm-like targets).
  • Loading branch information
ehuss committed Aug 8, 2022
1 parent fab8996 commit c86e523
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/tools/compiletest/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ impl Config {
self.target_cfg().abi == abi
}

pub fn matches_family(&self, family: &str) -> bool {
self.target_cfg().families.iter().any(|f| f == family)
}

pub fn is_big_endian(&self) -> bool {
self.target_cfg().endian == Endian::Big
}
Expand All @@ -436,6 +440,7 @@ pub struct TargetCfg {
os: String,
env: String,
abi: String,
families: Vec<String>,
pointer_width: u32,
endian: Endian,
}
Expand Down Expand Up @@ -470,6 +475,7 @@ impl TargetCfg {
let mut os = None;
let mut env = None;
let mut abi = None;
let mut families = Vec::new();
let mut pointer_width = None;
let mut endian = None;
for line in print_cfg.lines() {
Expand All @@ -480,6 +486,7 @@ impl TargetCfg {
"target_os" => os = Some(value),
"target_env" => env = Some(value),
"target_abi" => abi = Some(value),
"target_family" => families.push(value.to_string()),
"target_pointer_width" => pointer_width = Some(value.parse().unwrap()),
"target_endian" => {
endian = Some(match value {
Expand All @@ -497,6 +504,7 @@ impl TargetCfg {
os: os.unwrap().to_string(),
env: env.unwrap().to_string(),
abi: abi.unwrap().to_string(),
families,
pointer_width: pointer_width.unwrap(),
endian: endian.unwrap(),
}
Expand Down
1 change: 1 addition & 0 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ impl Config {
self.matches_os(name) ||
self.matches_env(name) ||
self.matches_abi(name) ||
self.matches_family(name) ||
self.target.ends_with(name) || // target and env
self.matches_arch(name) ||
matches_wasm32_alias() ||
Expand Down
20 changes: 20 additions & 0 deletions src/tools/compiletest/src/header/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,23 @@ fn wasm_special() {
);
}
}

#[test]
fn families() {
let families = [
("x86_64-unknown-linux-gnu", "unix"),
("x86_64-pc-windows-gnu", "windows"),
("wasm32-unknown-unknown", "wasm"),
("wasm32-unknown-emscripten", "wasm"),
("wasm32-unknown-emscripten", "unix"),
];
for (target, family) in families {
let mut config = config();
config.target = target.to_string();
assert!(config.matches_family(family));
let other = if family == "windows" { "unix" } else { "windows" };
assert!(!config.matches_family(other));
assert!(check_ignore(&config, &format!("// ignore-{family}")));
assert!(!check_ignore(&config, &format!("// ignore-{other}")));
}
}

0 comments on commit c86e523

Please # to comment.