aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/makefile/mod.rs26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/makefile/mod.rs b/src/makefile/mod.rs
index 2959953..f38815d 100644
--- a/src/makefile/mod.rs
+++ b/src/makefile/mod.rs
@@ -533,7 +533,8 @@ impl Makefile {
_ => vec![]
};
- let mut targets = self.targets.borrow_mut();
+ let targets = self.targets.borrow();
+ let mut new_target = None;
let exists_but_infer_anyway = if follow_gnu {
match targets.get(name) {
Some(target) => {
@@ -567,13 +568,12 @@ impl Makefile {
};
for prereq in prereq_path_options {
if prereq.exists() {
- let new_target = Target {
+ new_target = Some(Target {
name: name.into(),
prerequisites: vec![prereq.to_string_lossy().into()],
commands: rule.commands.clone(),
already_updated: Cell::new(false),
- };
- targets.insert(name.into(), Rc::new(RefCell::new(new_target)));
+ });
break 'rules;
}
}
@@ -582,36 +582,38 @@ impl Makefile {
}
}
- if !targets.contains_key(name) {
+ if !targets.contains_key(name) && new_target.is_none() {
// well, inference didn't work. is there a default?
if let Some(default) = targets.get(".DEFAULT") {
let default = default.borrow();
let commands = default.commands.clone();
drop(default);
- let new_target = Target {
+ new_target = Some(Target {
name: name.into(),
prerequisites: vec![],
commands,
already_updated: Cell::new(false),
- };
- targets.insert(name.into(), Rc::new(RefCell::new(new_target)));
+ });
} else {
// if it already exists, it counts as up-to-date
if Path::new(name).exists() {
- let new_target = Target {
+ new_target = Some(Target {
name: name.into(),
prerequisites: vec![],
commands: vec![],
already_updated: Cell::new(true),
- };
- targets.insert(name.into(), Rc::new(RefCell::new(new_target)));
+ });
}
}
}
drop(targets);
- let targets = self.targets.borrow();
+ if let Some(new_target) = new_target {
+ let mut targets = self.targets.borrow_mut();
+ targets.insert(new_target.name.clone(), Rc::new(RefCell::new(new_target)));
+ }
+ let targets = self.targets.borrow();
targets.get(name).expect("Target not found!").clone()
}