Module Name: src
Committed By: rillig
Date: Fri Jan 5 23:22:06 UTC 2024
Modified Files:
src/usr.bin/make: compat.c job.c main.c make.c parse.c str.c suff.c
var.c
Log Message:
make: miscellaneous cleanups
To generate a diff of this commit:
cvs rdiff -u -r1.251 -r1.252 src/usr.bin/make/compat.c
cvs rdiff -u -r1.462 -r1.463 src/usr.bin/make/job.c
cvs rdiff -u -r1.607 -r1.608 src/usr.bin/make/main.c
cvs rdiff -u -r1.261 -r1.262 src/usr.bin/make/make.c
cvs rdiff -u -r1.714 -r1.715 src/usr.bin/make/parse.c
cvs rdiff -u -r1.101 -r1.102 src/usr.bin/make/str.c
cvs rdiff -u -r1.376 -r1.377 src/usr.bin/make/suff.c
cvs rdiff -u -r1.1092 -r1.1093 src/usr.bin/make/var.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.251 src/usr.bin/make/compat.c:1.252
--- src/usr.bin/make/compat.c:1.251 Tue Dec 26 20:09:42 2023
+++ src/usr.bin/make/compat.c Fri Jan 5 23:22:06 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: compat.c,v 1.251 2023/12/26 20:09:42 sjg Exp $ */
+/* $NetBSD: compat.c,v 1.252 2024/01/05 23:22:06 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -91,7 +91,7 @@
#include "pathnames.h"
/* "@(#)compat.c 8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: compat.c,v 1.251 2023/12/26 20:09:42 sjg Exp $");
+MAKE_RCSID("$NetBSD: compat.c,v 1.252 2024/01/05 23:22:06 rillig Exp $");
static GNode *curTarg = NULL;
static pid_t compatChild;
@@ -107,10 +107,8 @@ CompatDeleteTarget(GNode *gn)
if (gn != NULL && !GNode_IsPrecious(gn) &&
(gn->type & OP_PHONY) == 0) {
const char *file = GNode_VarTarget(gn);
-
- if (!opts.noExecute && unlink_file(file) == 0) {
+ if (!opts.noExecute && unlink_file(file) == 0)
Error("*** %s removed", file);
- }
}
}
@@ -132,9 +130,8 @@ CompatInterrupt(int signo)
/* Run .INTERRUPT only if hit with interrupt signal. */
if (signo == SIGINT) {
GNode *gn = Targ_FindNode(".INTERRUPT");
- if (gn != NULL) {
+ if (gn != NULL)
Compat_Make(gn, gn);
- }
}
}
@@ -360,9 +357,8 @@ Compat_RunCommand(const char *cmdp, GNod
while ((retstat = wait(&reason)) != cpid) {
if (retstat > 0)
JobReapChild(retstat, reason, false); /* not ours? */
- if (retstat == -1 && errno != EINTR) {
+ if (retstat == -1 && errno != EINTR)
break;
- }
}
if (retstat < 0)
Index: src/usr.bin/make/job.c
diff -u src/usr.bin/make/job.c:1.462 src/usr.bin/make/job.c:1.463
--- src/usr.bin/make/job.c:1.462 Fri Dec 29 12:59:43 2023
+++ src/usr.bin/make/job.c Fri Jan 5 23:22:06 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: job.c,v 1.462 2023/12/29 12:59:43 rillig Exp $ */
+/* $NetBSD: job.c,v 1.463 2024/01/05 23:22:06 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -141,7 +141,7 @@
#include "trace.h"
/* "@(#)job.c 8.2 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: job.c,v 1.462 2023/12/29 12:59:43 rillig Exp $");
+MAKE_RCSID("$NetBSD: job.c,v 1.463 2024/01/05 23:22:06 rillig Exp $");
/*
* A shell defines how the commands are run. All commands for a target are
@@ -928,12 +928,10 @@ JobWriteCommand(Job *job, ShellWriter *w
escCmd = shell->hasErrCtl ? NULL : EscapeShellDblQuot(xcmd);
if (!cmdFlags.echo) {
- if (job->echo && run && shell->hasEchoCtl) {
+ if (job->echo && run && shell->hasEchoCtl)
ShellWriter_EchoOff(wr);
- } else {
- if (shell->hasErrCtl)
- cmdFlags.echo = true;
- }
+ else if (shell->hasErrCtl)
+ cmdFlags.echo = true;
}
if (cmdFlags.ignerr) {
@@ -2182,11 +2180,10 @@ Shell_GetNewline(void)
void
Job_SetPrefix(void)
{
- if (targPrefix != NULL) {
+ if (targPrefix != NULL)
free(targPrefix);
- } else if (!Var_Exists(SCOPE_GLOBAL, ".MAKE.JOB.PREFIX")) {
+ else if (!Var_Exists(SCOPE_GLOBAL, ".MAKE.JOB.PREFIX"))
Global_Set(".MAKE.JOB.PREFIX", "---");
- }
targPrefix = Var_Subst("${.MAKE.JOB.PREFIX}",
SCOPE_GLOBAL, VARE_WANTRES);
@@ -2484,18 +2481,9 @@ Job_ParseShell(char *line)
* its word and copy it to a new location. In either case,
* we need to record the path the user gave for the shell.
*/
+ char *name = path + (str_basename(path) - path);
shellPath = path;
- path = strrchr(path, '/');
- if (path == NULL) {
- path = UNCONST(shellPath);
- } else {
- path++;
- }
- if (newShell.name != NULL) {
- shellName = newShell.name;
- } else {
- shellName = path;
- }
+ shellName = newShell.name != NULL ? newShell.name : name;
if (!fullSpec) {
if ((sh = FindShellByName(shellName)) == NULL) {
Parse_Error(PARSE_WARNING,
@@ -2592,11 +2580,10 @@ Job_Finish(void)
GNode *endNode = Targ_GetEndNode();
if (!Lst_IsEmpty(&endNode->commands) ||
!Lst_IsEmpty(&endNode->children)) {
- if (job_errors != 0) {
+ if (job_errors != 0)
Error("Errors reported so .END ignored");
- } else {
+ else
JobRun(endNode);
- }
}
return job_errors;
}
@@ -2867,9 +2854,8 @@ Job_TokenWithdraw(void)
if (count == 0)
Fatal("eof on job pipe!");
if (count < 0 && jobTokensRunning != 0) {
- if (errno != EAGAIN) {
+ if (errno != EAGAIN)
Fatal("job pipe read: %s", strerror(errno));
- }
DEBUG1(JOB, "(%d) blocked for token\n", getpid());
wantToken = 1;
return false;
Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.607 src/usr.bin/make/main.c:1.608
--- src/usr.bin/make/main.c:1.607 Fri Jan 5 22:20:07 2024
+++ src/usr.bin/make/main.c Fri Jan 5 23:22:06 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.607 2024/01/05 22:20:07 sjg Exp $ */
+/* $NetBSD: main.c,v 1.608 2024/01/05 23:22:06 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -111,7 +111,7 @@
#include "trace.h"
/* "@(#)main.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: main.c,v 1.607 2024/01/05 22:20:07 sjg Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.608 2024/01/05 23:22:06 rillig Exp $");
#if defined(MAKE_NATIVE)
__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
"The Regents of the University of California. "
@@ -222,8 +222,7 @@ MainParseArgDebugFile(const char *arg)
opts.debug_file = fopen(fname, mode);
if (opts.debug_file == NULL) {
- fprintf(stderr, "Cannot open debug file \"%s\"\n",
- fname);
+ fprintf(stderr, "Cannot open debug file \"%s\"\n", fname);
exit(2);
}
free(fname);
@@ -408,9 +407,9 @@ MainParseArgJobs(const char *arg)
if (*p != '\0') {
double d;
- if (*p == 'C') {
+ if (*p == 'C')
d = (opts.maxJobs > 0) ? opts.maxJobs : 1;
- } else if (*p == '.') {
+ else if (*p == '.') {
d = strtod(arg, &end);
p = end;
} else
Index: src/usr.bin/make/make.c
diff -u src/usr.bin/make/make.c:1.261 src/usr.bin/make/make.c:1.262
--- src/usr.bin/make/make.c:1.261 Fri Dec 29 18:53:24 2023
+++ src/usr.bin/make/make.c Fri Jan 5 23:22:06 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: make.c,v 1.261 2023/12/29 18:53:24 rillig Exp $ */
+/* $NetBSD: make.c,v 1.262 2024/01/05 23:22:06 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -104,7 +104,7 @@
#include "job.h"
/* "@(#)make.c 8.1 (Berkeley) 6/6/93" */
-MAKE_RCSID("$NetBSD: make.c,v 1.261 2023/12/29 18:53:24 rillig Exp $");
+MAKE_RCSID("$NetBSD: make.c,v 1.262 2024/01/05 23:22:06 rillig Exp $");
/* Sequence # to detect recursion. */
static unsigned int checked_seqno = 1;
@@ -330,13 +330,12 @@ GNode_IsOODate(GNode *gn)
* out-of-date.
*/
if (DEBUG(MAKE)) {
- if (gn->type & OP_FORCE) {
+ if (gn->type & OP_FORCE)
debug_printf("! operator...");
- } else if (gn->type & OP_PHONY) {
+ else if (gn->type & OP_PHONY)
debug_printf(".PHONY node...");
- } else {
+ else
debug_printf(".EXEC node...");
- }
}
oodate = true;
} else if (IsOODateRegular(gn)) {
@@ -440,11 +439,10 @@ Make_HandleUse(GNode *cgn, GNode *pgn)
* We don't need to do this for commands.
* They get expanded properly when we execute.
*/
- if (gn->uname == NULL) {
+ if (gn->uname == NULL)
gn->uname = gn->name;
- } else {
+ else
free(gn->name);
- }
gn->name = Var_Subst(gn->uname, pgn, VARE_WANTRES);
/* TODO: handle errors */
if (gn->uname != NULL && strcmp(gn->name, gn->uname) != 0) {
@@ -546,9 +544,8 @@ Make_Recheck(GNode *gn)
* depend on FRC to be made, so we have to check for gn->children
* being empty as well.
*/
- if (!Lst_IsEmpty(gn->commands) || Lst_IsEmpty(gn->children)) {
+ if (!Lst_IsEmpty(gn->commands) || Lst_IsEmpty(gn->children))
gn->mtime = now;
- }
#else
/*
* This is what Make does and it's actually a good thing, as it
@@ -689,9 +686,8 @@ Make_Update(GNode *cgn)
* now -- some rules won't actually update the file. If the file
* still doesn't exist, make its mtime now.
*/
- if (cgn->made != UPTODATE) {
+ if (cgn->made != UPTODATE)
mtime = Make_Recheck(cgn);
- }
/*
* If this is a `::' node, we must consult its first instance
Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.714 src/usr.bin/make/parse.c:1.715
--- src/usr.bin/make/parse.c:1.714 Wed Jan 3 20:24:16 2024
+++ src/usr.bin/make/parse.c Fri Jan 5 23:22:06 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.714 2024/01/03 20:24:16 sjg Exp $ */
+/* $NetBSD: parse.c,v 1.715 2024/01/05 23:22:06 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -105,7 +105,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.714 2024/01/03 20:24:16 sjg Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.715 2024/01/05 23:22:06 rillig Exp $");
/* Detects a multiple-inclusion guard in a makefile. */
typedef enum {
@@ -336,7 +336,7 @@ GetInclude(size_t i)
return Vector_Get(&includes, i);
}
-/* The makefile that is currently being read. */
+/* The makefile or the body of a .for loop that is currently being read. */
static IncludedFile *
CurFile(void)
{
Index: src/usr.bin/make/str.c
diff -u src/usr.bin/make/str.c:1.101 src/usr.bin/make/str.c:1.102
--- src/usr.bin/make/str.c:1.101 Sun Dec 17 22:46:44 2023
+++ src/usr.bin/make/str.c Fri Jan 5 23:22:06 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: str.c,v 1.101 2023/12/17 22:46:44 rillig Exp $ */
+/* $NetBSD: str.c,v 1.102 2024/01/05 23:22:06 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -71,7 +71,7 @@
#include "make.h"
/* "@(#)str.c 5.8 (Berkeley) 6/1/90" */
-MAKE_RCSID("$NetBSD: str.c,v 1.101 2023/12/17 22:46:44 rillig Exp $");
+MAKE_RCSID("$NetBSD: str.c,v 1.102 2024/01/05 23:22:06 rillig Exp $");
static HashTable interned_strings;
@@ -107,6 +107,10 @@ str_concat3(const char *s1, const char *
* Fracture a string into an array of words (as delineated by tabs or spaces)
* taking quotation marks into account.
*
+ * A string that is empty or only contains whitespace nevertheless results in
+ * a single word. This is unexpected in many places, and the caller needs to
+ * correct for this edge case.
+ *
* If expand is true, quotes are removed and escape sequences such as \r, \t,
* etc... are expanded. In this case, return NULL on parse errors.
*
Index: src/usr.bin/make/suff.c
diff -u src/usr.bin/make/suff.c:1.376 src/usr.bin/make/suff.c:1.377
--- src/usr.bin/make/suff.c:1.376 Sat Dec 30 15:00:56 2023
+++ src/usr.bin/make/suff.c Fri Jan 5 23:22:06 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: suff.c,v 1.376 2023/12/30 15:00:56 rillig Exp $ */
+/* $NetBSD: suff.c,v 1.377 2024/01/05 23:22:06 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -115,7 +115,7 @@
#include "dir.h"
/* "@(#)suff.c 8.4 (Berkeley) 3/21/94" */
-MAKE_RCSID("$NetBSD: suff.c,v 1.376 2023/12/30 15:00:56 rillig Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.377 2024/01/05 23:22:06 rillig Exp $");
typedef List SuffixList;
typedef ListNode SuffixListNode;
@@ -1281,8 +1281,7 @@ ExpandChildrenRegular(char *p, GNode *pg
/* TODO: handle errors */
if (junk.str == var_Error) {
Parse_Error(PARSE_FATAL,
- "Malformed expression at \"%s\"",
- p);
+ "Malformed expression at \"%s\"", p);
p++;
} else {
p += nested_p - p;
@@ -1917,8 +1916,7 @@ FindDepsRegular(GNode *gn, CandidateSear
if (targ->node == NULL)
targ->node = Targ_GetNode(targ->file);
- ApplyTransform(targ->node, src->node,
- targ->suff, src->suff);
+ ApplyTransform(targ->node, src->node, targ->suff, src->suff);
if (targ->node != gn) {
/*
Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.1092 src/usr.bin/make/var.c:1.1093
--- src/usr.bin/make/var.c:1.1092 Fri Jan 5 21:56:55 2024
+++ src/usr.bin/make/var.c Fri Jan 5 23:22:06 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.1092 2024/01/05 21:56:55 rillig Exp $ */
+/* $NetBSD: var.c,v 1.1093 2024/01/05 23:22:06 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1092 2024/01/05 21:56:55 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1093 2024/01/05 23:22:06 rillig Exp $");
/*
* Variables are defined using one of the VAR=value assignments. Their
@@ -1596,7 +1596,6 @@ ModifyWord_Loop(Substring word, SepBuf *
s = Var_Subst(args->body, args->scope, args->emode);
/* TODO: handle errors */
- assert(word.end[0] == '\0'); /* assume null-terminated word */
DEBUG2(VAR, "ModifyWord_Loop: expand \"%s\" to \"%s\"\n",
args->body, s);
@@ -2001,7 +2000,7 @@ ModChain_ShouldEval(const ModChain *ch)
typedef enum ApplyModifierResult {
/* Continue parsing */
AMR_OK,
- /* Not a match, try other modifiers as well. */
+ /* Not a match, try the ':from=to' modifier as well. */
AMR_UNKNOWN,
/* Error out with "Bad modifier" message. */
AMR_BAD,
@@ -4287,11 +4286,11 @@ ParseVarnameLong(
ParseVarname(&p, startc, endc, scope, emode, &varname);
name = LazyBuf_Get(&varname);
- if (*p == ':') {
+ if (*p == ':')
haveModifier = true;
- } else if (*p == endc) {
+ else if (*p == endc)
haveModifier = false;
- } else {
+ else {
Parse_Error(PARSE_FATAL, "Unclosed variable \"%.*s\"",
(int)Substring_Length(name), name.start);
LazyBuf_Done(&varname);
@@ -4399,10 +4398,9 @@ Var_Parse_FastLane(const char **pp, VarE
if (*p != '}')
return false;
- if (emode == VARE_PARSE_ONLY)
- *out_value = FStr_InitRefer("");
- else
- *out_value = FStr_InitOwn(bmake_strsedup(*pp + 4, p));
+ *out_value = emode == VARE_PARSE_ONLY
+ ? FStr_InitRefer("")
+ : FStr_InitOwn(bmake_strsedup(*pp + 4, p));
*pp = p + 1;
return true;
}