From bcfcc38538af8bb896551c9e5730767807ad7a67 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 7 Feb 2017 10:05:47 +0200 Subject: Tighten code that operates during both search/match and execute --- build2/file.cxx | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) (limited to 'build2/file.cxx') diff --git a/build2/file.cxx b/build2/file.cxx index 3da1d35..c403eea 100644 --- a/build2/file.cxx +++ b/build2/file.cxx @@ -1142,8 +1142,8 @@ namespace build2 return names (); // Never reached. } - target& - import (const prerequisite_key& pk) + target* + import (const prerequisite_key& pk, bool existing) { tracer trace ("import"); @@ -1155,7 +1155,7 @@ namespace build2 const target_key& tk (pk.tk); const target_type& tt (*tk.type); - // Try to find the executable in PATH (or CWD is relative). + // Try to find the executable in PATH (or CWD if relative). // if (tt.is_a ()) { @@ -1174,24 +1174,36 @@ namespace build2 path& p (pp.effect); assert (!p.empty ()); // We searched for a simple name. - exe& t ( - targets.insert ( - tt, - p.directory (), - dir_path (), // No out (out of project). - p.leaf ().base ().string (), - p.extension (), // Always specified. - trace)); - - if (t.path ().empty ()) - t.path (move (p)); - else - assert (t.path () == p); + exe* t ( + !existing + ? &targets.insert (tt, + p.directory (), + dir_path (), // No out (out of project). + p.leaf ().base ().string (), + p.extension (), // Always specified. + trace) + : targets.find (tt, + p.directory (), + dir_path (), + p.leaf ().base ().string (), + p.extension (), + trace)); + + if (t != nullptr) + { + if (t->path ().empty () && !existing) + t->path (move (p)); + else + assert (t->path () == p); - return t; + return t; + } } } + if (existing) + return nullptr; + // @@ We no longer have location. This is especially bad for the // empty case, i.e., where do I need to specify the project // name)? Looks like the only way to do this is to keep location -- cgit v1.1