From 05ee8c20d83c2f108aa71a65e19b7adff8ff9aa0 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 11 Jan 2024 14:45:15 +0200 Subject: Fail with unable to import rather than unknown target type --- libbuild2/functions-name.cxx | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'libbuild2/functions-name.cxx') diff --git a/libbuild2/functions-name.cxx b/libbuild2/functions-name.cxx index fcb492f..456f85b 100644 --- a/libbuild2/functions-name.cxx +++ b/libbuild2/functions-name.cxx @@ -97,7 +97,18 @@ namespace build2 const target_type* ntt (to_target_type (s, n, o).first); if (ntt == nullptr) + { + // If this is an imported target and the target type is unknown, then + // it cannot possibly match one of the known types. We handle it like + // this instead of failing because the later failure (e.g., as a + // result of this target listed as prerequisite) will have more + // accurate diagnostics. See also filter() below. + // + if (n.proj) + return false; + fail << "unknown target type " << n.type << " in " << n; + } return ntt->is_a (*tt); } @@ -142,13 +153,24 @@ namespace build2 const target_type* ntt (to_target_type (s, c, p ? *++i : name ()).first); if (ntt == nullptr) - fail << "unknown target type " << n.type << " in " << n; + { + // If this is an imported target and the target type is unknown, then + // it cannot possibly match one of the known types. We handle it like + // this instead of failing because the later failure (e.g., as a + // result of this target listed as prerequisite) will have more + // accurate diagnostics. See also is_a() above. + // + if (!n.proj) + fail << "unknown target type " << n.type << " in " << n; + } - if ((find_if (tts.begin (), tts.end (), - [ntt] (const target_type* tt) - { - return ntt->is_a (*tt); - }) != tts.end ()) != out) + if (ntt != nullptr + ? (find_if (tts.begin (), tts.end (), + [ntt] (const target_type* tt) + { + return ntt->is_a (*tt); + }) != tts.end ()) != out + : out) { r.push_back (move (n)); if (p) -- cgit v1.1