aboutsummaryrefslogtreecommitdiff
path: root/src/makefile/input.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/makefile/input.rs')
-rw-r--r--src/makefile/input.rs72
1 files changed, 43 insertions, 29 deletions
diff --git a/src/makefile/input.rs b/src/makefile/input.rs
index 0e0506a..e2add0c 100644
--- a/src/makefile/input.rs
+++ b/src/makefile/input.rs
@@ -19,7 +19,7 @@ use super::inference_rules::InferenceRule;
#[cfg(feature = "full")]
use super::r#macro::ExportConfig;
use super::r#macro::{Macro, Set as MacroSet};
-use super::target::Target;
+use super::target::{StaticTargetSet, Target};
use super::token::{tokenize, Token, TokenString};
use super::ItemSource;
@@ -166,7 +166,7 @@ pub struct MakefileReader<'a, 'parent, R: BufRead> {
file_name: String,
pub inference_rules: Vec<InferenceRule>,
pub macros: MacroSet<'parent, 'static>,
- pub targets: HashMap<String, Target>,
+ pub targets: StaticTargetSet,
built_in_targets: HashMap<String, Target>,
pub first_non_special_target: Option<String>,
pub failed_includes: Vec<String>,
@@ -222,7 +222,7 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> {
file_name: name.clone(),
inference_rules: Vec::new(),
macros,
- targets: HashMap::new(),
+ targets: Default::default(),
built_in_targets: HashMap::new(),
first_non_special_target: None,
failed_includes: Vec::new(),
@@ -675,7 +675,7 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> {
.and_then(|x| x.get(1).map(|x| x.as_str().to_owned())),
already_updated: Cell::new(false),
};
- self.targets.insert(real_target.to_owned(), new_target);
+ self.targets.put(new_target);
}
}
} else {
@@ -728,34 +728,26 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> {
});
self.inference_rules.push(new_rule);
} else {
+ log::trace!(
+ "{}:{}: new target {:?} based on {:?}",
+ &self.file_name,
+ line_number,
+ &targets,
+ &prerequisites
+ );
for target in targets {
if self.first_non_special_target.is_none() && !target.starts_with('.') {
self.first_non_special_target = Some(target.into());
}
// TODO handle appending to built-in (it's Complicated)
- match self.targets.get_mut(target) {
- Some(old_target)
- if commands.is_empty()
- && !(target == ".SUFFIXES" && prerequisites.is_empty()) =>
- {
- let new_prerequisites = prerequisites
- .iter()
- .filter(|x| !old_target.prerequisites.contains(x))
- .cloned()
- .collect::<Vec<_>>();
- old_target.prerequisites.extend(new_prerequisites);
- }
- _ => {
- let new_target = Target {
- name: target.into(),
- prerequisites: prerequisites.clone(),
- commands: commands.clone(),
- stem: None,
- already_updated: Cell::new(false),
- };
- self.targets.insert(target.into(), new_target);
- }
- }
+ let new_target = Target {
+ name: target.into(),
+ prerequisites: prerequisites.clone(),
+ commands: commands.clone(),
+ stem: None,
+ already_updated: Cell::new(false),
+ };
+ self.targets.put(new_target);
}
}
@@ -886,7 +878,7 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> {
macros: self.macros.data,
#[cfg(feature = "full")]
macro_exports: self.macros.exported,
- targets: self.targets,
+ targets: self.targets.into(),
first_non_special_target: self.first_non_special_target,
failed_includes: self.failed_includes,
}
@@ -899,7 +891,9 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> {
#[cfg(feature = "full")]
new.macro_exports,
);
- self.targets.extend(new.targets);
+ for (_, target) in new.targets {
+ self.targets.put(target);
+ }
if self.first_non_special_target.is_none() {
self.first_non_special_target = new.first_non_special_target;
}
@@ -976,6 +970,7 @@ endif
";
let args = Args::empty();
let makefile = MakefileReader::read(&args, MacroSet::new(), Cursor::new(file), "")?;
+ let makefile = makefile.finish();
assert_eq!(makefile.targets["a"].commands.len(), 1);
Ok(())
}
@@ -1055,6 +1050,7 @@ clean:
let args = Args::empty();
let makefile = MakefileReader::read(&args, MacroSet::new(), Cursor::new(file), "")?;
+ let makefile = makefile.finish();
assert!(makefile.targets.contains_key("server"));
Ok(())
}
@@ -1135,4 +1131,22 @@ cursed:
assert_eq!(makefile.inference_rules.len(), 2);
Ok(())
}
+
+ #[test]
+ fn dependency_prepending_appending() -> R {
+ let file = "
+test: a
+test: b
+\techo hi
+test: c
+ ";
+ let args = Args::empty();
+ let makefile = MakefileReader::read(&args, MacroSet::new(), Cursor::new(file), "")?;
+ let makefile = makefile.finish();
+ assert_eq!(
+ makefile.targets["test"].prerequisites,
+ vec!["a".to_owned(), "b".to_owned(), "c".to_owned()]
+ );
+ Ok(())
+ }
}