Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make make(1): move Job.xtraced to ShellWriter



details:   https://anonhg.NetBSD.org/src/rev/7b234f9b4b19
branches:  trunk
changeset: 957817:7b234f9b4b19
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Dec 12 10:21:50 2020 +0000

description:
make(1): move Job.xtraced to ShellWriter

This flag was placed wrong in the Job since it is only necessary as long
as the shell commands are written to the shell file.

Resetting it in JobStart and JobExec was completely misguided since that
is far away from writing the shell commands; this should have been done
in JobPrintCommands instead.

The status of this flag doesn't need to be printed in debugging mode
since it is controlled by a single command line option (-dx) and does
not interact with all the other switches.

diffstat:

 usr.bin/make/job.c                         |  35 ++++++++++++++++++------------
 usr.bin/make/job.h                         |   4 +--
 usr.bin/make/trace.c                       |   6 ++--
 usr.bin/make/unit-tests/opt-debug-jobs.exp |   2 +-
 4 files changed, 26 insertions(+), 21 deletions(-)

diffs (163 lines):

diff -r 923564c6897c -r 7b234f9b4b19 usr.bin/make/job.c
--- a/usr.bin/make/job.c        Sat Dec 12 10:05:15 2020 +0000
+++ b/usr.bin/make/job.c        Sat Dec 12 10:21:50 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.c,v 1.373 2020/12/12 10:05:15 rillig Exp $ */
+/*     $NetBSD: job.c,v 1.374 2020/12/12 10:21:50 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -143,7 +143,7 @@
 #include "trace.h"
 
 /*     "@(#)job.c      8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: job.c,v 1.373 2020/12/12 10:05:15 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.374 2020/12/12 10:21:50 rillig Exp $");
 
 /*
  * A shell defines how the commands are run.  All commands for a target are
@@ -238,6 +238,10 @@
  */
 typedef struct ShellWriter {
        FILE *f;
+
+       /* we've sent 'set -x' */
+       Boolean xtraced;
+
 } ShellWriter;
 
 /*
@@ -465,18 +469,17 @@
 void
 Job_FlagsToString(const Job *job, char *buf, size_t bufsize)
 {
-       snprintf(buf, bufsize, "%c%c%c%c",
+       snprintf(buf, bufsize, "%c%c%c",
            job->ignerr ? 'i' : '-',
            !job->echo ? 's' : '-',
-           job->special ? 'S' : '-',
-           job->xtraced ? 'x' : '-');
+           job->special ? 'S' : '-');
 }
 
 static void
 job_table_dump(const char *where)
 {
        Job *job;
-       char flags[5];
+       char flags[4];
 
        debug_printf("job table @ %s\n", where);
        for (job = job_table; job < job_table_end; job++) {
@@ -791,6 +794,15 @@
                ShellWriter_Println(wr, shell->echoOn);
 }
 
+static void
+ShellWriter_TraceOn(ShellWriter *wr)
+{
+       if (!wr->xtraced) {
+               ShellWriter_Println(wr, "set -x");
+               wr->xtraced = TRUE;
+       }
+}
+
 /*
  * We don't want the error-control commands showing up either, so we turn
  * off echoing while executing them. We could put another field in the shell
@@ -949,10 +961,8 @@
                }
        }
 
-       if (DEBUG(SHELL) && strcmp(shellName, "sh") == 0 && !job->xtraced) {
-               ShellWriter_Println(wr, "set -x");
-               job->xtraced = TRUE;
-       }
+       if (DEBUG(SHELL) && strcmp(shellName, "sh") == 0)
+               ShellWriter_TraceOn(wr);
 
        ShellWriter_PrintCmd(wr, cmdTemplate, xcmd);
        free(xcmdStart);
@@ -986,7 +996,7 @@
 {
        StringListNode *ln;
        Boolean seen = FALSE;
-       ShellWriter wr = { job->cmdFILE };
+       ShellWriter wr = { job->cmdFILE, FALSE };
 
        for (ln = job->node->commands.first; ln != NULL; ln = ln->next) {
                const char *cmd = ln->datum;
@@ -1337,8 +1347,6 @@
        int cpid;               /* ID of new child */
        sigset_t mask;
 
-       job->xtraced = FALSE;
-
        if (DEBUG(JOB)) {
                int i;
 
@@ -1628,7 +1636,6 @@
        job->special = special || gn->type & OP_SPECIAL;
        job->ignerr = opts.ignoreErrors || gn->type & OP_IGNORE;
        job->echo = !(opts.beSilent || gn->type & OP_SILENT);
-       job->xtraced = FALSE;
 
        /*
         * Check the commands now so any attributes from .DEFAULT have a
diff -r 923564c6897c -r 7b234f9b4b19 usr.bin/make/job.h
--- a/usr.bin/make/job.h        Sat Dec 12 10:05:15 2020 +0000
+++ b/usr.bin/make/job.h        Sat Dec 12 10:21:50 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.h,v 1.68 2020/12/12 01:42:33 rillig Exp $  */
+/*     $NetBSD: job.h,v 1.69 2020/12/12 10:21:50 rillig Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -163,8 +163,6 @@
     Boolean echo;
     /* Target is a special one. */
     Boolean special;
-    /* we've sent 'set -x' */
-    Boolean xtraced;
 
     int inPipe;                        /* Pipe for reading output from job */
     int outPipe;               /* Pipe for writing control commands */
diff -r 923564c6897c -r 7b234f9b4b19 usr.bin/make/trace.c
--- a/usr.bin/make/trace.c      Sat Dec 12 10:05:15 2020 +0000
+++ b/usr.bin/make/trace.c      Sat Dec 12 10:21:50 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trace.c,v 1.23 2020/12/10 21:33:25 rillig Exp $        */
+/*     $NetBSD: trace.c,v 1.24 2020/12/12 10:21:50 rillig Exp $        */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
 #include "job.h"
 #include "trace.h"
 
-MAKE_RCSID("$NetBSD: trace.c,v 1.23 2020/12/10 21:33:25 rillig Exp $");
+MAKE_RCSID("$NetBSD: trace.c,v 1.24 2020/12/12 10:21:50 rillig Exp $");
 
 static FILE *trfile;
 static pid_t trpid;
@@ -92,7 +92,7 @@
            jobTokensRunning,
            evname[event], trpid, trwd);
        if (job != NULL) {
-               char flags[5];
+               char flags[4];
 
                Job_FlagsToString(job, flags, sizeof flags);
                fprintf(trfile, " %s %d %s %x", job->node->name,
diff -r 923564c6897c -r 7b234f9b4b19 usr.bin/make/unit-tests/opt-debug-jobs.exp
--- a/usr.bin/make/unit-tests/opt-debug-jobs.exp        Sat Dec 12 10:05:15 2020 +0000
+++ b/usr.bin/make/unit-tests/opt-debug-jobs.exp        Sat Dec 12 10:21:50 2020 +0000
@@ -16,7 +16,7 @@
        Command: <shell> 
 JobExec(all): pid <pid> added to jobs table
 job table @ job started
-job 0, status 3, flags ----, pid <pid>
+job 0, status 3, flags ---, pid <pid>
 : expanded expression
 :  variable
 : 'single' and "double" quotes



Home | Main Index | Thread Index | Old Index