Module Name: src Committed By: sjg Date: Sat Jun 1 06:26:36 UTC 2024
Modified Files: src/usr.bin/make: make.1 make.h parse.c var.c src/usr.bin/make/unit-tests: directive-export.exp directive-export.mk export-all.mk Log Message: make: add .export-all An explicit syntax for exporting all global variables is much safer than allowing .export with no argument to do the same. Add .export-all and have .export with no argument throw a warning saying to use .export-all Reviewed by: rillig To generate a diff of this commit: cvs rdiff -u -r1.376 -r1.377 src/usr.bin/make/make.1 cvs rdiff -u -r1.336 -r1.337 src/usr.bin/make/make.h cvs rdiff -u -r1.728 -r1.729 src/usr.bin/make/parse.c cvs rdiff -u -r1.1116 -r1.1117 src/usr.bin/make/var.c cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/directive-export.exp cvs rdiff -u -r1.10 -r1.11 src/usr.bin/make/unit-tests/directive-export.mk cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/export-all.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/make.1 diff -u src/usr.bin/make/make.1:1.376 src/usr.bin/make/make.1:1.377 --- src/usr.bin/make/make.1:1.376 Tue May 28 19:09:04 2024 +++ src/usr.bin/make/make.1 Sat Jun 1 06:26:36 2024 @@ -1,4 +1,4 @@ -.\" $NetBSD: make.1,v 1.376 2024/05/28 19:09:04 sjg Exp $ +.\" $NetBSD: make.1,v 1.377 2024/06/01 06:26:36 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 May 28, 2024 +.Dd June 1, 2024 .Dt MAKE 1 .Os .Sh NAME @@ -1960,12 +1960,7 @@ The directives for exporting and unexpor .Bl -tag -width Ds .It Ic .export Ar variable No ... Export the specified global variable. -If no variable list is provided, all globals are exported -except for internal variables (those that start with -.Ql \&. ) . -This is not affected by the -.Fl X -flag, so should be used with caution. +.Pp For compatibility with other make programs, .Cm export Ar variable\| Ns Cm \&= Ns Ar value (without leading dot) is also accepted. @@ -1973,6 +1968,12 @@ For compatibility with other make progra Appending a variable name to .Va .MAKE.EXPORTED is equivalent to exporting a variable. +.It Ic .export-all +Export all globals except for internal variables (those that start with +.Ql \&. ) . +This is not affected by the +.Fl X +flag, so should be used with caution. .It Ic .export-env Ar variable No ... The same as .Ql .export , Index: src/usr.bin/make/make.h diff -u src/usr.bin/make/make.h:1.336 src/usr.bin/make/make.h:1.337 --- src/usr.bin/make/make.h:1.336 Sat Jun 1 05:08:48 2024 +++ src/usr.bin/make/make.h Sat Jun 1 06:26:36 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: make.h,v 1.336 2024/06/01 05:08:48 rillig Exp $ */ +/* $NetBSD: make.h,v 1.337 2024/06/01 06:26:36 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -992,6 +992,8 @@ typedef enum VarSetFlags { } VarSetFlags; typedef enum VarExportMode { + /* .export-all */ + VEM_ALL, /* .export-env */ VEM_ENV, /* .export: Initial export or update an already exported variable. */ Index: src/usr.bin/make/parse.c diff -u src/usr.bin/make/parse.c:1.728 src/usr.bin/make/parse.c:1.729 --- src/usr.bin/make/parse.c:1.728 Fri May 31 05:50:11 2024 +++ src/usr.bin/make/parse.c Sat Jun 1 06:26:36 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.728 2024/05/31 05:50:11 rillig Exp $ */ +/* $NetBSD: parse.c,v 1.729 2024/06/01 06:26:36 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -105,7 +105,7 @@ #include "pathnames.h" /* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: parse.c,v 1.728 2024/05/31 05:50:11 rillig Exp $"); +MAKE_RCSID("$NetBSD: parse.c,v 1.729 2024/06/01 06:26:36 sjg Exp $"); /* Detects a multiple-inclusion guard in a makefile. */ typedef enum { @@ -2759,6 +2759,8 @@ ParseDirective(char *line) Var_Undef(arg); else if (Substring_Equals(dir, "export")) Var_Export(VEM_PLAIN, arg); + else if (Substring_Equals(dir, "export-all")) + Var_Export(VEM_ALL, arg); else if (Substring_Equals(dir, "export-env")) Var_Export(VEM_ENV, arg); else if (Substring_Equals(dir, "export-literal")) Index: src/usr.bin/make/var.c diff -u src/usr.bin/make/var.c:1.1116 src/usr.bin/make/var.c:1.1117 --- src/usr.bin/make/var.c:1.1116 Sat Jun 1 05:08:48 2024 +++ src/usr.bin/make/var.c Sat Jun 1 06:26:36 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.1116 2024/06/01 05:08:48 rillig Exp $ */ +/* $NetBSD: var.c,v 1.1117 2024/06/01 06:26:36 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -132,7 +132,7 @@ #include "metachar.h" /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: var.c,v 1.1116 2024/06/01 05:08:48 rillig Exp $"); +MAKE_RCSID("$NetBSD: var.c,v 1.1117 2024/06/01 06:26:36 sjg Exp $"); /* * Variables are defined using one of the VAR=value assignments. Their @@ -838,9 +838,12 @@ ExportVarsExpand(const char *uvarnames, void Var_Export(VarExportMode mode, const char *varnames) { - if (mode == VEM_PLAIN && varnames[0] == '\0') { + if (mode == VEM_ALL) { var_exportedVars = VAR_EXPORTED_ALL; /* use with caution! */ return; + } else if (mode == VEM_PLAIN && varnames[0] == '\0') { + Parse_Error(PARSE_WARNING, ".export requires an argument."); + return; } ExportVarsExpand(varnames, true, mode); Index: src/usr.bin/make/unit-tests/directive-export.exp diff -u src/usr.bin/make/unit-tests/directive-export.exp:1.6 src/usr.bin/make/unit-tests/directive-export.exp:1.7 --- src/usr.bin/make/unit-tests/directive-export.exp:1.6 Sun Nov 19 09:45:19 2023 +++ src/usr.bin/make/unit-tests/directive-export.exp Sat Jun 1 06:26:36 2024 @@ -1,4 +1,5 @@ -make: "directive-export.mk" line 56: 00:00:00 -make: "directive-export.mk" line 61: 00:00:00 -make: "directive-export.mk" line 64: 16:00:00 +make: "directive-export.mk" line 33: warning: .export requires an argument. +make: "directive-export.mk" line 57: 00:00:00 +make: "directive-export.mk" line 62: 00:00:00 +make: "directive-export.mk" line 65: 16:00:00 exit status 0 Index: src/usr.bin/make/unit-tests/directive-export.mk diff -u src/usr.bin/make/unit-tests/directive-export.mk:1.10 src/usr.bin/make/unit-tests/directive-export.mk:1.11 --- src/usr.bin/make/unit-tests/directive-export.mk:1.10 Sun Nov 19 09:45:19 2023 +++ src/usr.bin/make/unit-tests/directive-export.mk Sat Jun 1 06:26:36 2024 @@ -1,4 +1,4 @@ -# $NetBSD: directive-export.mk,v 1.10 2023/11/19 09:45:19 rillig Exp $ +# $NetBSD: directive-export.mk,v 1.11 2024/06/01 06:26:36 sjg Exp $ # # Tests for the .export directive. # @@ -28,7 +28,8 @@ VAR= value $$ ${INDIRECT} . error .endif -# No syntactical argument means to export all variables. +# No syntactical argument used to mean export all variables. +# Since var.c 1.1117 2024/06/01 it causes a warning. .export # An empty argument means no additional variables to export. Index: src/usr.bin/make/unit-tests/export-all.mk diff -u src/usr.bin/make/unit-tests/export-all.mk:1.5 src/usr.bin/make/unit-tests/export-all.mk:1.6 --- src/usr.bin/make/unit-tests/export-all.mk:1.5 Sat Oct 24 08:50:17 2020 +++ src/usr.bin/make/unit-tests/export-all.mk Sat Jun 1 06:26:36 2024 @@ -1,4 +1,4 @@ -# $NetBSD: export-all.mk,v 1.5 2020/10/24 08:50:17 rillig Exp $ +# $NetBSD: export-all.mk,v 1.6 2024/06/01 06:26:36 sjg Exp $ UT_OK= good UT_F= fine @@ -15,7 +15,7 @@ UT_BADDIR= ${${here}/../${here:T}:L:${M_ # this will be ok UT_OKDIR= ${${here}/../${here:T}:L:${M_tA}:T} -.export +.export-all FILTER_CMD= grep ^UT_ .include "export.mk"