aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-04-14 17:59:46 -0600
committerMelody Horn <melody@boringcactus.com>2021-04-14 17:59:46 -0600
commit42098a0a02e7e1770b0bf07f93aa37159945edb2 (patch)
tree4266dd48921cacd36476a3a323cabcef14eea641 /src
parentb30e701c7e0d4ded6ca4cf7b84073110711dba1f (diff)
downloadmakers-42098a0a02e7e1770b0bf07f93aa37159945edb2.tar.gz
makers-42098a0a02e7e1770b0bf07f93aa37159945edb2.zip
move outer RefCell into DynamicTargetSet
Diffstat (limited to 'src')
-rw-r--r--src/makefile/mod.rs34
-rw-r--r--src/makefile/target.rs19
2 files changed, 25 insertions, 28 deletions
diff --git a/src/makefile/mod.rs b/src/makefile/mod.rs
index 5c38ab3..d7cc25e 100644
--- a/src/makefile/mod.rs
+++ b/src/makefile/mod.rs
@@ -41,7 +41,7 @@ pub struct Makefile<'a> {
inference_rules: Vec<InferenceRule>,
builtin_inference_rules: Vec<InferenceRule>,
pub macros: MacroSet<'static, 'static>,
- targets: RefCell<DynamicTargetSet>,
+ targets: DynamicTargetSet,
pub first_non_special_target: Option<String>,
args: &'a Args,
// TODO borrow warnings from Python version
@@ -51,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 = DynamicTargetSet::default();
+ let targets = DynamicTargetSet::default();
let first_non_special_target = None;
macros.set(
@@ -120,7 +120,7 @@ impl<'a> Makefile<'a> {
inference_rules: vec![],
builtin_inference_rules: inference_rules,
macros,
- targets: RefCell::new(targets),
+ targets,
first_non_special_target,
args,
}
@@ -134,7 +134,7 @@ impl<'a> Makefile<'a> {
new.macro_exports,
);
for (_, target) in new.targets {
- self.targets.borrow_mut().put(target);
+ self.targets.put(target);
}
if self.first_non_special_target.is_none() {
self.first_non_special_target = new.first_non_special_target;
@@ -152,8 +152,7 @@ impl<'a> Makefile<'a> {
}
fn special_target_has_prereq(&self, target: &str, name: &str) -> bool {
- let targets = self.targets.borrow();
- match targets.get(target) {
+ match self.targets.get(target) {
Some(target) => {
let target = target.borrow();
target.prerequisites.is_empty() || target.prerequisites.iter().any(|e| e == name)
@@ -211,7 +210,7 @@ impl<'a> Makefile<'a> {
// we can't build this based on itself! fuck outta here
return None;
}
- if self.targets.borrow().has(&prereq_path_name) {
+ if self.targets.has(&prereq_path_name) {
return Some(prereq_path_name);
}
let prereq_path = PathBuf::from(&prereq_path_name);
@@ -234,7 +233,7 @@ impl<'a> Makefile<'a> {
self.infer_target(&prereq_path_name, banned_rules, banned_names)
.ok()
.and_then(|_| {
- if self.targets.borrow().has(&prereq_path_name) {
+ if self.targets.has(&prereq_path_name) {
Some(prereq_path_name)
} else {
None
@@ -259,7 +258,7 @@ impl<'a> Makefile<'a> {
}
if let Some(new_target) = new_target {
- self.targets.borrow_mut().put(new_target);
+ self.targets.put(new_target);
}
Ok(())
@@ -271,22 +270,20 @@ impl<'a> Makefile<'a> {
let exists_but_infer_anyway = if follow_gnu {
self.targets
- .borrow()
.get(name)
.map_or(false, |target| target.borrow().commands.is_empty())
} else {
false
};
- if !self.targets.borrow().has(name) || exists_but_infer_anyway {
+ if !self.targets.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.has(name) {
+ if !self.targets.has(name) {
// well, inference didn't work. is there a default?
- if let Some(default) = targets.get(".DEFAULT") {
+ if let Some(default) = self.targets.get(".DEFAULT") {
let commands = default.borrow().commands.clone();
new_target = Some(Target {
name: name.into(),
@@ -309,13 +306,12 @@ impl<'a> Makefile<'a> {
}
}
- drop(targets);
if let Some(new_target) = new_target {
- self.targets.borrow_mut().put(new_target);
+ self.targets.put(new_target);
}
- let targets = self.targets.borrow();
- Ok(targets
+ Ok(self
+ .targets
.get(name)
.ok_or_else(|| eyre!("Target {:?} not found!", name))?)
}
@@ -416,7 +412,7 @@ impl fmt::Display for Makefile<'_> {
writeln!(f)?;
header(f, "Targets")?;
- writeln!(f, "{}", &self.targets.borrow())?;
+ writeln!(f, "{}", &self.targets)?;
Ok(())
}
diff --git a/src/makefile/target.rs b/src/makefile/target.rs
index 5de280d..8f56506 100644
--- a/src/makefile/target.rs
+++ b/src/makefile/target.rs
@@ -148,31 +148,32 @@ impl Into<HashMap<String, Target>> for StaticTargetSet {
// for targets that might become updated and so need refcelling
#[derive(Clone, Default)]
pub struct DynamicTargetSet {
- data: HashMap<String, Rc<RefCell<Target>>>,
+ data: RefCell<HashMap<String, Rc<RefCell<Target>>>>,
}
impl DynamicTargetSet {
pub fn get(&self, name: &str) -> Option<Rc<RefCell<Target>>> {
- self.data.get(name).map(|x| Rc::clone(x))
+ self.data.borrow().get(name).map(|x| Rc::clone(x))
}
- pub fn put(&mut self, target: Target) {
- if let Some(existing_target) = self.data.get_mut(&target.name) {
+ pub fn put(&self, target: Target) {
+ if let Some(existing_target) = self.data.borrow().get(&target.name) {
existing_target.borrow_mut().extend(target);
- } else {
- self.data
- .insert(target.name.clone(), Rc::new(RefCell::new(target)));
+ return;
}
+ self.data
+ .borrow_mut()
+ .insert(target.name.clone(), Rc::new(RefCell::new(target)));
}
pub fn has(&self, name: &str) -> bool {
- self.data.contains_key(name)
+ self.data.borrow().contains_key(name)
}
}
impl fmt::Display for DynamicTargetSet {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- for target in self.data.values() {
+ for target in self.data.borrow().values() {
writeln!(f, "{}", target.borrow())?;
}
Ok(())