tech-toolchain archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
make: skip set if var set on command line
The patch below, causes Var_Set to skip setting a var in the global
context, if it has been set on the command line.
Without this, some interesting combinations of indirection
do not produce the expected results.
For example, in the last part of the unit test we get
v=override k=is x
rather than the expected v=override k=override
--sjg
Index: var.c
===================================================================
RCS file: /cvsroot/src/usr.bin/make/var.c,v
retrieving revision 1.128
diff -u -p -r1.128 var.c
--- var.c 31 Mar 2008 00:12:21 -0000 1.128
+++ var.c 8 May 2008 17:17:36 -0000
@@ -746,6 +746,12 @@ Var_Set(const char *name, const char *va
name = Var_Subst(NULL, cp, ctxt, 0);
} else
name = cp;
+ if (ctxt == VAR_GLOBAL) {
+ v = VarFind(name, VAR_CMD, 0);
+ if (v != (Var *)NIL) {
+ goto out;
+ }
+ }
v = VarFind(name, ctxt, 0);
if (v == (Var *)NIL) {
VarAdd(name, val, ctxt);
@@ -777,6 +783,7 @@ Var_Set(const char *name, const char *va
Var_Append(MAKEOVERRIDES, name, VAR_GLOBAL);
}
+ out:
if (name != cp)
free(UNCONST(name));
if (v != (Var *)NIL)
Index: unit-tests/test.exp
===================================================================
RCS file: /cvsroot/src/usr.bin/make/unit-tests/test.exp,v
retrieving revision 1.22
diff -u -p -r1.22 test.exp
--- unit-tests/test.exp 31 Mar 2008 00:12:21 -0000 1.22
+++ unit-tests/test.exp 8 May 2008 17:17:36 -0000
@@ -300,4 +300,7 @@ default FU=<v>fu</v> FOO=<v>foo</v> VAR=
two FU=<v>bar</v> FOO=<v>goo</v> VAR=<v></v>
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>
-show 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>
+five v=is x k=is x
+six v=is y k=is y
+show-v v=override k=override
Index: unit-tests/varcmd
===================================================================
RCS file: /cvsroot/src/usr.bin/make/unit-tests/varcmd,v
retrieving revision 1.2
diff -u -p -r1.2 varcmd
--- unit-tests/varcmd 1 Jun 2005 17:17:34 -0000 1.2
+++ unit-tests/varcmd 8 May 2008 17:17:36 -0000
@@ -30,4 +30,20 @@ VAR=Internal
.endif
four: show
- @${.MAKE} -f ${MAKEFILE} show
+ @${.MAKE} -f ${MAKEFILE} five
+
+M = x
+V.y = is y
+V.x = is x
+V := ${V.$M}
+K := ${V}
+
+show-v:
+ @echo '${TAG} v=${V} k=${K}'
+
+five: show show-v
+ @${.MAKE} -f ${MAKEFILE} M=y six
+
+six: show-v
+ @${.MAKE} -f ${MAKEFILE} V=override show-v
+
Home |
Main Index |
Thread Index |
Old Index