diff options
author | Melody Horn <melody@boringcactus.com> | 2021-03-26 20:43:41 -0600 |
---|---|---|
committer | Melody Horn <melody@boringcactus.com> | 2021-03-26 20:43:41 -0600 |
commit | 6626a20ea9dde169ca75a4e4c83b5fb5b85c1e47 (patch) | |
tree | bb4ad1ff0bcd1bdb90ca7353f3e14420833f5247 /src/makefile | |
parent | 92caea8c0e61ec01346e512eccc44723c82f1d2b (diff) | |
download | makers-6626a20ea9dde169ca75a4e4c83b5fb5b85c1e47.tar.gz makers-6626a20ea9dde169ca75a4e4c83b5fb5b85c1e47.zip |
don't borrow targets mutably for the whole get_target process
Diffstat (limited to 'src/makefile')
-rw-r--r-- | src/makefile/mod.rs | 26 |
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() } |