Skip to content

Instantly share code, notes, and snippets.

@LnL7
Last active April 29, 2020 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LnL7/27a567cd2b3162a21cbd0499c6fa0f71 to your computer and use it in GitHub Desktop.
Save LnL7/27a567cd2b3162a21cbd0499c6fa0f71 to your computer and use it in GitHub Desktop.
Carnix patches for Ofborg
diff --git a/src/cfg.rs b/src/cfg.rs
index 56f76a0..e4b9b44 100644
--- a/src/cfg.rs
+++ b/src/cfg.rs
@@ -49,12 +49,16 @@ fn to_nix_op(w: &mut Write, op: CfgOp, target: &[Cfg]) -> Result<(), Error> {
}
is_first = false;
match *cfg {
- Cfg::Op { op, ref operands } => to_nix_op(w, op, operands)?,
+ Cfg::Op { op, ref operands } => {
+ write!(w, "(")?;
+ to_nix_op(w, op, operands)?;
+ write!(w, ")")?;
+ },
Cfg::Not(ref cfg) => {
write!(w, "!(")?;
to_nix_op(w, CfgOp::All, cfg)?;
write!(w, ")")?;
- }
+ },
Cfg::Equal(ref key, ref value) => {
match key.as_str() {
"target_os" => cfg_value(w, "kernel", value)?,
@@ -121,7 +125,35 @@ fn test_cfg() {
// let s = "cfg(target_os=\"em\")";
let x = cfg(s.as_bytes());
if let IResult::Done(ref i, ref o) = x {
- println!("{:?}", o);
+ let mut v = vec![];
+ to_nix(&mut v, &o).unwrap();
+ assert_eq!(String::from_utf8(v).unwrap(), r#"((kernel == "linux" || kernel == "darwin") && !(kernel == "emscripten") && !(kernel == "darwin") && !(kernel == "ios"))"#);
+ } else {
+ panic!("{:?}", x)
+ }
+}
+
+#[test]
+fn test_any() {
+ let s = "cfg(any(unix, windows))";
+ let x = cfg(s.as_bytes());
+ if let IResult::Done(ref i, ref o) = x {
+ let mut v = vec![];
+ to_nix(&mut v, &o).unwrap();
+ assert_eq!(String::from_utf8(v).unwrap(), r#"((kernel == "linux" || kernel == "darwin") || kernel == "windows")"#);
+ } else {
+ panic!("{:?}", x)
+ }
+}
+
+#[test]
+fn test_precedence() {
+ let s = r#"cfg(all(any(target_arch = "x86_64", target_arch = "aarch64"), target_os = "hermit"))"#;
+ let x = cfg(s.as_bytes());
+ if let IResult::Done(ref i, ref o) = x {
+ let mut v = vec![];
+ to_nix(&mut v, &o).unwrap();
+ assert_eq!(String::from_utf8(v).unwrap(), r#"((cpu == "x86_64" || cpu == "aarch64") && kernel == "hermit")"#);
} else {
panic!("{:?}", x)
}
diff --git a/src/output.rs b/src/output.rs
index 2487b37..bd32054 100644
--- a/src/output.rs
+++ b/src/output.rs
@@ -1041,7 +1041,13 @@ impl Crate {
if let Ok(fsmeta) = std::fs::metadata(&path_canon) {
debug!("fsmeta = {:?}", fsmeta);
if fsmeta.is_dir() {
- if let Some(ref include) = meta.include {
+ if let Some(ref ws) = workspace_member {
+ // Existing includes should be relative to the workspace, but that's
+ // not supported at the moment.
+ filter_source.push_str("include [ \"Cargo.toml\" \"");
+ filter_source.push_str(&ws.to_string_lossy());
+ filter_source.push_str("\" ] ");
+ } else if let Some(ref include) = meta.include {
filter_source.push_str("include [ ");
for file in include.iter() {
filter_source.push_str("\"");
@@ -1050,10 +1056,6 @@ impl Crate {
filter_source.push_str(" ");
}
filter_source.push_str("] ");
- } else if let Some(ref ws) = workspace_member {
- filter_source.push_str("include [ \"Cargo.toml\" \" ");
- filter_source.push_str(&ws.to_string_lossy());
- filter_source.push_str("\" ] ");
} else {
filter_source.push_str("exclude [ \".git\" \"target\" ] ");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment