Module Name:    src
Committed By:   sjg
Date:           Wed Oct  7 16:40:30 UTC 2009

Modified Files:
        src/usr.bin/make: parse.c
        src/usr.bin/make/unit-tests: Makefile test.exp
Added Files:
        src/usr.bin/make/unit-tests: forsubst

Log Message:
The parser used to break dependency lines at ';' without regard
for substitution patterns.  This (perhaps coupled with the
new handling of .for variables in ${:U<value>...) caused interesting
results for lines like:

.for file in ${LIST}
for-subst:       ${file:S;^;${here}/;g}

add a unit-test to keep an eye on this.


To generate a diff of this commit:
cvs rdiff -u -r1.157 -r1.158 src/usr.bin/make/parse.c
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/forsubst
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/make/unit-tests/test.exp

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/parse.c
diff -u src/usr.bin/make/parse.c:1.157 src/usr.bin/make/parse.c:1.158
--- src/usr.bin/make/parse.c:1.157	Fri Jan 23 21:26:30 2009
+++ src/usr.bin/make/parse.c	Wed Oct  7 16:40:30 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.157 2009/01/23 21:26:30 dsl Exp $	*/
+/*	$NetBSD: parse.c,v 1.158 2009/10/07 16:40:30 sjg Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.157 2009/01/23 21:26:30 dsl Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.158 2009/10/07 16:40:30 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)parse.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: parse.c,v 1.157 2009/01/23 21:26:30 dsl Exp $");
+__RCSID("$NetBSD: parse.c,v 1.158 2009/10/07 16:40:30 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2590,15 +2590,30 @@
 	    /*
 	     * For some reason - probably to make the parser impossible -
 	     * a ';' can be used to separate commands from dependencies.
-	     * No attempt is made to avoid ';' inside substitution patterns.
+	     * Attempt to avoid ';' inside substitution patterns.
 	     */
-	    for (cp = line; *cp != 0; cp++) {
-		if (*cp == '\\' && cp[1] != 0) {
-		    cp++;
-		    continue;
+	    {
+		int level = 0;
+
+		for (cp = line; *cp != 0; cp++) {
+		    if (*cp == '\\' && cp[1] != 0) {
+			cp++;
+			continue;
+		    }
+		    if (*cp == '$' &&
+			(cp[1] == '(' || cp[1] == '{')) {
+			level++;
+			continue;
+		    }
+		    if (level > 0) {
+			if (*cp == ')' || *cp == '}') {
+			    level--;
+			    continue;
+			}
+		    } else if (*cp == ';') {
+			break;
+		    }
 		}
-		if (*cp == ';')
-		    break;
 	    }
 	    if (*cp != 0)
 		/* Terminate the dependency list at the ';' */

Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.23 src/usr.bin/make/unit-tests/Makefile:1.24
--- src/usr.bin/make/unit-tests/Makefile:1.23	Sat Oct 25 22:27:39 2008
+++ src/usr.bin/make/unit-tests/Makefile	Wed Oct  7 16:40:30 2009
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.23 2008/10/25 22:27:39 apb Exp $
+# $NetBSD: Makefile,v 1.24 2009/10/07 16:40:30 sjg Exp $
 #
 # Unit tests for make(1)
 # The main targets are:
@@ -24,6 +24,7 @@
 	export \
 	export-all \
 	dotwait \
+	forsubst \
 	moderrs \
 	modmatch \
 	modmisc \

Index: src/usr.bin/make/unit-tests/test.exp
diff -u src/usr.bin/make/unit-tests/test.exp:1.28 src/usr.bin/make/unit-tests/test.exp:1.29
--- src/usr.bin/make/unit-tests/test.exp:1.28	Mon Sep  7 17:56:23 2009
+++ src/usr.bin/make/unit-tests/test.exp	Wed Oct  7 16:40:30 2009
@@ -67,6 +67,7 @@
 make: Graph cycles through `cycle.2.97'
 cycle.1.99
 cycle.1.99
+.for with :S;... OK
 Expect: Unknown modifier 'Z'
 make: Unknown modifier 'Z'
 VAR:Z=

Added files:

Index: src/usr.bin/make/unit-tests/forsubst
diff -u /dev/null src/usr.bin/make/unit-tests/forsubst:1.1
--- /dev/null	Wed Oct  7 16:40:30 2009
+++ src/usr.bin/make/unit-tests/forsubst	Wed Oct  7 16:40:30 2009
@@ -0,0 +1,10 @@
+# $Id: forsubst,v 1.1 2009/10/07 16:40:30 sjg Exp $
+
+all: for-subst
+
+here := ${.PARSEDIR}
+# this should not run foul of the parser
+.for file in ${.PARSEFILE}
+for-subst:	  ${file:S;^;${here}/;g}
+	@echo ".for with :S;... OK"
+.endfor

Reply via email to