Module Name:    src
Committed By:   rillig
Date:           Sat Dec 12 10:21:50 UTC 2020

Modified Files:
        src/usr.bin/make: job.c job.h trace.c
        src/usr.bin/make/unit-tests: opt-debug-jobs.exp

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.373 -r1.374 src/usr.bin/make/job.c
cvs rdiff -u -r1.68 -r1.69 src/usr.bin/make/job.h
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/make/trace.c
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/make/unit-tests/opt-debug-jobs.exp

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/job.c
diff -u src/usr.bin/make/job.c:1.373 src/usr.bin/make/job.c:1.374
--- src/usr.bin/make/job.c:1.373	Sat Dec 12 10:05:15 2020
+++ src/usr.bin/make/job.c	Sat Dec 12 10:21:50 2020
@@ -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 CommandFlags {
  */
 typedef struct ShellWriter {
 	FILE *f;
+
+	/* we've sent 'set -x' */
+	Boolean xtraced;
+
 } ShellWriter;
 
 /*
@@ -465,18 +469,17 @@ nfds_per_job(void)
 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_EchoOn(ShellWriter *wr)
 		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 @@ JobPrintCommand(Job *job, ShellWriter *w
 		}
 	}
 
-	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 @@ JobPrintCommands(Job *job)
 {
 	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 @@ JobExec(Job *job, char **argv)
 	int cpid;		/* ID of new child */
 	sigset_t mask;
 
-	job->xtraced = FALSE;
-
 	if (DEBUG(JOB)) {
 		int i;
 
@@ -1628,7 +1636,6 @@ JobStart(GNode *gn, Boolean special)
 	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

Index: src/usr.bin/make/job.h
diff -u src/usr.bin/make/job.h:1.68 src/usr.bin/make/job.h:1.69
--- src/usr.bin/make/job.h:1.68	Sat Dec 12 01:42:33 2020
+++ src/usr.bin/make/job.h	Sat Dec 12 10:21:50 2020
@@ -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 @@ typedef struct Job {
     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 */

Index: src/usr.bin/make/trace.c
diff -u src/usr.bin/make/trace.c:1.23 src/usr.bin/make/trace.c:1.24
--- src/usr.bin/make/trace.c:1.23	Thu Dec 10 21:33:25 2020
+++ src/usr.bin/make/trace.c	Sat Dec 12 10:21:50 2020
@@ -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 @@ Trace_Log(TrEvent event, Job *job)
 	    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,

Index: src/usr.bin/make/unit-tests/opt-debug-jobs.exp
diff -u src/usr.bin/make/unit-tests/opt-debug-jobs.exp:1.9 src/usr.bin/make/unit-tests/opt-debug-jobs.exp:1.10
--- src/usr.bin/make/unit-tests/opt-debug-jobs.exp:1.9	Thu Dec 10 20:49:11 2020
+++ src/usr.bin/make/unit-tests/opt-debug-jobs.exp	Sat Dec 12 10:21:50 2020
@@ -16,7 +16,7 @@ Running all
 	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

Reply via email to