diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2017-02-07 10:05:47 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2017-02-13 12:42:42 +0200 |
commit | bcfcc38538af8bb896551c9e5730767807ad7a67 (patch) | |
tree | 722e71364bf6d8080ca61d8b2d02879520d90765 /build2/file.cxx | |
parent | 7b9eb752cad04aaadc4552d0f26d307b04af1869 (diff) |
Tighten code that operates during both search/match and execute
Diffstat (limited to 'build2/file.cxx')
-rw-r--r-- | build2/file.cxx | 46 |
1 files changed, 29 insertions, 17 deletions
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<exe> ()) { @@ -1174,24 +1174,36 @@ namespace build2 path& p (pp.effect); assert (!p.empty ()); // We searched for a simple name. - exe& t ( - targets.insert<exe> ( - 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<exe> (tt, + p.directory (), + dir_path (), // No out (out of project). + p.leaf ().base ().string (), + p.extension (), // Always specified. + trace) + : targets.find<exe> (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 |