From b259a318223370881d5244cc38ff8a7be58e2a3e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 3 Dec 2023 13:47:42 +0200 Subject: Reimplement search_existing() functions via target_type::search This allows us to automatically get the target type-specific behavior with regards to the out_only semantics (added in the previous commit) instead of passing it explicitly from each call site. --- libbuild2/algorithm.cxx | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'libbuild2/algorithm.cxx') diff --git a/libbuild2/algorithm.cxx b/libbuild2/algorithm.cxx index 71bf134..8b7aa28 100644 --- a/libbuild2/algorithm.cxx +++ b/libbuild2/algorithm.cxx @@ -54,19 +54,21 @@ namespace build2 const target& search (const target& t, const prerequisite_key& pk) { - assert (t.ctx.phase == run_phase::match); + context& ctx (t.ctx); + + assert (ctx.phase == run_phase::match); // If this is a project-qualified prerequisite, then this is import's // business (phase 2). // if (pk.proj) - return import2 (t.ctx, pk); + return import2 (ctx, pk); - if (const target* pt = pk.tk.type->search (t, pk)) + if (const target* pt = pk.tk.type->search (ctx, &t, pk)) return *pt; if (pk.tk.out->empty ()) - return create_new_target (t.ctx, pk); + return create_new_target (ctx, pk); // If this is triggered, then you are probably not passing scope to // search() (which leads to search_existing_file() being skipped). @@ -77,13 +79,15 @@ namespace build2 pair search_locked (const target& t, const prerequisite_key& pk) { - assert (t.ctx.phase == run_phase::match && !pk.proj); + context& ctx (t.ctx); + + assert (ctx.phase == run_phase::match && !pk.proj); - if (const target* pt = pk.tk.type->search (t, pk)) + if (const target* pt = pk.tk.type->search (ctx, &t, pk)) return {const_cast (*pt), ulock ()}; if (pk.tk.out->empty ()) - return create_new_target_locked (t.ctx, pk); + return create_new_target_locked (ctx, pk); // If this is triggered, then you are probably not passing scope to // search() (which leads to search_existing_file() being skipped). @@ -96,7 +100,7 @@ namespace build2 { return pk.proj ? import_existing (ctx, pk) - : search_existing_target (ctx, pk, false /*out_only*/); // @@ TODO + : pk.tk.type->search (ctx, nullptr /* existing */, pk); } const target& @@ -181,7 +185,7 @@ namespace build2 return q ? import_existing (s.ctx, pk) - : search_existing_target (s.ctx, pk, false /*out_only*/); // @@ TODO + : tt->search (s.ctx, nullptr /* existing */, pk); } const target* -- cgit v1.1