Skip to content

Commit

Permalink
Fix target_os = "none" parsing (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshowers authored Jun 19, 2023
1 parent 960f370 commit ab22574
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ impl TargetMatcher for targ::TargetInfo {
},
Family(fam) => self.families.contains(fam),
HasAtomic(has_atomic) => self.has_atomics.contains(*has_atomic),
Os(os) => Some(os) == self.os.as_ref(),
Os(os) => match &self.os {
Some(self_os) => os == self_os,
// os = "none" means it should be matched against None. Note that this is different
// from "env" above.
None => os.as_str() == "none",
},
PointerWidth(w) => *w == self.pointer_width,
Vendor(ven) => match &self.vendor {
Some(v) => ven == v,
Expand Down
6 changes: 6 additions & 0 deletions tests/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ fn complex() {
// Should *not* match x86_64 windows or android
assert!(!complex.eval(|pred| tg_match!(pred, windows_msvc)));
assert!(!complex.eval(|pred| tg_match!(pred, android)));

// Ensure that target_os = "none" matches against Os == None.
let complex = Expression::parse(r#"all(target_os="none")"#).unwrap();
let armebv7r_none_eabi = Target::make("armebv7r-none-eabi");
assert!(!complex.eval(|pred| tg_match!(pred, linux_gnu)));
assert!(complex.eval(|pred| tg_match!(pred, armebv7r_none_eabi)));
}

#[test]
Expand Down

0 comments on commit ab22574

Please sign in to comment.