aboutsummaryrefslogtreecommitdiff
path: root/src/makefile/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/makefile/mod.rs')
-rw-r--r--src/makefile/mod.rs51
1 files changed, 19 insertions, 32 deletions
diff --git a/src/makefile/mod.rs b/src/makefile/mod.rs
index 1d4873e..5c38ab3 100644
--- a/src/makefile/mod.rs
+++ b/src/makefile/mod.rs
@@ -1,5 +1,4 @@
use std::cell::{Cell, RefCell};
-use std::collections::HashMap;
use std::env;
use std::fmt;
use std::path::{Path, PathBuf};
@@ -12,7 +11,7 @@ use inference_rules::InferenceRule;
use input::FinishedMakefileReader;
pub use input::MakefileReader;
use r#macro::{Macro, Set as MacroSet};
-use target::Target;
+use target::{DynamicTargetSet, Target};
use token::TokenString;
use crate::args::Args;
@@ -42,7 +41,7 @@ pub struct Makefile<'a> {
inference_rules: Vec<InferenceRule>,
builtin_inference_rules: Vec<InferenceRule>,
pub macros: MacroSet<'static, 'static>,
- targets: RefCell<HashMap<String, Rc<RefCell<Target>>>>,
+ targets: RefCell<DynamicTargetSet>,
pub first_non_special_target: Option<String>,
args: &'a Args,
// TODO borrow warnings from Python version
@@ -52,7 +51,7 @@ impl<'a> Makefile<'a> {
pub fn new(args: &'a Args) -> Self {
let mut inference_rules = vec![];
let mut macros = MacroSet::new();
- let mut targets = HashMap::new();
+ let mut targets = DynamicTargetSet::default();
let first_non_special_target = None;
macros.set(
@@ -70,11 +69,9 @@ impl<'a> Makefile<'a> {
if !args.no_builtin_rules {
inference_rules.extend(builtin_inference_rules());
macros.add_builtins();
- targets.extend(
- builtin_targets()
- .into_iter()
- .map(|t| (t.name.clone(), Rc::new(RefCell::new(t)))),
- );
+ for target in builtin_targets() {
+ targets.put(target);
+ }
}
macros.add_env();
@@ -136,11 +133,9 @@ impl<'a> Makefile<'a> {
#[cfg(feature = "full")]
new.macro_exports,
);
- self.targets.borrow_mut().extend(
- new.targets
- .into_iter()
- .map(|(k, v)| (k, Rc::new(RefCell::new(v)))),
- );
+ for (_, target) in new.targets {
+ self.targets.borrow_mut().put(target);
+ }
if self.first_non_special_target.is_none() {
self.first_non_special_target = new.first_non_special_target;
}
@@ -216,7 +211,7 @@ impl<'a> Makefile<'a> {
// we can't build this based on itself! fuck outta here
return None;
}
- if self.targets.borrow().contains_key(&prereq_path_name) {
+ if self.targets.borrow().has(&prereq_path_name) {
return Some(prereq_path_name);
}
let prereq_path = PathBuf::from(&prereq_path_name);
@@ -239,7 +234,7 @@ impl<'a> Makefile<'a> {
self.infer_target(&prereq_path_name, banned_rules, banned_names)
.ok()
.and_then(|_| {
- if self.targets.borrow().contains_key(&prereq_path_name) {
+ if self.targets.borrow().has(&prereq_path_name) {
Some(prereq_path_name)
} else {
None
@@ -264,9 +259,7 @@ impl<'a> Makefile<'a> {
}
if let Some(new_target) = new_target {
- self.targets
- .borrow_mut()
- .insert(new_target.name.clone(), Rc::new(RefCell::new(new_target)));
+ self.targets.borrow_mut().put(new_target);
}
Ok(())
@@ -284,14 +277,14 @@ impl<'a> Makefile<'a> {
} else {
false
};
- if !self.targets.borrow().contains_key(name) || exists_but_infer_anyway {
+ if !self.targets.borrow().has(name) || exists_but_infer_anyway {
log::trace!("trying to infer for {}", name);
self.infer_target(name, vec![], vec![])?;
}
let mut new_target = None;
let targets = self.targets.borrow();
- if !targets.contains_key(name) {
+ if !targets.has(name) {
// well, inference didn't work. is there a default?
if let Some(default) = targets.get(".DEFAULT") {
let commands = default.borrow().commands.clone();
@@ -318,17 +311,13 @@ impl<'a> Makefile<'a> {
drop(targets);
if let Some(new_target) = new_target {
- self.targets
- .borrow_mut()
- .insert(new_target.name.clone(), Rc::new(RefCell::new(new_target)));
+ self.targets.borrow_mut().put(new_target);
}
let targets = self.targets.borrow();
- Ok(Rc::clone(
- targets
- .get(name)
- .ok_or_else(|| eyre!("Target {:?} not found!", name))?,
- ))
+ Ok(targets
+ .get(name)
+ .ok_or_else(|| eyre!("Target {:?} not found!", name))?)
}
pub fn update_target(&self, name: &str) -> Result<()> {
@@ -427,9 +416,7 @@ impl fmt::Display for Makefile<'_> {
writeln!(f)?;
header(f, "Targets")?;
- for target in self.targets.borrow().values() {
- writeln!(f, "{}", target.borrow())?;
- }
+ writeln!(f, "{}", &self.targets.borrow())?;
Ok(())
}