Module Name:    src
Committed By:   rillig
Date:           Mon Dec 27 18:54:19 UTC 2021

Modified Files:
        src/usr.bin/make: cond.c main.c parse.c
        src/usr.bin/make/unit-tests: cond-short.mk cond-token-number.exp
            cond-token-number.mk var-eval-short.exp var-eval-short.mk

Log Message:
make: clean up comments


To generate a diff of this commit:
cvs rdiff -u -r1.306 -r1.307 src/usr.bin/make/cond.c
cvs rdiff -u -r1.549 -r1.550 src/usr.bin/make/main.c
cvs rdiff -u -r1.584 -r1.585 src/usr.bin/make/parse.c
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/make/unit-tests/cond-short.mk
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/cond-token-number.exp
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/cond-token-number.mk
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/make/unit-tests/var-eval-short.exp
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/var-eval-short.mk

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/cond.c
diff -u src/usr.bin/make/cond.c:1.306 src/usr.bin/make/cond.c:1.307
--- src/usr.bin/make/cond.c:1.306	Wed Dec 15 12:58:01 2021
+++ src/usr.bin/make/cond.c	Mon Dec 27 18:54:19 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.306 2021/12/15 12:58:01 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.307 2021/12/27 18:54:19 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -95,7 +95,7 @@
 #include "dir.h"
 
 /*	"@(#)cond.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: cond.c,v 1.306 2021/12/15 12:58:01 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.307 2021/12/27 18:54:19 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -123,8 +123,8 @@ MAKE_RCSID("$NetBSD: cond.c,v 1.306 2021
  *	TOK_RPAREN	for ')'
  *
  * Other terminal symbols are evaluated using either the default function or
- * the function given in the terminal, they return either TOK_TRUE or
- * TOK_FALSE.
+ * the function given in the terminal, they return either TOK_TRUE, TOK_FALSE
+ * or TOK_ERROR.
  */
 typedef enum Token {
 	TOK_FALSE, TOK_TRUE, TOK_AND, TOK_OR, TOK_NOT,
@@ -450,12 +450,11 @@ CondParser_StringExpr(CondParser *par, c
 }
 
 /*
- * Parse a string from a variable expression or an optionally quoted
- * string.  This is called for the left-hand and right-hand sides of
- * comparisons.
+ * Parse a string from a variable expression or an optionally quoted string,
+ * on the left-hand and right-hand sides of comparisons.
  *
  * Results:
- *	Returns the string, absent any quotes, or NULL on error.
+ *	Returns the string without any enclosing quotes, or NULL on error.
  *	Sets out_quoted if the leaf was a quoted string literal.
  */
 static void

Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.549 src/usr.bin/make/main.c:1.550
--- src/usr.bin/make/main.c:1.549	Mon Dec 27 18:26:22 2021
+++ src/usr.bin/make/main.c	Mon Dec 27 18:54:19 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.549 2021/12/27 18:26:22 rillig Exp $	*/
+/*	$NetBSD: main.c,v 1.550 2021/12/27 18:54:19 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.549 2021/12/27 18:26:22 rillig Exp $");
+MAKE_RCSID("$NetBSD: main.c,v 1.550 2021/12/27 18:54:19 rillig Exp $");
 #if defined(MAKE_NATIVE) && !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 "
 	    "The Regents of the University of California.  "
@@ -178,10 +178,6 @@ explode(const char *flags)
 	return st;
 }
 
-/*
- * usage --
- *	exit with usage message
- */
 MAKE_ATTR_DEAD static void
 usage(void)
 {
@@ -503,7 +499,7 @@ MainParseArg(char c, const char *argvalu
 		break;
 	case 'W':
 		opts.parseWarnFatal = true;
-		/* XXX: why no Var_Append? */
+		/* XXX: why no Global_Append? */
 		break;
 	case 'X':
 		opts.varNoExportEnv = true;
@@ -1075,13 +1071,13 @@ ignore_pwd:
 #endif
 
 /*
- * Find the .OBJDIR.  If MAKEOBJDIRPREFIX, or failing that,
- * MAKEOBJDIR is set in the environment, try only that value
- * and fall back to .CURDIR if it does not exist.
+ * Find the .OBJDIR.  If MAKEOBJDIRPREFIX, or failing that, MAKEOBJDIR is set
+ * in the environment, try only that value and fall back to .CURDIR if it
+ * does not exist.
  *
  * Otherwise, try _PATH_OBJDIR.MACHINE-MACHINE_ARCH, _PATH_OBJDIR.MACHINE,
- * and * finally _PATH_OBJDIRPREFIX`pwd`, in that order.  If none
- * of these paths exist, just use .CURDIR.
+ * and finally _PATH_OBJDIRPREFIX`pwd`, in that order.  If none of these
+ * paths exist, just use .CURDIR.
  */
 static void
 InitObjdir(const char *machine, const char *machine_arch)
@@ -1401,10 +1397,8 @@ main_Init(int argc, char **argv)
 	Global_Set("MAKE_VERSION", MAKE_VERSION);
 #endif
 	Global_Set(".newline", "\n");	/* handy for :@ loops */
-	/*
-	 * This is the traditional preference for makefiles.
-	 */
 #ifndef MAKEFILE_PREFERENCE_LIST
+	/* This is the traditional preference for makefiles. */
 # define MAKEFILE_PREFERENCE_LIST "makefile Makefile"
 #endif
 	Global_Set(MAKE_MAKEFILE_PREFERENCE, MAKEFILE_PREFERENCE_LIST);
@@ -1436,7 +1430,6 @@ main_Init(int argc, char **argv)
 	Global_Set(MAKEOVERRIDES, "");
 	Global_Set("MFLAGS", "");
 	Global_Set(".ALLTARGETS", "");
-	/* some makefiles need to know this */
 	Var_Set(SCOPE_CMDLINE, MAKE_LEVEL ".ENV", MAKE_LEVEL_ENV);
 
 	/* Set some other useful variables. */
@@ -1468,11 +1461,6 @@ main_Init(int argc, char **argv)
 #endif
 	Dir_Init();
 
-	/*
-	 * First snag any flags out of the MAKE environment variable.
-	 * (Note this is *not* MAKEFLAGS since /bin/make uses that and it's
-	 * in a different format).
-	 */
 #ifdef POSIX
 	{
 		char *p1 = explode(getenv("MAKEFLAGS"));
@@ -1480,13 +1468,14 @@ main_Init(int argc, char **argv)
 		free(p1);
 	}
 #else
+	/*
+	 * First snag any flags out of the MAKE environment variable.
+	 * (Note this is *not* MAKEFLAGS since /bin/make uses that and it's
+	 * in a different format).
+	 */
 	Main_ParseArgLine(getenv("MAKE"));
 #endif
 
-	/*
-	 * Find where we are (now).
-	 * We take care of PWD for the automounter below...
-	 */
 	if (getcwd(curdir, MAXPATHLEN) == NULL) {
 		(void)fprintf(stderr, "%s: getcwd: %s.\n",
 		    progname, strerror(errno));
@@ -1498,9 +1487,6 @@ main_Init(int argc, char **argv)
 	if (opts.enterFlag)
 		printf("%s: Entering directory `%s'\n", progname, curdir);
 
-	/*
-	 * Verify that cwd is sane.
-	 */
 	if (stat(curdir, &sa) == -1) {
 		(void)fprintf(stderr, "%s: %s: %s.\n",
 		    progname, curdir, strerror(errno));
@@ -1514,10 +1500,6 @@ main_Init(int argc, char **argv)
 
 	InitObjdir(machine, machine_arch);
 
-	/*
-	 * Initialize archive, target and suffix modules in preparation for
-	 * parsing the makefile(s)
-	 */
 	Arch_Init();
 	Suff_Init();
 	Trace_Init(tracefile);
@@ -1578,10 +1560,6 @@ main_PrepareMaking(void)
 
 	InitMaxJobs();
 
-	/*
-	 * Be compatible if the user did not specify -j and did not explicitly
-	 * turn compatibility on.
-	 */
 	if (!opts.compatMake && !forceJobs)
 		opts.compatMake = true;
 
@@ -1634,15 +1612,10 @@ main_CleanUp(void)
 {
 #ifdef CLEANUP
 	Lst_DoneCall(&opts.variables, free);
-	/*
-	 * Don't free the actual strings from opts.makefiles, they may be
-	 * used in GNodes.
-	 */
 	Lst_Done(&opts.makefiles);
 	Lst_DoneCall(&opts.create, free);
 #endif
 
-	/* print the graph now it's been processed if the user requested it */
 	if (DEBUG(GRAPH2))
 		Targ_PrintGraph(2);
 
@@ -1691,9 +1664,7 @@ main(int argc, char **argv)
 
 /*
  * Open and parse the given makefile, with all its side effects.
- *
- * Results:
- *	0 if ok. -1 if couldn't open file.
+ * Return -1 if the file could not be opened.
  */
 static int
 ReadMakefile(const char *fname)
@@ -1755,22 +1726,19 @@ found:
 }
 
 /*
- * Cmd_Exec --
- *	Execute the command in cmd, and return the output of that command
- *	in a string.  In the output, newlines are replaced with spaces.
+ * Execute the command in cmd, and return its output (only stdout, not
+ * stderr).  In the output, replace newlines with spaces.
  *
  * Results:
- *	A string containing the output of the command, or the empty string.
+ *	The output of the command, can be empty.
  *	*errfmt returns a format string describing the command failure,
  *	if any, using a single %s conversion specification.
- *
- * Side Effects:
- *	The string must be freed by the caller.
+ *	TODO: replace errfmt with an actual error message.
  */
 char *
 Cmd_Exec(const char *cmd, const char **errfmt)
 {
-	const char *args[4];	/* Args for invoking the shell */
+	const char *args[4];	/* Arguments for invoking the shell */
 	int pipefds[2];
 	int cpid;		/* Child PID */
 	int pid;		/* PID from wait() */
@@ -1786,17 +1754,12 @@ Cmd_Exec(const char *cmd, const char **e
 
 	if (shellName == NULL)
 		Shell_Init();
-	/*
-	 * Set up arguments for shell
-	 */
+
 	args[0] = shellName;
 	args[1] = "-c";
 	args[2] = cmd;
 	args[3] = NULL;
 
-	/*
-	 * Open a pipe for fetching its output
-	 */
 	if (pipe(pipefds) == -1) {
 		*errfmt = "Couldn't create pipe for \"%s\"";
 		goto bad;
@@ -1804,18 +1767,9 @@ Cmd_Exec(const char *cmd, const char **e
 
 	Var_ReexportVars();
 
-	/*
-	 * Fork
-	 */
 	switch (cpid = vfork()) {
 	case 0:
-		(void)close(pipefds[0]); /* Close input side of pipe */
-
-		/*
-		 * Duplicate the output stream to the shell's output, then
-		 * shut the extra thing down. Note we don't fetch the error
-		 * stream...why not? Why?
-		 */
+		(void)close(pipefds[0]);
 		(void)dup2(pipefds[1], 1);
 		(void)close(pipefds[1]);
 
@@ -1845,7 +1799,6 @@ Cmd_Exec(const char *cmd, const char **e
 
 		(void)close(pipefds[0]); /* Close the input side of the pipe. */
 
-		/* Wait for the process to exit. */
 		while ((pid = waitpid(cpid, &status, 0)) != cpid && pid >= 0)
 			JobReapChild(pid, status, false);
 
@@ -1860,10 +1813,7 @@ Cmd_Exec(const char *cmd, const char **e
 		else if (WEXITSTATUS(status) != 0)
 			*errfmt = "\"%s\" returned non-zero status";
 
-		/*
-		 * Convert newlines to spaces.  A final newline is just
-		 * stripped.
-		 */
+		/* Convert newlines to spaces, strip the final newline. */
 		if (res_len > 0 && res[res_len - 1] == '\n')
 			res[res_len - 1] = '\0';
 		for (cp = res; *cp != '\0'; cp++)
@@ -1879,8 +1829,9 @@ bad:
 /*
  * Print a printf-style error message.
  *
- * In default mode, this error message has no consequences, in particular it
- * does not affect the exit status.  Only in lint mode (-dL) it does.
+ * In default mode, this error message has no consequences, for compatibility
+ * reasons, in particular it does not affect the exit status.  Only in lint
+ * mode (-dL) it does.
  */
 void
 Error(const char *fmt, ...)
@@ -2014,10 +1965,7 @@ write_all(int fd, const void *data, size
 	}
 }
 
-/*
- * execDie --
- *	Print why exec failed, avoiding stdio.
- */
+/* Print why exec failed, avoiding stdio. */
 void MAKE_ATTR_DEAD
 execDie(const char *af, const char *av)
 {

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.584 src/usr.bin/make/parse.c:1.585
--- src/usr.bin/make/parse.c:1.584	Mon Dec 27 18:26:22 2021
+++ src/usr.bin/make/parse.c	Mon Dec 27 18:54:19 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.584 2021/12/27 18:26:22 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.585 2021/12/27 18:54:19 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -109,7 +109,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.584 2021/12/27 18:26:22 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.585 2021/12/27 18:54:19 rillig Exp $");
 
 /* types and constants */
 
@@ -1631,8 +1631,7 @@ ParseDependencySources(char *line, char 
  * targets. Nodes are created as necessary.
  *
  * The operator is applied to each node in the global 'targets' list,
- * which is where the nodes found for the targets are kept, by means of
- * the ParseOp function.
+ * which is where the nodes found for the targets are kept.
  *
  * The sources are parsed in much the same way as the targets, except
  * that they are expanded using the wildcarding scheme of the C-Shell,
@@ -1640,13 +1639,10 @@ ParseDependencySources(char *line, char 
  * nodes is then linked to each of the targets as one of its children.
  *
  * Certain targets and sources such as .PHONY or .PRECIOUS are handled
- * specially. These are the ones detailed by the specType variable.
+ * specially, see ParseSpecial.
  *
- * The storing of transformation rules such as '.c.o' is also taken care of
- * here. A target is recognized as a transformation rule by calling
- * Suff_IsTransform. If it is a transformation rule, its node is gotten
- * from the suffix module via Suff_AddTransform rather than the standard
- * Targ_FindNode in the target module.
+ * Transformation rules such as '.c.o' are also handled here, see
+ * Suff_AddTransform.
  *
  * Upon return, the value of the line is unspecified.
  */
@@ -1654,7 +1650,7 @@ static void
 ParseDependency(char *line)
 {
 	char *cp;		/* our current position */
-	GNodeType op;		/* the operator on the line */
+	GNodeType op;		/* the dependency operator on the line */
 	SearchPathList *paths;	/* search paths to alter when parsing a list
 				 * of .PATH targets */
 	GNodeType tOp;		/* operator from special target */
@@ -1663,9 +1659,8 @@ ParseDependency(char *line)
 	char *lstart = line;
 
 	/*
-	 * specType contains the SPECial TYPE of the current target. It is
-	 * SP_NOT if the target is unspecial. If it *is* special, however, the
-	 * children are linked as children of the parent but not vice versa.
+	 * In special targets, the children are linked as children of the
+	 * parent but not vice versa.
 	 */
 	ParseSpecial specType = SP_NOT;
 
@@ -1674,9 +1669,6 @@ ParseDependency(char *line)
 
 	paths = NULL;
 
-	/*
-	 * First, grind through the targets.
-	 */
 	/* XXX: don't use 'line' as an iterator variable */
 	if (!ParseDependencyTargets(&cp, &line, lstart, &specType, &tOp,
 	    &paths, &curTargs))
@@ -1692,20 +1684,9 @@ ParseDependency(char *line)
 	if (!Lst_IsEmpty(targets))
 		ParseDependencyCheckSpec(specType);
 
-	/*
-	 * Apply the operator to the target. This is how we remember which
-	 * operator a target was defined with. It fails if the operator
-	 * used isn't consistent across all references.
-	 */
 	op = ParseDependencyOp(&cp);
 	ApplyDependencyOperator(op);
 
-	/*
-	 * Onward to the sources.
-	 *
-	 * LINE will now point to the first source word, if any, or the
-	 * end of the string if not.
-	 */
 	pp_skip_whitespace(&cp);
 	line = cp;		/* XXX: 'line' is an inappropriate name */
 
@@ -2327,14 +2308,14 @@ StrContainsWord(const char *str, const c
 	const char *p, *end;
 
 	if (strLen < wordLen)
-		return false;	/* str is too short to contain word */
+		return false;
 
 	end = str + strLen - wordLen;
 	for (p = str; p != NULL; p = strchr(p, ' ')) {
 		if (*p == ' ')
 			p++;
 		if (p > end)
-			return false;	/* cannot contain word */
+			return false;
 
 		if (memcmp(p, word, wordLen) == 0 &&
 		    (p[wordLen] == '\0' || p[wordLen] == ' '))

Index: src/usr.bin/make/unit-tests/cond-short.mk
diff -u src/usr.bin/make/unit-tests/cond-short.mk:1.18 src/usr.bin/make/unit-tests/cond-short.mk:1.19
--- src/usr.bin/make/unit-tests/cond-short.mk:1.18	Sun Dec 12 09:49:09 2021
+++ src/usr.bin/make/unit-tests/cond-short.mk	Mon Dec 27 18:54:19 2021
@@ -1,4 +1,4 @@
-# $NetBSD: cond-short.mk,v 1.18 2021/12/12 09:49:09 rillig Exp $
+# $NetBSD: cond-short.mk,v 1.19 2021/12/27 18:54:19 rillig Exp $
 #
 # Demonstrates that in conditions, the right-hand side of an && or ||
 # is only evaluated if it can actually influence the result.
@@ -14,14 +14,14 @@
 # relevant variable expressions was that in the irrelevant variable
 # expressions, undefined variables were allowed.  This allowed for conditions
 # like 'defined(VAR) && ${VAR:S,from,to,} != ""', which no longer produced an
-# error message 'Malformed conditional', but it still evaluated the
-# expression, even though the expression was irrelevant.
+# error message 'Malformed conditional', but the irrelevant expression was
+# still evaluated.
 #
 # Since the initial commit on 1993-03-21, the manual page has been saying that
 # make 'will only evaluate a conditional as far as is necessary to determine',
 # but that was wrong.  The code in cond.c 1.1 from 1993-03-21 looks good since
 # it calls Var_Parse(condExpr, VAR_CMD, doEval,&varSpecLen,&doFree), but the
-# definition of Var_Parse does not call the third parameter 'doEval', as would
+# definition of Var_Parse did not call the third parameter 'doEval', as would
 # be expected, but instead 'err', accompanied by the comment 'TRUE if
 # undefined variables are an error'.  This subtle difference between 'do not
 # evaluate at all' and 'allow undefined variables' led to the unexpected
@@ -122,7 +122,9 @@ VAR=	# empty again, for the following te
 .if 0 || empty(${echo "expected or empty" 1>&2 :L:sh})
 .endif
 
-# Unreachable nested conditions are skipped completely as well.
+# Unreachable nested conditions are skipped completely as well.  These skipped
+# lines may even contain syntax errors.  This allows to skip syntactically
+# incompatible new features in older versions of make.
 
 .if 0
 .  if ${echo "unexpected nested and" 1>&2 :L:sh}

Index: src/usr.bin/make/unit-tests/cond-token-number.exp
diff -u src/usr.bin/make/unit-tests/cond-token-number.exp:1.4 src/usr.bin/make/unit-tests/cond-token-number.exp:1.5
--- src/usr.bin/make/unit-tests/cond-token-number.exp:1.4	Sun Nov 15 14:58:14 2020
+++ src/usr.bin/make/unit-tests/cond-token-number.exp	Mon Dec 27 18:54:19 2021
@@ -2,7 +2,7 @@ make: "cond-token-number.mk" line 15: Ma
 make: "cond-token-number.mk" line 25: Malformed conditional (+0)
 make: "cond-token-number.mk" line 35: Malformed conditional (!-1)
 make: "cond-token-number.mk" line 45: Malformed conditional (!+1)
-make: "cond-token-number.mk" line 80: End of the tests.
+make: "cond-token-number.mk" line 89: End of the tests.
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/cond-token-number.mk
diff -u src/usr.bin/make/unit-tests/cond-token-number.mk:1.5 src/usr.bin/make/unit-tests/cond-token-number.mk:1.6
--- src/usr.bin/make/unit-tests/cond-token-number.mk:1.5	Sun Nov 15 14:58:14 2020
+++ src/usr.bin/make/unit-tests/cond-token-number.mk	Mon Dec 27 18:54:19 2021
@@ -1,4 +1,4 @@
-# $NetBSD: cond-token-number.mk,v 1.5 2020/11/15 14:58:14 rillig Exp $
+# $NetBSD: cond-token-number.mk,v 1.6 2021/12/27 18:54:19 rillig Exp $
 #
 # Tests for number tokens in .if conditions.
 #
@@ -69,13 +69,22 @@
 .  error
 .endif
 
-# This is not a hexadecimal number, even though it has an x.
-# It is interpreted as a string instead, effectively meaning defined(3x4).
+# This is not a hexadecimal number, even though it has an x.  It is
+# interpreted as a string instead.  In a plain '.if', such a token evaluates
+# to true if it is non-empty.  In other '.if' directives, such a token is
+# evaluated by either FuncDefined or FuncMake.
 .if 3x4
 .else
 .  error
 .endif
 
+# Make can do radix conversion from hex to decimal.
+HEX=	dead
+.if 0x${HEX} == 57005
+.else
+.  error
+.endif
+
 # Ensure that parsing continues until here.
 .info End of the tests.
 

Index: src/usr.bin/make/unit-tests/var-eval-short.exp
diff -u src/usr.bin/make/unit-tests/var-eval-short.exp:1.16 src/usr.bin/make/unit-tests/var-eval-short.exp:1.17
--- src/usr.bin/make/unit-tests/var-eval-short.exp:1.16	Thu Dec  9 20:27:01 2021
+++ src/usr.bin/make/unit-tests/var-eval-short.exp	Mon Dec 27 18:54:19 2021
@@ -1,16 +1,16 @@
-make: "var-eval-short.mk" line 41: In the :@ modifier of "", the variable name "${FAIL}" must not contain a dollar
-make: "var-eval-short.mk" line 41: Malformed conditional (0 && ${:Uword:@${FAIL}@expr@})
-make: "var-eval-short.mk" line 81: Invalid time value at "${FAIL}}"
-make: "var-eval-short.mk" line 81: Malformed conditional (0 && ${:Uword:gmtime=${FAIL}})
-make: "var-eval-short.mk" line 95: Invalid time value at "${FAIL}}"
-make: "var-eval-short.mk" line 95: Malformed conditional (0 && ${:Uword:localtime=${FAIL}})
+make: "var-eval-short.mk" line 44: In the :@ modifier of "", the variable name "${FAIL}" must not contain a dollar
+make: "var-eval-short.mk" line 44: Malformed conditional (0 && ${:Uword:@${FAIL}@expr@})
+make: "var-eval-short.mk" line 84: Invalid time value at "${FAIL}}"
+make: "var-eval-short.mk" line 84: Malformed conditional (0 && ${:Uword:gmtime=${FAIL}})
+make: "var-eval-short.mk" line 98: Invalid time value at "${FAIL}}"
+make: "var-eval-short.mk" line 98: Malformed conditional (0 && ${:Uword:localtime=${FAIL}})
 CondParser_Eval: 0 && ${0:?${FAIL}then:${FAIL}else}
 Var_Parse: ${0:?${FAIL}then:${FAIL}else} (parse-only)
 Parsing modifier ${0:?...}
 Modifier part: "${FAIL}then"
 Modifier part: "${FAIL}else"
 Result of ${0:?${FAIL}then:${FAIL}else} is "" (parse-only, defined)
-ParseReadLine (160): 'DEFINED=	defined'
+ParseReadLine (163): 'DEFINED=	defined'
 Global: DEFINED = defined
 CondParser_Eval: 0 && ${DEFINED:L:?${FAIL}then:${FAIL}else}
 Var_Parse: ${DEFINED:L:?${FAIL}then:${FAIL}else} (parse-only)
@@ -20,7 +20,7 @@ Parsing modifier ${DEFINED:?...}
 Modifier part: "${FAIL}then"
 Modifier part: "${FAIL}else"
 Result of ${DEFINED:?${FAIL}then:${FAIL}else} is "defined" (parse-only, regular)
-ParseReadLine (163): '.MAKEFLAGS: -d0'
+ParseReadLine (166): '.MAKEFLAGS: -d0'
 ParseDependency(.MAKEFLAGS: -d0)
 Global: .MAKEFLAGS =  -r -k -d cpv -d
 Global: .MAKEFLAGS =  -r -k -d cpv -d 0

Index: src/usr.bin/make/unit-tests/var-eval-short.mk
diff -u src/usr.bin/make/unit-tests/var-eval-short.mk:1.7 src/usr.bin/make/unit-tests/var-eval-short.mk:1.8
--- src/usr.bin/make/unit-tests/var-eval-short.mk:1.7	Tue Sep  7 20:41:58 2021
+++ src/usr.bin/make/unit-tests/var-eval-short.mk	Mon Dec 27 18:54:19 2021
@@ -1,12 +1,13 @@
-# $NetBSD: var-eval-short.mk,v 1.7 2021/09/07 20:41:58 rillig Exp $
+# $NetBSD: var-eval-short.mk,v 1.8 2021/12/27 18:54:19 rillig Exp $
 #
 # Tests for each variable modifier to ensure that they only do the minimum
-# necessary computations.  If the result of the expression is not needed, they
-# should only parse the modifier but not actually evaluate it.
+# necessary computations.  If the result of the expression is irrelevant,
+# the modifier should only be parsed.  The modifier should not be evaluated,
+# but if it is evaluated for simplicity of the code (such as ':ts'), it must
+# not have any observable side effects.
 #
 # See also:
 #	var.c, the comment starting with 'The ApplyModifier functions'
-#	ApplyModifier, for the order of the modifiers
 #	ParseModifierPart, for evaluating nested expressions
 #	cond-short.mk
 
@@ -17,6 +18,8 @@ FAIL=	${:!echo unexpected 1>&2!}
 # is ignored as well.  To do that, it is necessary to step through the code of
 # each modifier.
 
+# TODO: Test the modifiers in the same order as they appear in ApplyModifier.
+
 .if 0 && ${FAIL}
 .endif
 

Reply via email to