Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make Add a .DELETE_ON_ERROR: magic target that cause...



details:   https://anonhg.NetBSD.org/src/rev/39f4d4a96006
branches:  trunk
changeset: 347451:39f4d4a96006
user:      dholland <dholland%NetBSD.org@localhost>
date:      Fri Aug 26 23:28:39 2016 +0000

description:
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.

diffstat:

 usr.bin/make/compat.c |  51 +++++++++++++++++++++++++++++++++++----------------
 usr.bin/make/job.c    |  34 +++++++++++++++++++++++++---------
 usr.bin/make/main.c   |   8 +++++---
 usr.bin/make/make.h   |   3 ++-
 usr.bin/make/parse.c  |  15 +++++++++++----
 5 files changed, 78 insertions(+), 33 deletions(-)

diffs (truncated from 340 to 300 lines):

diff -r a60e78c547e9 -r 39f4d4a96006 usr.bin/make/compat.c
--- a/usr.bin/make/compat.c     Fri Aug 26 23:12:06 2016 +0000
+++ b/usr.bin/make/compat.c     Fri Aug 26 23:28:39 2016 +0000
@@ -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       *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 @@
  *     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 @@
 {
     GNode   *gn;
 
-    if ((curTarg != NULL) && !Targ_Precious (curTarg)) {
-       char      *p1;
-       char      *file = Var_Value(TARGET, curTarg, &p1);
+    CompatDeleteTarget(curTarg);
 
-       if (!noExecute && eunlink(file) != -1) {
-           Error("*** %s removed", file);
-       }
-
-       free(p1);
-
+    if ((curTarg != NULL) && !Targ_Precious (curTarg)) {
        /*
         * Run .INTERRUPT only if hit with interrupt signal
         */
@@ -155,7 +170,6 @@
                Compat_Make(gn, gn);
            }
        }
-
     }
     if (signo == SIGQUIT)
        _exit(signo);
@@ -444,6 +458,11 @@
                         * continue.
                         */
                        printf(" (continuing)\n");
+                   } else {
+                       printf("\n");
+                   }
+                   if (deleteOnError) {
+                           CompatDeleteTarget(gn);
                    }
                } else {
                    /*
@@ -604,7 +623,7 @@
        } 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 @@
        if (gn != NULL) {
            Compat_Make(gn, gn);
             if (gn->made == ERROR) {
-                PrintOnError(gn, "\n\nStop.");
+                PrintOnError(gn, "\nStop.");
                 exit(1);
             }
        }
@@ -736,7 +755,7 @@
     if (errors == 0) {
        Compat_Make(ENDNode, ENDNode);
        if (gn->made == ERROR) {
-           PrintOnError(gn, "\n\nStop.");
+           PrintOnError(gn, "\nStop.");
            exit(1);
        }
     }
diff -r a60e78c547e9 -r 39f4d4a96006 usr.bin/make/job.c
--- a/usr.bin/make/job.c        Fri Aug 26 23:12:06 2016 +0000
+++ b/usr.bin/make/job.c        Fri Aug 26 23:28:39 2016 +0000
@@ -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 @@
 }
 
 /*
+ * 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 @@
                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 @@
            }
            (void)printf("*** [%s] Signal %d\n",
                        job->node->name, WTERMSIG(status));
+           if (deleteOnError) {
+               JobDeleteTarget(job->node);
+           }
        }
        (void)fflush(stdout);
     }
@@ -2562,12 +2583,7 @@
 
        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,
diff -r a60e78c547e9 -r 39f4d4a96006 usr.bin/make/main.c
--- a/usr.bin/make/main.c       Fri Aug 26 23:12:06 2016 +0000
+++ b/usr.bin/make/main.c       Fri Aug 26 23:28:39 2016 +0000
@@ -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 @@
 #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 @@
 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 @@
        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 */
diff -r a60e78c547e9 -r 39f4d4a96006 usr.bin/make/make.h
--- a/usr.bin/make/make.h       Fri Aug 26 23:12:06 2016 +0000
+++ b/usr.bin/make/make.h       Fri Aug 26 23:28:39 2016 +0000
@@ -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  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 */
diff -r a60e78c547e9 -r 39f4d4a96006 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Fri Aug 26 23:12:06 2016 +0000
+++ b/usr.bin/make/parse.c      Fri Aug 26 23:28:39 2016 +0000
@@ -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 enum {
     Begin,         /* .BEGIN */
     Default,       /* .DEFAULT */



Home | Main Index | Thread Index | Old Index