Module Name: src
Committed By: sjg
Date: Fri Dec 8 03:36:42 UTC 2017
Modified Files:
src/usr.bin/make: var.c
src/usr.bin/make/unit-tests: varcmd.exp varcmd.mk
Log Message:
Ensure VAR+=val on command line is handled correctly
If VAR is not previously set, call Var_Set to deal with
the special case of VAR_CMD.
If VAR is previously set, and ctxt is VAR_CMD we should do the update
even if VAR_FROM_CMD is set.
To generate a diff of this commit:
cvs rdiff -u -r1.216 -r1.217 src/usr.bin/make/var.c
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/varcmd.exp \
src/usr.bin/make/unit-tests/varcmd.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.216 src/usr.bin/make/var.c:1.217
--- src/usr.bin/make/var.c:1.216 Sat Nov 18 22:34:04 2017
+++ src/usr.bin/make/var.c Fri Dec 8 03:36:42 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.216 2017/11/18 22:34:04 sjg Exp $ */
+/* $NetBSD: var.c,v 1.217 2017/12/08 03:36:42 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.216 2017/11/18 22:34:04 sjg Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.217 2017/12/08 03:36:42 sjg 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.216 2017/11/18 22:34:04 sjg Exp $");
+__RCSID("$NetBSD: var.c,v 1.217 2017/12/08 03:36:42 sjg Exp $");
#endif
#endif /* not lint */
#endif
@@ -1064,8 +1064,8 @@ Var_Append(const char *name, const char
v = VarFind(name, ctxt, (ctxt == VAR_GLOBAL) ? (FIND_CMD|FIND_ENV) : 0);
if (v == NULL) {
- VarAdd(name, val, ctxt);
- } else if (!(v->flags & VAR_FROM_CMD)) {
+ Var_Set(name, val, ctxt, 0);
+ } else if (ctxt == VAR_CMD || !(v->flags & VAR_FROM_CMD)) {
Buf_AddByte(&v->val, ' ');
Buf_AddBytes(&v->val, strlen(val), val);
Index: src/usr.bin/make/unit-tests/varcmd.exp
diff -u src/usr.bin/make/unit-tests/varcmd.exp:1.2 src/usr.bin/make/unit-tests/varcmd.exp:1.3
--- src/usr.bin/make/unit-tests/varcmd.exp:1.2 Sat Nov 18 22:34:04 2017
+++ src/usr.bin/make/unit-tests/varcmd.exp Fri Dec 8 03:36:42 2017
@@ -1,6 +1,7 @@
default FU=<v>fu</v> FOO=<v>foo</v> VAR=<v></v>
two FU=<v>bar</v> FOO=<v>goo</v> VAR=<v></v>
immutable FU='bar'
+immutable FOO='goo'
three FU=<v>bar</v> FOO=<v>goo</v> VAR=<v></v>
four FU=<v>bar</v> FOO=<v>goo</v> VAR=<v>Internal</v>
five FU=<v>bar</v> FOO=<v>goo</v> VAR=<v>Internal</v>
Index: src/usr.bin/make/unit-tests/varcmd.mk
diff -u src/usr.bin/make/unit-tests/varcmd.mk:1.2 src/usr.bin/make/unit-tests/varcmd.mk:1.3
--- src/usr.bin/make/unit-tests/varcmd.mk:1.2 Sat Nov 18 22:34:04 2017
+++ src/usr.bin/make/unit-tests/varcmd.mk Fri Dec 8 03:36:42 2017
@@ -1,4 +1,4 @@
-# $Id: varcmd.mk,v 1.2 2017/11/18 22:34:04 sjg Exp $
+# $Id: varcmd.mk,v 1.3 2017/12/08 03:36:42 sjg Exp $
#
# Test behaviour of recursive make and vars set on command line.
@@ -15,7 +15,7 @@ show:
@echo "${TAG} FU=<v>${FU}</v> FOO=<v>${FOO}</v> VAR=<v>${VAR}</v>"
one: show
- @${.MAKE} -f ${MAKEFILE} FU=bar FOO=goo two
+ @${.MAKE} -f ${MAKEFILE} FU=bar FOO+=goo two
two: show
@${.MAKE} -f ${MAKEFILE} three
@@ -27,10 +27,13 @@ three: show
.ifmake two
# this should not work
FU+= oops
+FOO+= oops
_FU:= ${FU}
+_FOO:= ${FOO}
two: immutable
immutable:
@echo "$@ FU='${_FU}'"
+ @echo "$@ FOO='${_FOO}'"
.endif
.ifmake four
VAR=Internal