From cddb2d17e71887fdb325afdc67905201d0220b13 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 20 Oct 2022 12:26:35 +0200 Subject: Don't create targets for non-existent source files --- libbuild2/algorithm.cxx | 16 ++++++++++++++-- libbuild2/dyndep.cxx | 4 ++-- libbuild2/search.cxx | 26 ++++++++++++-------------- 3 files changed, 28 insertions(+), 18 deletions(-) (limited to 'libbuild2') diff --git a/libbuild2/algorithm.cxx b/libbuild2/algorithm.cxx index cb63e87..8f399dd 100644 --- a/libbuild2/algorithm.cxx +++ b/libbuild2/algorithm.cxx @@ -65,7 +65,13 @@ namespace build2 if (const target* pt = pk.tk.type->search (t, pk)) return *pt; - return create_new_target (t.ctx, pk); + if (pk.tk.out->empty ()) + return create_new_target (t.ctx, pk); + + // If this is triggered, then you are probably not passing scope to + // search() (which leads to search_existing_file() being skipped). + // + fail << "no existing source file for prerequisite " << pk << endf; } pair @@ -76,7 +82,13 @@ namespace build2 if (const target* pt = pk.tk.type->search (t, pk)) return {const_cast (*pt), ulock ()}; - return create_new_target_locked (t.ctx, pk); + if (pk.tk.out->empty ()) + return create_new_target_locked (t.ctx, pk); + + // If this is triggered, then you are probably not passing scope to + // search() (which leads to search_existing_file() being skipped). + // + fail << "no existing source file for prerequisite " << pk << endf; } const target* diff --git a/libbuild2/dyndep.cxx b/libbuild2/dyndep.cxx index 94d2028..9816ad6 100644 --- a/libbuild2/dyndep.cxx +++ b/libbuild2/dyndep.cxx @@ -445,7 +445,7 @@ namespace build2 // The directory is only moved from if insert is true. Note that it must // be normalized. // - auto find = [&trace, what, &t, + auto find = [&trace, what, &bs, &t, &map_extension, &fallback] (dir_path&& d, path&& f, @@ -603,7 +603,7 @@ namespace build2 // @@ OPT: move d, out, n // if (r == nullptr && insert) - r = &search (t, *tts[0], d, out, n, &e); + r = &search (t, *tts[0], d, out, n, &e, &bs); return static_cast (r); }; diff --git a/libbuild2/search.cxx b/libbuild2/search.cxx index c2f7de4..3bdb503 100644 --- a/libbuild2/search.cxx +++ b/libbuild2/search.cxx @@ -231,6 +231,12 @@ namespace build2 const target_key& tk (pk.tk); + // If out is present, then it means the target is in src and we shouldn't + // be creating new targets in src, should we? Feels like this should not + // even be called if out is not empty. + // + assert (tk.out->empty ()); + // We default to the target in this directory scope. // dir_path d; @@ -251,13 +257,6 @@ namespace build2 // // More often insert than find, so skip find in insert(). // - // @@ OUT: same story as in search_existing_target() re out. Maybe not: - // if out is present, then it means the target is in src and we - // shouldn't be creating new targets in src, should we? Feels - // like this should not even be called in out is not empty. - // - //assert (tk.out->empty ()); @@ TMP - auto r (ctx.targets.insert (*tk.type, move (d), *tk.out, @@ -280,6 +279,12 @@ namespace build2 const target_key& tk (pk.tk); + // If out is present, then it means the target is in src and we shouldn't + // be creating new targets in src, should we? Feels like this should not + // even be called if out is not empty. + // + assert (tk.out->empty ()); + // We default to the target in this directory scope. // dir_path d; @@ -300,13 +305,6 @@ namespace build2 // // More often insert than find, so skip find in insert_locked(). // - // @@ OUT: same story as in search_existing_target() re out. Maybe not: - // if out is present, then it means the target is in src and we - // shouldn't be creating new targets in src, should we? Feels - // like this should not even be called in out is not empty. - // - //assert (tk.out->empty ()); @@ TMP - auto r (ctx.targets.insert_locked (*tk.type, move (d), *tk.out, -- cgit v1.1