Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): fix the :u modifier, which was broken ...



details:   https://anonhg.NetBSD.org/src/rev/3520f620f52d
branches:  trunk
changeset: 943333:3520f620f52d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Aug 31 17:41:38 2020 +0000

description:
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.

diffstat:

 usr.bin/make/unit-tests/varmod-unique.exp |   6 -----
 usr.bin/make/unit-tests/varmod-unique.mk  |  33 +++++++++++++++---------------
 usr.bin/make/var.c                        |  13 +++++------
 3 files changed, 22 insertions(+), 30 deletions(-)

diffs (115 lines):

diff -r a064b9e2376e -r 3520f620f52d usr.bin/make/unit-tests/varmod-unique.exp
--- a/usr.bin/make/unit-tests/varmod-unique.exp Mon Aug 31 17:32:13 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-unique.exp Mon Aug 31 17:41:38 2020 +0000
@@ -1,7 +1,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
diff -r a064b9e2376e -r 3520f620f52d usr.bin/make/unit-tests/varmod-unique.mk
--- a/usr.bin/make/unit-tests/varmod-unique.mk  Mon Aug 31 17:32:13 2020 +0000
+++ b/usr.bin/make/unit-tests/varmod-unique.mk  Mon Aug 31 17:41:38 2020 +0000
@@ -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:u} != "1"
+.  warning The :u modifier must merge _all_ adjacent duplicate words.
 .endif
 
-.if ${:U1 1 1 1 1 1 1 1} != "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
+.if ${:U   1    2    1 1  :u} != "1 2 1"
+.  warning The :u modifier must normalize whitespace between the words.
 .endif
 
-.if ${:U   1    2    1 1  } != "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
+.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:
diff -r a064b9e2376e -r 3520f620f52d usr.bin/make/var.c
--- a/usr.bin/make/var.c        Mon Aug 31 17:32:13 2020 +0000
+++ b/usr.bin/make/var.c        Mon Aug 31 17:41:38 2020 +0000
@@ -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 @@
 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);



Home | Main Index | Thread Index | Old Index