From 87a7253a3bd82b59063172f3799b0a5587e7b2a5 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 2 Apr 2024 08:03:55 +0200 Subject: Detect and diagnose attempt to create new target in src directory GitHub issue #277. --- libbuild2/search.cxx | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'libbuild2/search.cxx') 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 (); -- cgit v1.1