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
This commit is contained in:
parent
f8e0665918
commit
cdcc95b114
|
@ -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 unexporting variables are:
|
|||
.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 programs,
|
|||
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 ,
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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"))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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_tAbad}:T}
|
|||
# this will be ok
|
||||
UT_OKDIR= ${${here}/../${here:T}:L:${M_tA}:T}
|
||||
|
||||
.export
|
||||
.export-all
|
||||
|
||||
FILTER_CMD= grep ^UT_
|
||||
.include "export.mk"
|
||||
|
|
|
@ -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, bool isExport, VarExportMode mode)
|
|||
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);
|
||||
|
|
Loading…
Reference in New Issue