Module Name: src Committed By: sjg Date: Thu Feb 18 20:25:09 UTC 2016
Modified Files: src/usr.bin/make: main.c make.1 nonints.h var.c src/usr.bin/make/unit-tests: export-env.exp export-env.mk Log Message: Add .export-literal to avoid the need for $$ dance when trying to put unexpanded variables into environment. Reviewed by: christos To generate a diff of this commit: cvs rdiff -u -r1.239 -r1.240 src/usr.bin/make/main.c cvs rdiff -u -r1.251 -r1.252 src/usr.bin/make/make.1 cvs rdiff -u -r1.71 -r1.72 src/usr.bin/make/nonints.h cvs rdiff -u -r1.202 -r1.203 src/usr.bin/make/var.c cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/export-env.exp \ src/usr.bin/make/unit-tests/export-env.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/main.c diff -u src/usr.bin/make/main.c:1.239 src/usr.bin/make/main.c:1.240 --- src/usr.bin/make/main.c:1.239 Thu Feb 18 18:29:14 2016 +++ src/usr.bin/make/main.c Thu Feb 18 20:25:08 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.239 2016/02/18 18:29:14 christos Exp $ */ +/* $NetBSD: main.c,v 1.240 2016/02/18 20:25:08 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,7 +69,7 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: main.c,v 1.239 2016/02/18 18:29:14 christos Exp $"; +static char rcsid[] = "$NetBSD: main.c,v 1.240 2016/02/18 20:25:08 sjg Exp $"; #else #include <sys/cdefs.h> #ifndef lint @@ -81,7 +81,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19 #if 0 static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: main.c,v 1.239 2016/02/18 18:29:14 christos Exp $"); +__RCSID("$NetBSD: main.c,v 1.240 2016/02/18 20:25:08 sjg Exp $"); #endif #endif /* not lint */ #endif @@ -1950,6 +1950,44 @@ mkTempFile(const char *pattern, char **f return fd; } +/* + * Convert a string representation of a boolean. + * Anything that looks like "No", "False", "Off", "0" etc, + * is FALSE, otherwise TRUE. + */ +Boolean +s2Boolean(const char *s, Boolean bf) +{ + if (s) { + switch(*s) { + case '\0': /* not set - the default wins */ + break; + case '0': + case 'F': + case 'f': + case 'N': + case 'n': + bf = FALSE; + break; + case 'O': + case 'o': + switch (s[1]) { + case 'F': + case 'f': + bf = FALSE; + break; + default: + bf = TRUE; + break; + } + break; + default: + bf = TRUE; + break; + } + } + return (bf); +} /* * Return a Boolean based on setting of a knob. @@ -1968,28 +2006,7 @@ getBoolean(const char *name, Boolean bf) cp = Var_Subst(NULL, tmp, VAR_GLOBAL, VARF_WANTRES); if (cp) { - switch(*cp) { - case '\0': /* not set - the default wins */ - break; - case '0': - case 'f': - case 'n': - bf = FALSE; - break; - case 'o': - switch (cp[1]) { - case 'f': - bf = FALSE; - break; - default: - bf = TRUE; - break; - } - break; - default: - bf = TRUE; - break; - } + bf = s2Boolean(cp, bf); free(cp); } } Index: src/usr.bin/make/make.1 diff -u src/usr.bin/make/make.1:1.251 src/usr.bin/make/make.1:1.252 --- src/usr.bin/make/make.1:1.251 Thu Feb 18 06:18:58 2016 +++ src/usr.bin/make/make.1 Thu Feb 18 20:25:08 2016 @@ -1,4 +1,4 @@ -.\" $NetBSD: make.1,v 1.251 2016/02/18 06:18:58 sjg Exp $ +.\" $NetBSD: make.1,v 1.252 2016/02/18 20:25:08 sjg Exp $ .\" .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)make.1 8.4 (Berkeley) 3/19/94 .\" -.Dd February 17, 2016 +.Dd February 18, 2016 .Dt MAKE 1 .Os .Sh NAME @@ -1579,6 +1579,10 @@ This allows exporting a value to the env used by .Nm internally. +.It Ic .export-literal Ar variable ... +The same as +.Ql .export-env , +except that variables in the value are not expanded. .It Ic .info Ar message The message is printed along with the name of the makefile and line number. .It Ic .undef Ar variable Index: src/usr.bin/make/nonints.h diff -u src/usr.bin/make/nonints.h:1.71 src/usr.bin/make/nonints.h:1.72 --- src/usr.bin/make/nonints.h:1.71 Thu Feb 18 18:29:14 2016 +++ src/usr.bin/make/nonints.h Thu Feb 18 20:25:08 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: nonints.h,v 1.71 2016/02/18 18:29:14 christos Exp $ */ +/* $NetBSD: nonints.h,v 1.72 2016/02/18 20:25:08 sjg Exp $ */ /*- * Copyright (c) 1988, 1989, 1990, 1993 @@ -118,6 +118,7 @@ void Finish(int) MAKE_ATTR_DEAD; int eunlink(const char *); void execError(const char *, const char *); char *getTmpdir(void); +Boolean s2Boolean(const char *, Boolean); Boolean getBoolean(const char *, Boolean); /* parse.c */ Index: src/usr.bin/make/var.c diff -u src/usr.bin/make/var.c:1.202 src/usr.bin/make/var.c:1.203 --- src/usr.bin/make/var.c:1.202 Thu Feb 18 18:29:14 2016 +++ src/usr.bin/make/var.c Thu Feb 18 20:25:08 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.202 2016/02/18 18:29:14 christos Exp $ */ +/* $NetBSD: var.c,v 1.203 2016/02/18 20:25:08 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: var.c,v 1.202 2016/02/18 18:29:14 christos Exp $"; +static char rcsid[] = "$NetBSD: var.c,v 1.203 2016/02/18 20:25:08 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.202 2016/02/18 18:29:14 christos Exp $"); +__RCSID("$NetBSD: var.c,v 1.203 2016/02/18 20:25:08 sjg Exp $"); #endif #endif /* not lint */ #endif @@ -217,7 +217,11 @@ static int var_exportedVars = VAR_EXPORT * We pass this to Var_Export when doing the initial export * or after updating an exported var. */ -#define VAR_EXPORT_PARENT 1 +#define VAR_EXPORT_PARENT 1 +/* + * We pass this to Var_Export1 to tell it to leave the value alone. + */ +#define VAR_EXPORT_LITERAL 2 /* Var*Pattern flags */ #define VAR_SUB_GLOBAL 0x01 /* Apply substitution globally */ @@ -581,12 +585,13 @@ Var_Delete(const char *name, GNode *ctxt * We only manipulate flags of vars if 'parent' is set. */ static int -Var_Export1(const char *name, int parent) +Var_Export1(const char *name, int flags) { char tmp[BUFSIZ]; Var *v; char *val = NULL; int n; + int parent = (flags & VAR_EXPORT_PARENT); if (*name == '.') return 0; /* skip internals */ @@ -614,7 +619,7 @@ Var_Export1(const char *name, int parent return 0; /* nothing to do */ } val = Buf_GetAll(&v->val, NULL); - if (strchr(val, '$')) { + if ((flags & VAR_EXPORT_LITERAL) == 0 && strchr(val, '$')) { if (parent) { /* * Flag this as something we need to re-export. @@ -726,7 +731,7 @@ Var_Export(char *str, int isExport) char *val; char **av; char *as; - int track; + int flags; int ac; int i; @@ -735,11 +740,14 @@ Var_Export(char *str, int isExport) return; } + flags = 0; if (strncmp(str, "-env", 4) == 0) { - track = 0; str += 4; + } else if (strncmp(str, "-literal", 8) == 0) { + str += 8; + flags |= VAR_EXPORT_LITERAL; } else { - track = VAR_EXPORT_PARENT; + flags |= VAR_EXPORT_PARENT; } val = Var_Subst(NULL, str, VAR_GLOBAL, VARF_WANTRES); if (*val) { @@ -761,10 +769,10 @@ Var_Export(char *str, int isExport) continue; } } - if (Var_Export1(name, track)) { + if (Var_Export1(name, flags)) { if (VAR_EXPORTED_ALL != var_exportedVars) var_exportedVars = VAR_EXPORTED_YES; - if (isExport && track) { + if (isExport && (flags & VAR_EXPORT_PARENT)) { Var_Append(MAKE_EXPORTED, name, VAR_GLOBAL); } } Index: src/usr.bin/make/unit-tests/export-env.exp diff -u src/usr.bin/make/unit-tests/export-env.exp:1.1 src/usr.bin/make/unit-tests/export-env.exp:1.2 --- src/usr.bin/make/unit-tests/export-env.exp:1.1 Thu Aug 21 13:44:51 2014 +++ src/usr.bin/make/unit-tests/export-env.exp Thu Feb 18 20:25:08 2016 @@ -2,8 +2,10 @@ make: UT_TEST=export-env.mk UT_ENV=not-exported UT_EXP=not-exported +UT_LIT=literal export-env.mk env: UT_TEST=export-env.mk UT_ENV=exported UT_EXP=exported +UT_LIT=literal ${UT_TEST} exit status 0 Index: src/usr.bin/make/unit-tests/export-env.mk diff -u src/usr.bin/make/unit-tests/export-env.mk:1.1 src/usr.bin/make/unit-tests/export-env.mk:1.2 --- src/usr.bin/make/unit-tests/export-env.mk:1.1 Thu Aug 21 13:44:51 2014 +++ src/usr.bin/make/unit-tests/export-env.mk Thu Feb 18 20:25:08 2016 @@ -1,4 +1,4 @@ -# $Id: export-env.mk,v 1.1 2014/08/21 13:44:51 apb Exp $ +# $Id: export-env.mk,v 1.2 2016/02/18 20:25:08 sjg Exp $ # our normal .export, subsequent changes affect the environment UT_TEST=this @@ -15,9 +15,12 @@ UT_EXP=before-export export UT_EXP=exported UT_EXP=not-exported +UT_LIT= literal ${UT_TEST} +.export-literal UT_LIT + all: - @echo make:; ${UT_TEST UT_ENV UT_EXP:L:@v@echo $v=${$v};@} - @echo env:; ${UT_TEST UT_ENV UT_EXP:L:@v@echo $v=$${$v};@} + @echo make:; ${UT_TEST UT_ENV UT_EXP UT_LIT:L:@v@echo $v=${$v};@} + @echo env:; ${UT_TEST UT_ENV UT_EXP UT_LIT:L:@v@echo $v=$${$v};@}