From 6d510d99dee4135bcb6f973c6e208f05f889bc8d Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Wed, 22 Jan 2020 10:45:07 -0800 Subject: [PATCH 2/4] parse: Check that rules always have a command This way, we catch the error earlier than build(), and won't have to repeat the check for the compdb tool. --- build.c | 4 ---- parse.c | 5 +++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/build.c b/build.c index 71dda17..c382c17 100644 --- a/build.c +++ b/build.c @@ -231,10 +231,6 @@ jobstart(struct job *j, struct edge *e) } j->edge = e; j->cmd = edgevar(e, "command", true); - if (!j->cmd) { - warn("rule '%s' has no command", e->rule->name); - goto err2; - } j->fd = fd[0]; argv[2] = j->cmd->s; diff --git a/parse.c b/parse.c index f8f9509..6d07816 100644 --- a/parse.c +++ b/parse.c @@ -35,6 +35,7 @@ parserule(struct scanner *s, struct environment *env) struct rule *r; char *var; struct evalstring *val; + bool hascommand = false; r = mkrule(scanname(s)); scannewline(s); @@ -42,7 +43,11 @@ parserule(struct scanner *s, struct environment *env) var = scanname(s); parselet(s, &val); ruleaddvar(r, var, val); + if (strcmp(var, "command") == 0) + hascommand = true; } + if (!hascommand) + fatal("rule '%s' has no command", r->name); envaddrule(env, r); } -- 2.24.0