Module Name: src Committed By: dholland Date: Fri Aug 26 23:28:39 UTC 2016
Modified Files: src/usr.bin/make: compat.c job.c main.c make.h parse.c Log Message: Add a .DELETE_ON_ERROR: magic target that causes *failed* targets as well as *interrupted* targets to be deleted. The name and behavior of the variable matches gmake. Also fix a glitch in newline output on error in compat mode that I discovered while doing it. Closes PR 51376. To generate a diff of this commit: cvs rdiff -u -r1.105 -r1.106 src/usr.bin/make/compat.c cvs rdiff -u -r1.187 -r1.188 src/usr.bin/make/job.c cvs rdiff -u -r1.250 -r1.251 src/usr.bin/make/main.c cvs rdiff -u -r1.100 -r1.101 src/usr.bin/make/make.h cvs rdiff -u -r1.214 -r1.215 src/usr.bin/make/parse.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/compat.c diff -u src/usr.bin/make/compat.c:1.105 src/usr.bin/make/compat.c:1.106 --- src/usr.bin/make/compat.c:1.105 Thu May 12 20:28:34 2016 +++ src/usr.bin/make/compat.c Fri Aug 26 23:28:39 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: compat.c,v 1.105 2016/05/12 20:28:34 sjg Exp $ */ +/* $NetBSD: compat.c,v 1.106 2016/08/26 23:28:39 dholland Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: compat.c,v 1.105 2016/05/12 20:28:34 sjg Exp $"; +static char rcsid[] = "$NetBSD: compat.c,v 1.106 2016/08/26 23:28:39 dholland Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)compat.c 8.2 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: compat.c,v 1.105 2016/05/12 20:28:34 sjg Exp $"); +__RCSID("$NetBSD: compat.c,v 1.106 2016/08/26 23:28:39 dholland Exp $"); #endif #endif /* not lint */ #endif @@ -116,6 +116,25 @@ static GNode *curTarg = NULL; static GNode *ENDNode; static void CompatInterrupt(int); +/* + * CompatDeleteTarget -- delete a failed, interrupted, or otherwise + * duffed target if not inhibited by .PRECIOUS. + */ +static void +CompatDeleteTarget(GNode *gn) +{ + if ((gn != NULL) && !Targ_Precious (gn)) { + char *p1; + char *file = Var_Value(TARGET, gn, &p1); + + if (!noExecute && eunlink(file) != -1) { + Error("*** %s removed", file); + } + + free(p1); + } +} + /*- *----------------------------------------------------------------------- * CompatInterrupt -- @@ -129,6 +148,9 @@ static void CompatInterrupt(int); * The target is removed and the process exits. If .INTERRUPT exists, * its commands are run first WITH INTERRUPTS IGNORED.. * + * XXX: is .PRECIOUS supposed to inhibit .INTERRUPT? I doubt it, but I've + * left the logic alone for now. - dholland 20160826 + * *----------------------------------------------------------------------- */ static void @@ -136,16 +158,9 @@ CompatInterrupt(int signo) { GNode *gn; - if ((curTarg != NULL) && !Targ_Precious (curTarg)) { - char *p1; - char *file = Var_Value(TARGET, curTarg, &p1); - - if (!noExecute && eunlink(file) != -1) { - Error("*** %s removed", file); - } - - free(p1); + CompatDeleteTarget(curTarg); + if ((curTarg != NULL) && !Targ_Precious (curTarg)) { /* * Run .INTERRUPT only if hit with interrupt signal */ @@ -155,7 +170,6 @@ CompatInterrupt(int signo) Compat_Make(gn, gn); } } - } if (signo == SIGQUIT) _exit(signo); @@ -444,6 +458,11 @@ again: * continue. */ printf(" (continuing)\n"); + } else { + printf("\n"); + } + if (deleteOnError) { + CompatDeleteTarget(gn); } } else { /* @@ -604,7 +623,7 @@ Compat_Make(void *gnp, void *pgnp) } else if (keepgoing) { pgn->flags &= ~REMAKE; } else { - PrintOnError(gn, "\n\nStop."); + PrintOnError(gn, "\nStop."); exit(1); } } else if (gn->made == ERROR) { @@ -695,7 +714,7 @@ Compat_Run(Lst targs) if (gn != NULL) { Compat_Make(gn, gn); if (gn->made == ERROR) { - PrintOnError(gn, "\n\nStop."); + PrintOnError(gn, "\nStop."); exit(1); } } @@ -736,7 +755,7 @@ Compat_Run(Lst targs) if (errors == 0) { Compat_Make(ENDNode, ENDNode); if (gn->made == ERROR) { - PrintOnError(gn, "\n\nStop."); + PrintOnError(gn, "\nStop."); exit(1); } } Index: src/usr.bin/make/job.c diff -u src/usr.bin/make/job.c:1.187 src/usr.bin/make/job.c:1.188 --- src/usr.bin/make/job.c:1.187 Thu May 12 20:28:34 2016 +++ src/usr.bin/make/job.c Fri Aug 26 23:28:39 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: job.c,v 1.187 2016/05/12 20:28:34 sjg Exp $ */ +/* $NetBSD: job.c,v 1.188 2016/08/26 23:28:39 dholland Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -70,14 +70,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: job.c,v 1.187 2016/05/12 20:28:34 sjg Exp $"; +static char rcsid[] = "$NetBSD: job.c,v 1.188 2016/08/26 23:28:39 dholland Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: job.c,v 1.187 2016/05/12 20:28:34 sjg Exp $"); +__RCSID("$NetBSD: job.c,v 1.188 2016/08/26 23:28:39 dholland Exp $"); #endif #endif /* not lint */ #endif @@ -375,6 +375,21 @@ job_table_dump(const char *where) } /* + * Delete the target of a failed, interrupted, or otherwise + * unsuccessful job unless inhibited by .PRECIOUS. + */ +static void +JobDeleteTarget(GNode *gn) +{ + if ((gn->type & (OP_JOIN|OP_PHONY)) == 0 && !Targ_Precious(gn)) { + char *file = (gn->path == NULL ? gn->name : gn->path); + if (!noExecute && eunlink(file) != -1) { + Error("*** %s removed", file); + } + } +} + +/* * JobSigLock/JobSigUnlock * * Signal lock routines to get exclusive access. Currently used to @@ -1020,6 +1035,9 @@ JobFinish(Job *job, int status) if (job->flags & JOB_IGNERR) { status = 0; } else { + if (deleteOnError) { + JobDeleteTarget(job->node); + } PrintOnError(job->node, NULL); } } else if (DEBUG(JOB)) { @@ -1037,6 +1055,9 @@ JobFinish(Job *job, int status) } (void)printf("*** [%s] Signal %d\n", job->node->name, WTERMSIG(status)); + if (deleteOnError) { + JobDeleteTarget(job->node); + } } (void)fflush(stdout); } @@ -2562,12 +2583,7 @@ JobInterrupt(int runINTERRUPT, int signo gn = job->node; - if ((gn->type & (OP_JOIN|OP_PHONY)) == 0 && !Targ_Precious(gn)) { - char *file = (gn->path == NULL ? gn->name : gn->path); - if (!noExecute && eunlink(file) != -1) { - Error("*** %s removed", file); - } - } + JobDeleteTarget(gn); if (job->pid) { if (DEBUG(JOB)) { (void)fprintf(debug_file, Index: src/usr.bin/make/main.c diff -u src/usr.bin/make/main.c:1.250 src/usr.bin/make/main.c:1.251 --- src/usr.bin/make/main.c:1.250 Thu Aug 11 19:53:17 2016 +++ src/usr.bin/make/main.c Fri Aug 26 23:28:39 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.250 2016/08/11 19:53:17 sjg Exp $ */ +/* $NetBSD: main.c,v 1.251 2016/08/26 23:28:39 dholland Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,7 +69,7 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: main.c,v 1.250 2016/08/11 19:53:17 sjg Exp $"; +static char rcsid[] = "$NetBSD: main.c,v 1.251 2016/08/26 23:28:39 dholland Exp $"; #else #include <sys/cdefs.h> #ifndef lint @@ -81,7 +81,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19 #if 0 static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: main.c,v 1.250 2016/08/11 19:53:17 sjg Exp $"); +__RCSID("$NetBSD: main.c,v 1.251 2016/08/26 23:28:39 dholland Exp $"); #endif #endif /* not lint */ #endif @@ -151,6 +151,7 @@ Lst create; /* Targets to be made */ time_t now; /* Time at start of make */ GNode *DEFAULT; /* .DEFAULT node */ Boolean allPrecious; /* .PRECIOUS given on line by itself */ +Boolean deleteOnError; /* .DELETE_ON_ERROR: set */ static Boolean noBuiltins; /* -r flag */ static Lst makefiles; /* ordered list of makefiles to read */ @@ -944,6 +945,7 @@ main(int argc, char **argv) noRecursiveExecute = FALSE; /* Execute all .MAKE targets */ keepgoing = FALSE; /* Stop on error */ allPrecious = FALSE; /* Remove targets when interrupted */ + deleteOnError = FALSE; /* Historical default behavior */ queryFlag = FALSE; /* This is not just a check-run */ noBuiltins = FALSE; /* Read the built-in rules */ touchFlag = FALSE; /* Actually update targets */ Index: src/usr.bin/make/make.h diff -u src/usr.bin/make/make.h:1.100 src/usr.bin/make/make.h:1.101 --- src/usr.bin/make/make.h:1.100 Tue Jun 7 00:40:00 2016 +++ src/usr.bin/make/make.h Fri Aug 26 23:28:39 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: make.h,v 1.100 2016/06/07 00:40:00 sjg Exp $ */ +/* $NetBSD: make.h,v 1.101 2016/08/26 23:28:39 dholland Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -373,6 +373,7 @@ extern Boolean beSilent; /* True if extern Boolean noExecute; /* True if should execute nothing */ extern Boolean noRecursiveExecute; /* True if should execute nothing */ extern Boolean allPrecious; /* True if every target is precious */ +extern Boolean deleteOnError; /* True if failed targets should be deleted */ extern Boolean keepgoing; /* True if should continue on unaffected * portions of the graph when have an error * in one portion */ Index: src/usr.bin/make/parse.c diff -u src/usr.bin/make/parse.c:1.214 src/usr.bin/make/parse.c:1.215 --- src/usr.bin/make/parse.c:1.214 Wed Apr 6 09:57:00 2016 +++ src/usr.bin/make/parse.c Fri Aug 26 23:28:39 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.214 2016/04/06 09:57:00 gson Exp $ */ +/* $NetBSD: parse.c,v 1.215 2016/08/26 23:28:39 dholland Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: parse.c,v 1.214 2016/04/06 09:57:00 gson Exp $"; +static char rcsid[] = "$NetBSD: parse.c,v 1.215 2016/08/26 23:28:39 dholland Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: parse.c,v 1.214 2016/04/06 09:57:00 gson Exp $"); +__RCSID("$NetBSD: parse.c,v 1.215 2016/08/26 23:28:39 dholland Exp $"); #endif #endif /* not lint */ #endif @@ -181,6 +181,7 @@ typedef struct IFile { typedef enum { Begin, /* .BEGIN */ Default, /* .DEFAULT */ + DeleteOnError, /* .DELETE_ON_ERROR */ End, /* .END */ dotError, /* .ERROR */ Ignore, /* .IGNORE */ @@ -298,6 +299,7 @@ static const struct { } parseKeywords[] = { { ".BEGIN", Begin, 0 }, { ".DEFAULT", Default, 0 }, +{ ".DELETE_ON_ERROR", DeleteOnError, 0 }, { ".END", End, 0 }, { ".ERROR", dotError, 0 }, { ".EXEC", Attribute, OP_EXEC }, @@ -1320,6 +1322,7 @@ ParseDoDependency(char *line) * .BEGIN * .END * .ERROR + * .DELETE_ON_ERROR * .INTERRUPT Are not to be considered the * main target. * .NOTPARALLEL Make only one target at a time. @@ -1355,6 +1358,9 @@ ParseDoDependency(char *line) (void)Lst_AtEnd(targets, gn); DEFAULT = gn; break; + case DeleteOnError: + deleteOnError = TRUE; + break; case NotParallel: maxJobs = 1; break; @@ -1583,7 +1589,8 @@ ParseDoDependency(char *line) goto out; } *line = '\0'; - } else if ((specType == NotParallel) || (specType == SingleShell)) { + } else if ((specType == NotParallel) || (specType == SingleShell) || + (specType == DeleteOnError)) { *line = '\0'; }