make(1): clean up Var_Export
This commit is contained in:
parent
80fcd08175
commit
b506ce346a
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: nonints.h,v 1.168 2020/12/12 21:20:30 rillig Exp $ */
|
||||
/* $NetBSD: nonints.h,v 1.169 2020/12/13 01:41:12 rillig Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1988, 1989, 1990, 1993
|
||||
|
@ -311,6 +311,15 @@ typedef enum VarParseResult {
|
|||
VPR_UNKNOWN = 0x0008
|
||||
} VarParseResult;
|
||||
|
||||
typedef enum VarExportMode {
|
||||
/* .export-env */
|
||||
VEM_NORMAL,
|
||||
/* .export: Initial export or update an already exported variable. */
|
||||
VEM_PARENT,
|
||||
/* .export-literal: Do not expand the variable value. */
|
||||
VEM_LITERAL
|
||||
} VarExportMode;
|
||||
|
||||
void Var_Delete(const char *, GNode *);
|
||||
void Var_Set(const char *, const char *, GNode *);
|
||||
void Var_SetWithFlags(const char *, const char *, GNode *, VarSetFlags);
|
||||
|
@ -324,7 +333,7 @@ VarParseResult Var_Subst(const char *, GNode *, VarEvalFlags, char **);
|
|||
void Var_Stats(void);
|
||||
void Var_Dump(GNode *);
|
||||
void Var_ReexportVars(void);
|
||||
void Var_Export(const char *);
|
||||
void Var_Export(VarExportMode, const char *);
|
||||
void Var_ExportVars(const char *);
|
||||
void Var_UnExport(const char *);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: parse.c,v 1.475 2020/12/13 01:07:54 rillig Exp $ */
|
||||
/* $NetBSD: parse.c,v 1.476 2020/12/13 01:41:12 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 1993
|
||||
|
@ -117,7 +117,7 @@
|
|||
#include "pathnames.h"
|
||||
|
||||
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
|
||||
MAKE_RCSID("$NetBSD: parse.c,v 1.475 2020/12/13 01:07:54 rillig Exp $");
|
||||
MAKE_RCSID("$NetBSD: parse.c,v 1.476 2020/12/13 01:41:12 rillig Exp $");
|
||||
|
||||
/* types and constants */
|
||||
|
||||
|
@ -2988,10 +2988,14 @@ ParseDirective(char *line)
|
|||
/* TODO: undefine all variables, not only the first */
|
||||
/* TODO: use Str_Words, like everywhere else */
|
||||
return TRUE;
|
||||
} else if (IsDirective(dir, dirlen, "export") ||
|
||||
IsDirective(dir, dirlen, "export-env") ||
|
||||
IsDirective(dir, dirlen, "export-literal")) {
|
||||
Var_Export(dir + strlen("export"));
|
||||
} else if (IsDirective(dir, dirlen, "export")) {
|
||||
Var_Export(VEM_PARENT, arg);
|
||||
return TRUE;
|
||||
} else if (IsDirective(dir, dirlen, "export-env")) {
|
||||
Var_Export(VEM_NORMAL, arg);
|
||||
return TRUE;
|
||||
} else if (IsDirective(dir, dirlen, "export-literal")) {
|
||||
Var_Export(VEM_LITERAL, arg);
|
||||
return TRUE;
|
||||
} else if (IsDirective(dir, dirlen, "unexport") ||
|
||||
IsDirective(dir, dirlen, "unexport-env")) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: var.c,v 1.730 2020/12/13 01:33:17 rillig Exp $ */
|
||||
/* $NetBSD: var.c,v 1.731 2020/12/13 01:41:12 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 1993
|
||||
|
@ -131,7 +131,7 @@
|
|||
#include "metachar.h"
|
||||
|
||||
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
|
||||
MAKE_RCSID("$NetBSD: var.c,v 1.730 2020/12/13 01:33:17 rillig Exp $");
|
||||
MAKE_RCSID("$NetBSD: var.c,v 1.731 2020/12/13 01:41:12 rillig Exp $");
|
||||
|
||||
/* A string that may need to be freed after use. */
|
||||
typedef struct FStr {
|
||||
|
@ -212,14 +212,6 @@ typedef struct Var {
|
|||
VarFlags flags;
|
||||
} Var;
|
||||
|
||||
typedef enum VarExportMode {
|
||||
VEM_NORMAL,
|
||||
/* Initial export or updating an already exported variable. */
|
||||
VEM_PARENT,
|
||||
/* Do not expand the variable value. */
|
||||
VEM_LITERAL
|
||||
} VarExportMode;
|
||||
|
||||
/*
|
||||
* Exporting vars is expensive so skip it if we can
|
||||
*/
|
||||
|
@ -578,7 +570,7 @@ ExportVar(const char *name, VarExportMode mode)
|
|||
return FALSE; /* nothing to do */
|
||||
|
||||
val = Buf_GetAll(&v->val, NULL);
|
||||
if (!(mode == VEM_LITERAL) && strchr(val, '$') != NULL) {
|
||||
if (mode != VEM_LITERAL && strchr(val, '$') != NULL) {
|
||||
char *expr;
|
||||
|
||||
if (parent) {
|
||||
|
@ -700,35 +692,16 @@ ExportVarsExpand(const char *uvarnames, Boolean isExport, VarExportMode mode)
|
|||
free(xvarnames);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is called when .export is seen or .MAKE.EXPORTED is modified.
|
||||
*
|
||||
* It is also called when any exported variable is modified.
|
||||
* XXX: Is it really?
|
||||
*
|
||||
* str has the format "[-env|-literal] varname...".
|
||||
*/
|
||||
/* Export the named variables, or all variables. */
|
||||
void
|
||||
Var_Export(const char *str)
|
||||
Var_Export(VarExportMode mode, const char *varnames)
|
||||
{
|
||||
VarExportMode mode;
|
||||
|
||||
if (str[0] == '\0') {
|
||||
if (mode == VEM_PARENT && varnames[0] == '\0') {
|
||||
var_exportedVars = VAR_EXPORTED_ALL; /* use with caution! */
|
||||
return;
|
||||
}
|
||||
|
||||
if (strncmp(str, "-env", 4) == 0) {
|
||||
str += 4;
|
||||
mode = VEM_NORMAL;
|
||||
} else if (strncmp(str, "-literal", 8) == 0) {
|
||||
str += 8;
|
||||
mode = VEM_LITERAL;
|
||||
} else {
|
||||
mode = VEM_PARENT;
|
||||
}
|
||||
|
||||
ExportVarsExpand(str, TRUE, mode);
|
||||
ExportVarsExpand(varnames, TRUE, mode);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in New Issue