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/parser.cxx | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'libbuild2/parser.cxx') diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx index 71465f0..baf404a 100644 --- a/libbuild2/parser.cxx +++ b/libbuild2/parser.cxx @@ -2778,9 +2778,24 @@ namespace build2 optional& e (rp.second); if (t == nullptr) - fail (ploc) << "unknown target type " << n.type << - info << "perhaps the module that defines this target type is " - << "not loaded by project " << *scope_->root_scope (); + { + if (n.proj) + { + // If the target type is unknown then no phase 2 import (like + // rule-specific search) can possibly succeed so we can fail now and + // with a more accurate reason. See import2(names) for background. + // + diag_record dr; + dr << fail (ploc) << "unable to import target " << n; + import_suggest (dr, *n.proj, nullptr, string (), false); + } + else + { + fail (ploc) << "unknown target type " << n.type << + info << "perhaps the module that defines this target type is " + << "not loaded by project " << *scope_->root_scope (); + } + } if (t->factory == nullptr) fail (ploc) << "abstract target type " << t->name << "{}"; -- cgit v1.1