Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
remove features
Browse files Browse the repository at this point in the history
using c conditionals is more consistent,
and the variants never really worked anyway across library boundaries
  • Loading branch information
aep committed Jul 20, 2020
1 parent e37b09f commit 014be6f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 113 deletions.
14 changes: 0 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
Expand All @@ -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,
);
}
Expand Down Expand Up @@ -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,
);
}
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub fn load(
project: &super::project::Project,
artifact_name: &Name,
src: &Path,
features: &HashMap<String, bool>,
stage: &Stage,
) {
let mut files = Vec::new();
Expand Down Expand Up @@ -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);
Expand Down
23 changes: 4 additions & 19 deletions src/make.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> =
match std::env::var("TARGET_CFLAGS").or(std::env::var("CFLAGS")) {
Err(_) => Vec::new(),
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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") {
Expand Down
2 changes: 1 addition & 1 deletion src/makro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
44 changes: 20 additions & 24 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub struct ZZParser;

pub static ERRORS_AS_JSON: AtomicBool = AtomicBool::new(false);

pub fn parse(n: &Path, features: &HashMap<String, bool>, 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) {
Expand Down Expand Up @@ -49,7 +49,6 @@ pub fn parse(n: &Path, features: &HashMap<String, bool>, stage: &Stage) -> Modul

fn p(
n: &Path,
features: &HashMap<String, bool>,
stage: &Stage,
) -> Result<Module, pest::error::Error<Rule>> {
let mut module = Module::default();
Expand Down Expand Up @@ -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),
}
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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<String, bool>,
stage: &Stage,
stm: pest::iterators::Pair<'static, Rule>,
into: &mut Vec<Box<Statement>>,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1174,15 +1172,15 @@ 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 => {
let mut stm = stm.into_inner();
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)],
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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),
}
Expand Down Expand Up @@ -1367,15 +1365,15 @@ 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();
for case in ppart.into_inner() {
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));
}
}
Expand All @@ -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(),
)))));
Expand Down Expand Up @@ -1423,7 +1420,6 @@ pub(crate) fn parse_statement(

pub(crate) fn parse_block(
n: &str,
features: &HashMap<String, bool>,
stage: &Stage,
decl: pest::iterators::Pair<'static, Rule>,
) -> Block {
Expand All @@ -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,
Expand Down
Loading

0 comments on commit 014be6f

Please sign in to comment.