From 014be6f2537db23c7d9b8511ed6bafb03df14e9b Mon Sep 17 00:00:00 2001 From: "Arvid E. Picciani" Date: Mon, 20 Jul 2020 13:02:55 +0200 Subject: [PATCH] remove features using c conditionals is more consistent, and the variants never really worked anyway across library boundaries --- src/lib.rs | 14 ------------- src/loader.rs | 3 +-- src/make.rs | 23 ++++----------------- src/makro.rs | 2 +- src/parser.rs | 44 +++++++++++++++++++--------------------- src/project.rs | 54 +------------------------------------------------- 6 files changed, 27 insertions(+), 113 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c280a4d..1863e33 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -81,18 +81,12 @@ pub fn build(buildset: BuildSet, variant: &str, stage: make::Stage, _slow: bool) ]); let mut modules = HashMap::new(); - let features = project - .features(variant) - .into_iter() - .map(|(n, (e, _))| (n, e)) - .collect(); if root.join("src").exists() { loader::load( &mut modules, &project.project, &project_name, &root.join("src"), - &features, &stage, ); } @@ -102,7 +96,6 @@ pub fn build(buildset: BuildSet, variant: &str, stage: make::Stage, _slow: bool) &project.project, &project_tests_name, &root.join("tests").canonicalize().unwrap(), - &features, &stage, ); } @@ -197,17 +190,11 @@ fn getdep( let (root, project) = project::load(&found); let project_name = Name(vec![String::new(), project.project.name.clone()]); if found.join("src").exists() { - let features = project - .features("default") - .into_iter() - .map(|(n, (e, _))| (n, e)) - .collect(); loader::load( modules, &project.project, &project_name, &found.join("src"), - &features, &stage, ); } @@ -238,7 +225,6 @@ fn getdep( rootproj.pkgconfig.push(i.to_string_lossy().into()); } rootproj.cflags.extend(project.project.cflags); - rootproj.lflags.extend(project.project.lflags); if let Some(deps) = &project.dependencies { for (name, dep) in deps { diff --git a/src/loader.rs b/src/loader.rs index 76e3b75..8c02a42 100644 --- a/src/loader.rs +++ b/src/loader.rs @@ -22,7 +22,6 @@ pub fn load( project: &super::project::Project, artifact_name: &Name, src: &Path, - features: &HashMap, stage: &Stage, ) { let mut files = Vec::new(); @@ -93,7 +92,7 @@ pub fn load( if !silent { pb.lock().unwrap().message(&format!("parsing {:?} ", path)); } - let mut m = parser::parse(&path, features, stage); + let mut m = parser::parse(&path, stage); m.name = module_name; debug!("loaded {:?} as {}", path, m.name); diff --git a/src/make.rs b/src/make.rs index 413b528..14c45cc 100644 --- a/src/make.rs +++ b/src/make.rs @@ -129,8 +129,6 @@ pub struct Make { impl Make { pub fn new(mut config: Config, variant: &str, stage: Stage, artifact: Artifact) -> Self { - let features = config.features(variant); - let mut cflags: Vec = match std::env::var("TARGET_CFLAGS").or(std::env::var("CFLAGS")) { Err(_) => Vec::new(), @@ -170,22 +168,10 @@ impl Make { cxx = "afl-clang++".to_string(); } - let mut cincludes = config.project.cincludes.clone(); - let mut pkgconfig = config.project.pkgconfig.clone(); - let mut cobjects = std::mem::replace(&mut config.project.cobjects, Vec::new()); - let mut user_cflags = config.project.cflags.clone(); - let mut user_lflags = config.project.lflags.clone(); - - for (_, (enabled, feature)) in &features { - if !enabled { - continue; - } - cincludes.extend(feature.cincludes.clone()); - pkgconfig.extend(feature.pkgconfig.clone()); - cobjects.extend(feature.cobjects.clone()); - user_cflags.extend(feature.cflags.clone()); - user_lflags.extend(feature.lflags.clone()); - } + let cincludes = config.project.cincludes.clone(); + let pkgconfig = config.project.pkgconfig.clone(); + let cobjects = std::mem::replace(&mut config.project.cobjects, Vec::new()); + let user_cflags = config.project.cflags.clone(); for cinc in &cincludes { cflags.push("-I".into()); @@ -223,7 +209,6 @@ impl Make { cflags.push("-fvisibility=hidden".to_string()); cflags.extend(user_cflags); - lflags.extend(user_lflags); let mut stage = stage.clone(); if let Ok(_) = std::env::var("ZZ_BUILD_NO_PIC") { diff --git a/src/makro.rs b/src/makro.rs index cdf7a57..326aa2f 100644 --- a/src/makro.rs +++ b/src/makro.rs @@ -138,7 +138,7 @@ pub fn stm( None => break, Some(v) => v, }; - for stm2 in parser::parse_block(&path, &HashMap::new(), &super::make::Stage::release(), pp) + for stm2 in parser::parse_block(&path, &super::make::Stage::release(), pp) .statements { statements.push(stm2); diff --git a/src/parser.rs b/src/parser.rs index e882218..1621af8 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -13,8 +13,8 @@ pub struct ZZParser; pub static ERRORS_AS_JSON: AtomicBool = AtomicBool::new(false); -pub fn parse(n: &Path, features: &HashMap, stage: &Stage) -> Module { - match p(&n, features, stage) { +pub fn parse(n: &Path, stage: &Stage) -> Module { + match p(&n, stage) { Err(e) => { let e = e.with_path(&n.to_string_lossy().to_string()); if ERRORS_AS_JSON.load(Ordering::SeqCst) { @@ -49,7 +49,6 @@ pub fn parse(n: &Path, features: &HashMap, stage: &Stage) -> Modul fn p( n: &Path, - features: &HashMap, stage: &Stage, ) -> Result> { let mut module = Module::default(); @@ -101,7 +100,7 @@ fn p( } } Rule::block if body.is_none() => { - body = Some(parse_block(&n, features, stage, part)); + body = Some(parse_block(&n, stage, part)); } e => panic!("unexpected rule {:?} in macro ", e), } @@ -205,20 +204,20 @@ fn p( let part = stm.next().unwrap(); let expr = parse_expr(n, part); let part = stm.next().unwrap(); - let body2 = parse_block(n, features, stage, part); + let body2 = parse_block(n, stage, part); body.branches.push((loc.clone(), Some(expr), body2)); } Rule::else_stm => { let mut stm = branch.into_inner(); let part = stm.next().unwrap(); - let body2 = parse_block(n, features, stage, part); + let body2 = parse_block(n, stage, part); body.branches.push((loc.clone(), None, body2)); } Rule::block => { body.branches = vec![( loc.clone(), None, - parse_block(n, features, stage, branch), + parse_block(n, stage, branch), )]; } e => panic!("unexpected rule {:?} in gblock", e), @@ -657,20 +656,20 @@ fn p( let part = stm.next().unwrap(); let expr = parse_expr(n, part); let part = stm.next().unwrap(); - let body2 = parse_block(n, features, stage, part); + let body2 = parse_block(n, stage, part); body.branches.push((loc.clone(), Some(expr), body2)); } Rule::else_stm => { let mut stm = branch.into_inner(); let part = stm.next().unwrap(); - let body2 = parse_block(n, features, stage, part); + let body2 = parse_block(n, stage, part); body.branches.push((loc.clone(), None, body2)); } Rule::block => { body.branches = vec![( loc.clone(), None, - parse_block(n, features, stage, branch), + parse_block(n, stage, branch), )]; } e => panic!("unexpected rule {:?} in gblock", e), @@ -1102,7 +1101,6 @@ pub(crate) fn parse_expr_inner(n: &str, expr: pest::iterators::Pair<'static, Rul pub(crate) fn parse_statement( n: &str, - features: &HashMap, stage: &Stage, stm: pest::iterators::Pair<'static, Rule>, into: &mut Vec>, @@ -1141,7 +1139,7 @@ pub(crate) fn parse_statement( into.push(Box::new(Statement::Break { loc })); } Rule::block => into.push(Box::new(Statement::Block(Box::new(parse_block( - n, features, stage, stm, + n, stage, stm, ))))), Rule::return_stm => { let mut stm = stm.into_inner(); @@ -1174,7 +1172,7 @@ pub(crate) fn parse_statement( let part = stm.next().unwrap(); let expr = parse_expr(n, part); let part = stm.next().unwrap(); - let body = parse_block(n, features, stage, part); + let body = parse_block(n, stage, part); into.push(Box::new(Statement::While { expr, body })); } Rule::if_stm => { @@ -1182,7 +1180,7 @@ pub(crate) fn parse_statement( let part = stm.next().unwrap(); let expr = parse_expr(n, part); let part = stm.next().unwrap(); - let body = parse_block(n, features, stage, part); + let body = parse_block(n, stage, part); *current_if_statement = Some(into.len()); into.push(Box::new(Statement::If { branches: vec![(loc.clone(), Some(expr), body)], @@ -1193,7 +1191,7 @@ pub(crate) fn parse_statement( let part = stm.next().unwrap(); let expr = parse_expr(n, part); let part = stm.next().unwrap(); - let body = parse_block(n, features, stage, part); + let body = parse_block(n, stage, part); match *current_if_statement { None => { emit_error( @@ -1215,7 +1213,7 @@ pub(crate) fn parse_statement( Rule::else_stm => { let mut stm = stm.into_inner(); let part = stm.next().unwrap(); - let body = parse_block(n, features, stage, part); + let body = parse_block(n, stage, part); match *current_if_statement { None => { emit_error( @@ -1251,18 +1249,18 @@ pub(crate) fn parse_statement( cur += 1; } Rule::block if cur == 3 && block.is_none() => { - block = Some(parse_block(n, features, stage, part)); + block = Some(parse_block(n, stage, part)); } _ if cur == 1 => { let mut cif = None; - parse_statement(n, features, stage, part, &mut expr1, &mut cif); + parse_statement(n, stage, part, &mut expr1, &mut cif); } _ if cur == 2 => { expr2 = Some(parse_expr(n, part)); } _ if cur == 3 => { let mut cif = None; - parse_statement(n, features, stage, part, &mut expr3, &mut cif); + parse_statement(n, stage, part, &mut expr3, &mut cif); } e => panic!("unexpected rule {:?} in for ", e), } @@ -1367,7 +1365,7 @@ pub(crate) fn parse_statement( emit_error("multiple default cases", &[(loc.clone(), "in this switch")]); std::process::exit(9); } else { - default = Some(parse_block(n, features, stage, part.next().unwrap())); + default = Some(parse_block(n, stage, part.next().unwrap())); } } else { let mut case_cond = Vec::new(); @@ -1375,7 +1373,7 @@ pub(crate) fn parse_statement( case_cond.push(parse_expr(n, case)); } - let block = parse_block(n, features, stage, part.next().unwrap()); + let block = parse_block(n, stage, part.next().unwrap()); cases.push((case_cond, block)); } } @@ -1390,7 +1388,6 @@ pub(crate) fn parse_statement( Rule::unsafe_block => { into.push(Box::new(Statement::Unsafe(Box::new(parse_block( n, - features, stage, stm.into_inner().next().unwrap(), ))))); @@ -1423,7 +1420,6 @@ pub(crate) fn parse_statement( pub(crate) fn parse_block( n: &str, - features: &HashMap, stage: &Stage, decl: pest::iterators::Pair<'static, Rule>, ) -> Block { @@ -1445,7 +1441,7 @@ pub(crate) fn parse_block( let mut statements = Vec::new(); let mut cif_state = None; for stm in decl.into_inner() { - parse_statement(n, features, stage, stm, &mut statements, &mut cif_state) + parse_statement(n, stage, stm, &mut statements, &mut cif_state) } Block { statements, diff --git a/src/project.rs b/src/project.rs index 1f814a9..d031f13 100644 --- a/src/project.rs +++ b/src/project.rs @@ -67,8 +67,6 @@ pub struct Feature { pub pkgconfig: Vec, #[serde(default)] pub cflags: Vec, - #[serde(default)] - pub lflags: Vec, } #[derive(Clone, Default, Serialize, Deserialize)] @@ -85,8 +83,6 @@ pub struct Project { pub pkgconfig: Vec, #[serde(default)] pub cflags: Vec, - #[serde(default)] - pub lflags: Vec, } #[derive(Serialize, Deserialize)] @@ -99,10 +95,6 @@ pub struct Config { pub project: Project, pub artifacts: Option>, - pub features: Option>, - #[serde(default)] - pub variants: HashMap>, - pub dependencies: Option>, #[serde(default)] @@ -114,7 +106,7 @@ pub fn init() { dependencies.insert("log".into(), "1".into()); dependencies.insert("mem".into(), "1".into()); - let mut c = Config { + let c = Config { artifacts: None, project: Project { name: std::env::current_dir() @@ -127,11 +119,8 @@ pub fn init() { ..Default::default() }, dependencies: Some(dependencies), - features: None, - variants: HashMap::new(), repos: HashMap::new(), }; - c.variants.insert("default".to_string(), Vec::new()); if !std::env::current_dir().unwrap().join("zz.toml").exists() { let s = toml::to_string(&c).unwrap(); @@ -253,24 +242,6 @@ pub fn load(search: &std::path::Path) -> (PathBuf, Config) { } } - // implicit features - if !c.variants.contains_key("default") { - c.variants.insert("default".to_string(), Default::default()); - } - for (_, features) in &c.variants { - for f in features { - if c.features.is_none() { - c.features = Some(HashMap::new()); - } - if !c.features.as_mut().unwrap().contains_key(f) { - c.features - .as_mut() - .unwrap() - .insert(f.to_string(), Default::default()); - } - } - } - if c.artifacts.is_none() { let mut a = Vec::new(); if search.join("./src/main.zz").exists() { @@ -319,26 +290,3 @@ pub fn load(search: &std::path::Path) -> (PathBuf, Config) { (search.into(), c) } - -impl Config { - pub fn features(&self, variant: &str) -> HashMap { - match self.variants.get(variant) { - None => { - error!("variant {} not defined", variant); - std::process::exit(9); - } - Some(v) => { - let mut r = HashMap::new(); - if let Some(features) = &self.features { - for (n, feature) in features { - r.insert(n.to_string(), (false, feature.clone())); - } - } - for v in v { - r.get_mut(v).unwrap().0 = true; - } - r - } - } - } -}