From b6c61ea9afd2d738711770e44748e48be009154d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 24 Sep 2020 13:10:25 +0200 Subject: Give hints for common causes of "no rule to update ..." error --- libbuild2/algorithm.cxx | 51 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'libbuild2/algorithm.cxx') diff --git a/libbuild2/algorithm.cxx b/libbuild2/algorithm.cxx index 5b340c7..53aac4e 100644 --- a/libbuild2/algorithm.cxx +++ b/libbuild2/algorithm.cxx @@ -298,7 +298,7 @@ namespace build2 out, move (n), nullopt /* ext */, - true /* implied */, + target_decl::implied, trace)); assert (r.second.owns_lock ()); @@ -509,6 +509,55 @@ namespace build2 diag_record dr; dr << fail << "no rule to " << diag_do (a, t); + // Try to give some hints of the common causes. + // + switch (t.decl) + { + case target_decl::prereq_new: + { + dr << info << "target " << t << " is no declared in any buildfile"; + + if (t.is_a ()) + dr << info << "perhaps it is a missing source file?"; + + break; + } + case target_decl::prereq_file: + { + // It's an existing file so it's an unlikely case. + // + break; + } + case target_decl::implied: + { + // While the "in a buildfile" is not exactly accurate, we assume + // it's unlikely we will end up here in other cases. + // + dr << info << "target " << t << " is implicitly declared in a " + << "buildfile"; + + if (const scope* rs = bs.root_scope ()) + { + if (t.out.empty () && rs->src_path () != rs->out_path ()) + { + name n (t.as_name ()[0]); + n.dir.clear (); + dr << info << "perhaps it should be declared as being in the " + << "source tree: " << n << "@./ ?"; + } + } + + break; + } + case target_decl::real: + { + // If we had a location, maybe it would make sense to mention this + // case. + // + break; + } + } + if (verb < 4) dr << info << "re-run with --verbose=4 for more information"; } -- cgit v1.1