Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make Do not append to variable set on command line
details: https://anonhg.NetBSD.org/src/rev/7883b78a1c07
branches: trunk
changeset: 357625:7883b78a1c07
user: sjg <sjg%NetBSD.org@localhost>
date: Sat Nov 18 22:34:04 2017 +0000
description:
Do not append to variable set on command line
POSIX requires that variables set on the command line
be immutable.
Var_Append needs to pass FIND_CMD and skip append
if found variable has VAR_FROM_CMD flag set.
diffstat:
usr.bin/make/unit-tests/varcmd.exp | 1 +
usr.bin/make/unit-tests/varcmd.mk | 10 +++++++++-
usr.bin/make/var.c | 10 +++++-----
3 files changed, 15 insertions(+), 6 deletions(-)
diffs (74 lines):
diff -r 9f8c2a46a609 -r 7883b78a1c07 usr.bin/make/unit-tests/varcmd.exp
--- a/usr.bin/make/unit-tests/varcmd.exp Sat Nov 18 20:48:50 2017 +0000
+++ b/usr.bin/make/unit-tests/varcmd.exp Sat Nov 18 22:34:04 2017 +0000
@@ -1,5 +1,6 @@
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'
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>
diff -r 9f8c2a46a609 -r 7883b78a1c07 usr.bin/make/unit-tests/varcmd.mk
--- a/usr.bin/make/unit-tests/varcmd.mk Sat Nov 18 20:48:50 2017 +0000
+++ b/usr.bin/make/unit-tests/varcmd.mk Sat Nov 18 22:34:04 2017 +0000
@@ -1,4 +1,4 @@
-# $Id: varcmd.mk,v 1.1 2014/08/21 13:44:52 apb Exp $
+# $Id: varcmd.mk,v 1.2 2017/11/18 22:34:04 sjg Exp $
#
# Test behaviour of recursive make and vars set on command line.
@@ -24,6 +24,14 @@
@${.MAKE} -f ${MAKEFILE} four
+.ifmake two
+# this should not work
+FU+= oops
+_FU:= ${FU}
+two: immutable
+immutable:
+ @echo "$@ FU='${_FU}'"
+.endif
.ifmake four
VAR=Internal
.MAKEOVERRIDES+= VAR
diff -r 9f8c2a46a609 -r 7883b78a1c07 usr.bin/make/var.c
--- a/usr.bin/make/var.c Sat Nov 18 20:48:50 2017 +0000
+++ b/usr.bin/make/var.c Sat Nov 18 22:34:04 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.215 2017/04/16 21:39:49 riastradh Exp $ */
+/* $NetBSD: var.c,v 1.216 2017/11/18 22:34:04 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.215 2017/04/16 21:39:49 riastradh Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.216 2017/11/18 22:34:04 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.215 2017/04/16 21:39:49 riastradh Exp $");
+__RCSID("$NetBSD: var.c,v 1.216 2017/11/18 22:34:04 sjg Exp $");
#endif
#endif /* not lint */
#endif
@@ -1061,11 +1061,11 @@
name = expanded_name;
}
- v = VarFind(name, ctxt, (ctxt == VAR_GLOBAL) ? FIND_ENV : 0);
+ v = VarFind(name, ctxt, (ctxt == VAR_GLOBAL) ? (FIND_CMD|FIND_ENV) : 0);
if (v == NULL) {
VarAdd(name, val, ctxt);
- } else {
+ } else if (!(v->flags & VAR_FROM_CMD)) {
Buf_AddByte(&v->val, ' ');
Buf_AddBytes(&v->val, strlen(val), val);
Home |
Main Index |
Thread Index |
Old Index