1
Fork 0

compiletest: match ignores on target family

This primarily is so that `ignore-wasm` works as expected (ignores all wasm-like targets).
This commit is contained in:
Eric Huss 2022-08-07 21:44:23 -07:00
parent fab8996400
commit c86e523d97
3 changed files with 29 additions and 0 deletions

View file

@ -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
}
@ -436,6 +440,7 @@ pub struct TargetCfg {
os: String,
env: String,
abi: String,
families: Vec<String>,
pointer_width: u32,
endian: Endian,
}
@ -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() {
@ -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 {
@ -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(),
}

View file

@ -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() ||

View file

@ -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}")));
}
}