Module Name: src
Committed By: rillig
Date: Mon Aug 31 17:41:39 UTC 2020
Modified Files:
src/usr.bin/make: var.c
src/usr.bin/make/unit-tests: varmod-unique.exp varmod-unique.mk
Log Message:
make(1): fix the :u modifier, which was broken for almost a day
Big thanks go to sjg, who discovered the bug and did the main work to
track it down.
In the unit tests for the :u modifier from the previous commit, I had
forgotten to actually add the :u modifier at the end. I added it now
and also added a few other tests. It's better to have a few more tests
than too few.
To generate a diff of this commit:
cvs rdiff -u -r1.479 -r1.480 src/usr.bin/make/var.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/varmod-unique.exp
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/varmod-unique.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/var.c
diff -u src/usr.bin/make/var.c:1.479 src/usr.bin/make/var.c:1.480
--- src/usr.bin/make/var.c:1.479 Sun Aug 30 19:56:02 2020
+++ src/usr.bin/make/var.c Mon Aug 31 17:41:38 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.479 2020/08/30 19:56:02 rillig Exp $ */
+/* $NetBSD: var.c,v 1.480 2020/08/31 17:41:38 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.479 2020/08/30 19:56:02 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.480 2020/08/31 17:41:38 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: var.c,v 1.479 2020/08/30 19:56:02 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.480 2020/08/31 17:41:38 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -1609,15 +1609,14 @@ static char *
VarUniq(const char *str)
{
Words words = Str_Words(str, FALSE);
- size_t ac = words.len;
char **av = words.words;
- if (ac > 1) {
+ if (words.len > 1) {
size_t i, j;
- for (j = 0, i = 1; i < ac; i++)
+ for (j = 0, i = 1; i < words.len; i++)
if (strcmp(av[i], av[j]) != 0 && (++j != i))
av[j] = av[i];
- ac = j + 1;
+ words.len = j + 1;
}
return Words_JoinFree(words);
Index: src/usr.bin/make/unit-tests/varmod-unique.exp
diff -u src/usr.bin/make/unit-tests/varmod-unique.exp:1.2 src/usr.bin/make/unit-tests/varmod-unique.exp:1.3
--- src/usr.bin/make/unit-tests/varmod-unique.exp:1.2 Mon Aug 31 17:32:13 2020
+++ src/usr.bin/make/unit-tests/varmod-unique.exp Mon Aug 31 17:41:38 2020
@@ -1,7 +1 @@
-make: "varmod-unique.mk" line 11: warning: The :u modifier must merge adjacent duplicate words.
-make: "varmod-unique.mk" line 13: warning: FIXME
-make: "varmod-unique.mk" line 26: warning: The :u modifier must merge _all_ adjacent duplicate words.
-make: "varmod-unique.mk" line 28: warning: FIXME
-make: "varmod-unique.mk" line 33: warning: The :u modifier must normalize whitespace between the words.
-make: "varmod-unique.mk" line 35: warning: FIXME
exit status 0
Index: src/usr.bin/make/unit-tests/varmod-unique.mk
diff -u src/usr.bin/make/unit-tests/varmod-unique.mk:1.3 src/usr.bin/make/unit-tests/varmod-unique.mk:1.4
--- src/usr.bin/make/unit-tests/varmod-unique.mk:1.3 Mon Aug 31 17:32:13 2020
+++ src/usr.bin/make/unit-tests/varmod-unique.mk Mon Aug 31 17:41:38 2020
@@ -1,39 +1,38 @@
-# $NetBSD: varmod-unique.mk,v 1.3 2020/08/31 17:32:13 rillig Exp $
+# $NetBSD: varmod-unique.mk,v 1.4 2020/08/31 17:41:38 rillig Exp $
#
# Tests for the :u variable modifier, which discards adjacent duplicate
# words.
.if ${:U1 2 1:u} != "1 2 1"
-. error The :u modifier only merges _adjacent_ duplicate words.
+. warning The :u modifier only merges _adjacent_ duplicate words.
.endif
.if ${:U1 2 2 3:u} != "1 2 3"
. warning The :u modifier must merge adjacent duplicate words.
-. if ${:U1 2 2 3:u} == "1 2 3 3" # not the desired result
-. warning FIXME
-. endif
.endif
.if ${:U:u} != ""
-. error The :u modifier must do nothing with an empty word list.
+. warning The :u modifier must do nothing with an empty word list.
.endif
.if ${:U1:u} != "1"
-. error The :u modifier must do nothing with a single-element word list.
+. warning The :u modifier must do nothing with a single-element word list.
.endif
-.if ${:U1 1 1 1 1 1 1 1} != "1"
+.if ${:U1 1 1 1 1 1 1 1:u} != "1"
. warning The :u modifier must merge _all_ adjacent duplicate words.
-. if ${:U1 1 1 1 1 1 1 1} == "1 1 1 1 1 1 1 1"
-. warning FIXME
-. endif
.endif
-.if ${:U 1 2 1 1 } != "1 2 1"
+.if ${:U 1 2 1 1 :u} != "1 2 1"
. warning The :u modifier must normalize whitespace between the words.
-. if ${:U 1 2 1 1 } != "1 2 1 1"
-. warning FIXME
-. endif
+.endif
+
+.if ${:U1 1 1 1 2:u} != "1 2"
+. warning Duplicate words at the beginning must be merged.
+.endif
+
+.if ${:U1 2 2 2 2:u} != "1 2"
+. warning Duplicate words at the end must be merged.
.endif
all: