Do not set vars in VAR_GLOBAL context, if they have been set on the
command line. Add a suitable unit-test.
This commit is contained in:
parent
b87210fa51
commit
20275ee931
@ -300,4 +300,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>
|
||||
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
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $Id: varcmd,v 1.2 2005/06/01 17:17:34 sjg Exp $
|
||||
# $Id: varcmd,v 1.3 2008/05/14 14:27:02 sjg Exp $
|
||||
#
|
||||
# Test behaviour of recursive make and vars set on command line.
|
||||
|
||||
@ -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
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: var.c,v 1.128 2008/03/31 00:12:21 sjg Exp $ */
|
||||
/* $NetBSD: var.c,v 1.129 2008/05/14 14:27:02 sjg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 1993
|
||||
@ -69,14 +69,14 @@
|
||||
*/
|
||||
|
||||
#ifndef MAKE_NATIVE
|
||||
static char rcsid[] = "$NetBSD: var.c,v 1.128 2008/03/31 00:12:21 sjg Exp $";
|
||||
static char rcsid[] = "$NetBSD: var.c,v 1.129 2008/05/14 14:27:02 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.128 2008/03/31 00:12:21 sjg Exp $");
|
||||
__RCSID("$NetBSD: var.c,v 1.129 2008/05/14 14:27:02 sjg Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
#endif
|
||||
@ -746,6 +746,12 @@ Var_Set(const char *name, const char *val, GNode *ctxt, int flags)
|
||||
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 *val, GNode *ctxt, int flags)
|
||||
|
||||
Var_Append(MAKEOVERRIDES, name, VAR_GLOBAL);
|
||||
}
|
||||
out:
|
||||
if (name != cp)
|
||||
free(UNCONST(name));
|
||||
if (v != (Var *)NIL)
|
||||
|
Loading…
Reference in New Issue
Block a user