summaryrefslogtreecommitdiff
path: root/src/rule.c
diff options
context:
space:
mode:
authorDmitry Goncharov <dgoncharov@users.sf.net>2021-10-17 18:03:04 -0400
committerPaul Smith <psmith@gnu.org>2021-10-18 23:00:21 -0400
commitf8f9d371ff58a7195ca4abc9413f435c2bf2b998 (patch)
tree3508b3d47b1321ea64208be4c1c2c66d3f46f17e /src/rule.c
parentf5af979357f10e3c2dd1fc5e483d52928c7cf6ec (diff)
downloadmake-git-f8f9d371ff58a7195ca4abc9413f435c2bf2b998.tar.gz
[SV 61042] Enhance logging of implicit rule search
Logging of implicit rule search gives limited information as to why a given implicit rule was rejected, and if no implicit rule is found we get the confusing "No rule to make target" result when the real issue is that some prerequisite of some implicit rule could not be built. Enhance logging around implicit rule search as follows: 1. The messages which refer to a rule print a description (the targets and prerequisites) of the rule. 2. A new message tells when a rule is rejected, along with the reason. 3. The 'Looking for an implicit rule...' message is printed for every prerequisite, not just the top-level target. 4. "Trying harder" message is printed, when intermediate prerequisites are going to be searched. 5. The 'No rule found...' and 'Found implicit rule...' messages are printed for every prerequisite, not just the top-level target. 6. "Ought to exist...", "Found..." or "Not found..." message is printed for each prerequisite. * src/rule.h (struct rule): Remember the definition of the rule. * src/rule.c (get_rule_defn): Compute the definition of a rule. (install_pattern_rule): Initialize the definition to empty. (create_pattern_rule): Ditto. (freerule): Free the definition. (print_rule): Use the definition when printing rules. * src/remake.c (update_file_1): Push debug output down into try_implicit_rule(). * src/implicit.c (try_implicit_rule): Add debugging (pattern_search): Show the rule definition in various debug output. Add new debug messages for implicit rule search. Additional changes by Paul Smith <psmith@gnu.org>: Since we usually don't need the rule definition, defer computing it until we do. * bootstrap.conf: Include the mempcpy Gnulib module. * src/makeint.h (mempcpy): Declare mempcpy if not available. * src/misc.c (mempcpy): Define mempcpy if not available. * src/config.h-vms.template: Don't set HAVE_MEMPCPY. * src/config.h.W32.template: Ditto. * src/rule.h (get_rule_defn): Return the definition of a rule. * src/rule.c (get_rule_defn): If we don't have a definition compute it; either way return it. * src/implicit.c (pattern_search): Rework the handling of explicit prerequisites to pattern rules to be more clear. There is no change in behavior.
Diffstat (limited to 'src/rule.c')
-rw-r--r--src/rule.c65
1 files changed, 54 insertions, 11 deletions
diff --git a/src/rule.c b/src/rule.c
index 7efca58b..16aec7fe 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -59,6 +59,55 @@ struct file *suffix_file;
/* Maximum length of a suffix. */
static size_t maxsuffix;
+
+/* Return the rule definition: space separated rule targets, followed by
+ either a colon or two colons in the case of a terminal rule, followed by
+ space separated rule prerequisites, followed by a pipe, followed by
+ order-only prerequisites, if present. */
+
+const char *get_rule_defn (struct rule *r)
+{
+ if (r->_defn == NULL)
+ {
+ unsigned int k;
+ ptrdiff_t len = 8; // Reserve for ":: ", " | " and the null terminator.
+ char *p;
+ const char *sep = "";
+ const struct dep *dep, *ood = 0;
+
+ for (k = 0; k < r->num; ++k)
+ len += r->lens[k] + 1; // Add one for a space.
+
+ for (dep = r->deps; dep; dep = dep->next)
+ len += strlen (dep_name (dep)) + 1; // Add one for a space.
+
+ p = r->_defn = xmalloc (len);
+ for (k = 0; k < r->num; ++k, sep = " ")
+ p = mempcpy (mempcpy (p, sep, strlen (sep)), r->targets[k], r->lens[k]);
+ *p++ = ':';
+ if (r->terminal)
+ *p++ = ':';
+
+ /* Copy all normal dependencies; note any order-only deps. */
+ for (dep = r->deps; dep; dep = dep->next)
+ if (dep->ignore_mtime == 0)
+ p = mempcpy (mempcpy (p, " ", 1), dep_name (dep),
+ strlen (dep_name (dep)));
+ else if (ood == 0)
+ ood = dep;
+
+ /* Copy order-only deps, if we have any. */
+ for (sep = " | "; ood; ood = ood->next, sep = " ")
+ if (ood->ignore_mtime)
+ p = mempcpy (mempcpy (p, sep, strlen (sep)), dep_name (ood),
+ strlen (dep_name (ood)));
+ *p = '\0';
+ assert (p - r->_defn < len);
+ }
+
+ return r->_defn;
+}
+
/* Compute the maximum dependency length and maximum number of dependencies of
all implicit rules. Also sets the subdir flag for a rule when appropriate,
@@ -398,6 +447,7 @@ install_pattern_rule (struct pspec *p, int terminal)
r->targets = xmalloc (sizeof (const char *));
r->suffixes = xmalloc (sizeof (const char *));
r->lens = xmalloc (sizeof (unsigned int));
+ r->_defn = NULL;
r->lens[0] = (unsigned int) strlen (p->target);
r->targets[0] = p->target;
@@ -439,6 +489,7 @@ freerule (struct rule *rule, struct rule *lastrule)
free ((void *)rule->targets);
free ((void *)rule->suffixes);
free (rule->lens);
+ free ((void *) rule->_defn);
/* We can't free the storage for the commands because there
are ways that they could be in more than one place:
@@ -488,6 +539,7 @@ create_pattern_rule (const char **targets, const char **target_percents,
r->targets = targets;
r->suffixes = target_percents;
r->lens = xmalloc (n * sizeof (unsigned int));
+ r->_defn = NULL;
for (i = 0; i < n; ++i)
{
@@ -505,17 +557,8 @@ create_pattern_rule (const char **targets, const char **target_percents,
static void /* Useful to call from gdb. */
print_rule (struct rule *r)
{
- unsigned int i;
-
- for (i = 0; i < r->num; ++i)
- {
- fputs (r->targets[i], stdout);
- putchar ((i + 1 == r->num) ? ':' : ' ');
- }
- if (r->terminal)
- putchar (':');
-
- print_prereqs (r->deps);
+ fputs (get_rule_defn (r), stdout);
+ putchar ('\n');
if (r->cmds != 0)
print_commands (r->cmds);