aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/search.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2024-04-02 08:03:55 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2024-04-02 08:03:55 +0200
commit87a7253a3bd82b59063172f3799b0a5587e7b2a5 (patch)
treee99ea1139bea536f02865fc9fcd06486676c0f73 /libbuild2/search.cxx
parentcede94e8190ead8d2bc311e82348119d9abbfc3d (diff)
Detect and diagnose attempt to create new target in src directory
GitHub issue #277.
Diffstat (limited to 'libbuild2/search.cxx')
-rw-r--r--libbuild2/search.cxx27
1 files changed, 27 insertions, 0 deletions
diff --git a/libbuild2/search.cxx b/libbuild2/search.cxx
index dee2ae8..4e855e3 100644
--- a/libbuild2/search.cxx
+++ b/libbuild2/search.cxx
@@ -265,7 +265,24 @@ namespace build2
//
dir_path d;
if (tk.dir->absolute ())
+ {
d = *tk.dir; // Already normalized.
+
+ // Even if out is empty, it may still be (only) in src.
+ //
+ // Note: issue diagnostics consistent with search() after skipping this
+ // function due to non-empty out.
+ //
+ // @@ PERF: we could first check if it's in pk.scope, which feels like
+ // the common case. Though this doesn't seem to affect
+ // performance in any noticeable way.
+ //
+ auto p (ctx.scopes.find (d, false)); // Note: never empty.
+ if (*p.first == nullptr && ++p.first != p.second)
+ {
+ fail << "no existing source file for prerequisite " << pk << endf;
+ }
+ }
else
{
d = pk.scope->out_path ();
@@ -313,7 +330,17 @@ namespace build2
//
dir_path d;
if (tk.dir->absolute ())
+ {
d = *tk.dir; // Already normalized.
+
+ // As above.
+ //
+ auto p (ctx.scopes.find (d, false));
+ if (*p.first == nullptr && ++p.first != p.second)
+ {
+ fail << "no existing source file for prerequisite " << pk << endf;
+ }
+ }
else
{
d = pk.scope->out_path ();