Module Name: src
Committed By: rillig
Date: Thu Dec 10 23:12:59 UTC 2020
Modified Files:
src/usr.bin/make: job.c
Log Message:
make(1): eliminate global variable numCommands
It had only been used in a very small scope. The elimination of
Lst_ForEach made it easy to turn this global variable into a local
variable.
To generate a diff of this commit:
cvs rdiff -u -r1.361 -r1.362 src/usr.bin/make/job.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/job.c
diff -u src/usr.bin/make/job.c:1.361 src/usr.bin/make/job.c:1.362
--- src/usr.bin/make/job.c:1.361 Thu Dec 10 23:03:00 2020
+++ src/usr.bin/make/job.c Thu Dec 10 23:12:59 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: job.c,v 1.361 2020/12/10 23:03:00 rillig Exp $ */
+/* $NetBSD: job.c,v 1.362 2020/12/10 23:12:59 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.361 2020/12/10 23:03:00 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.362 2020/12/10 23:12:59 rillig Exp $");
/*
* A shell defines how the commands are run. All commands for a target are
@@ -248,10 +248,6 @@ static AbortReason aborting = ABORT_NONE
*/
int jobTokensRunning = 0;
-/* The number of commands actually printed to the shell commands file for
- * the current job. Should this number be 0, no shell will be executed. */
-static int numCommands;
-
typedef enum JobStartResult {
JOB_RUNNING, /* Job is running */
JOB_ERROR, /* Error in starting the job */
@@ -853,8 +849,6 @@ JobPrintCommand(Job *job, char *cmd)
run = GNode_ShouldExecute(job->node);
- numCommands++;
-
Var_Subst(cmd, job->node, VARE_WANTRES, &cmd);
/* TODO: handle errors */
cmdStart = cmd;
@@ -952,11 +946,14 @@ JobPrintCommand(Job *job, char *cmd)
*
* The special command "..." stops printing and saves the remaining commands
* to be executed later.
+ *
+ * Return whether at least one command was written to the shell file.
*/
-static void
+static Boolean
JobPrintCommands(Job *job)
{
StringListNode *ln;
+ Boolean seen = FALSE;
for (ln = job->node->commands.first; ln != NULL; ln = ln->next) {
const char *cmd = ln->datum;
@@ -968,7 +965,10 @@ JobPrintCommands(Job *job)
}
JobPrintCommand(job, ln->datum);
+ seen = TRUE;
}
+
+ return seen;
}
/* Save the delayed commands, to be executed when everything else is done. */
@@ -1544,15 +1544,9 @@ JobOpenTmpFile(Job *job, GNode *gn, Bool
job->echo = FALSE;
}
#endif
- /* We can do all the commands at once. hooray for sanity */
- numCommands = 0;
- JobPrintCommands(job);
- /*
- * If we didn't print out any commands to the shell script,
- * there's no point in executing the shell.
- */
- if (numCommands == 0)
+ /* We can do all the commands at once. hooray for sanity */
+ if (!JobPrintCommands(job))
*out_run = FALSE;
free(tfile);