From f549b757394fdb4ac27e4a4bc42e865e98434361 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Wed, 22 Jan 2020 11:36:30 -0800 Subject: [PATCH 3/4] parse: Check that rules have $rspfile iff they have $rspfile_content --- parse.c | 8 +++++++- util.c | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/parse.c b/parse.c index 6d07816..413e5d7 100644 --- a/parse.c +++ b/parse.c @@ -35,7 +35,7 @@ parserule(struct scanner *s, struct environment *env) struct rule *r; char *var; struct evalstring *val; - bool hascommand = false; + bool hascommand = false, hasrspfile = false, hasrspcontent = false; r = mkrule(scanname(s)); scannewline(s); @@ -45,9 +45,15 @@ parserule(struct scanner *s, struct environment *env) ruleaddvar(r, var, val); if (strcmp(var, "command") == 0) hascommand = true; + else if (strcmp(var, "rspfile") == 0) + hasrspfile = true; + else if (strcmp(var, "rspfile_content") == 0) + hasrspcontent = true; } if (!hascommand) fatal("rule '%s' has no command", r->name); + if (hasrspfile != hasrspcontent) + fatal("rule '%s' has rspfile and no rspfile_content or vice versa", r->name); envaddrule(env, r); } diff --git a/util.c b/util.c index 8eccf92..39bab18 100644 --- a/util.c +++ b/util.c @@ -257,7 +257,7 @@ writefile(const char *name, struct string *s) return -1; } ret = 0; - if (s && (fwrite(s->s, 1, s->n, f) != s->n || fflush(f) != 0)) { + if (fwrite(s->s, 1, s->n, f) != s->n || fflush(f) != 0) { warn("write %s:", name); ret = -1; } -- 2.24.0