Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make Add .SHELL as read-only variable
details: https://anonhg.NetBSD.org/src/rev/9199bf6e658d
branches: trunk
changeset: 937633:9199bf6e658d
user: sjg <sjg%NetBSD.org@localhost>
date: Sat Aug 22 19:30:58 2020 +0000
description:
Add .SHELL as read-only variable
The .SHELL variable represents the shellPath used to run
scripts.
Reviewed by: rillig, christos
diffstat:
usr.bin/make/job.c | 7 ++++---
usr.bin/make/make.1 | 7 +++++--
usr.bin/make/nonints.h | 9 ++++++++-
usr.bin/make/unit-tests/export.exp | 1 -
usr.bin/make/var.c | 33 +++++++++++++++++++++++----------
5 files changed, 40 insertions(+), 17 deletions(-)
diffs (193 lines):
diff -r 0a0ef8625a32 -r 9199bf6e658d usr.bin/make/job.c
--- a/usr.bin/make/job.c Sat Aug 22 19:27:22 2020 +0000
+++ b/usr.bin/make/job.c Sat Aug 22 19:30:58 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: job.c,v 1.212 2020/08/22 15:43:32 rillig Exp $ */
+/* $NetBSD: job.c,v 1.213 2020/08/22 19:30:58 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: job.c,v 1.212 2020/08/22 15:43:32 rillig Exp $";
+static char rcsid[] = "$NetBSD: job.c,v 1.213 2020/08/22 19:30:58 sjg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: job.c,v 1.212 2020/08/22 15:43:32 rillig Exp $");
+__RCSID("$NetBSD: job.c,v 1.213 2020/08/22 19:30:58 sjg Exp $");
#endif
#endif /* not lint */
#endif
@@ -2201,6 +2201,7 @@
#endif
shellPath = str_concat3(_PATH_DEFSHELLDIR, "/", shellName);
}
+ Var_Set_with_flags(".SHELL", shellPath, VAR_CMD, VAR_SET_READONLY);
if (commandShell->exit == NULL) {
commandShell->exit = "";
}
diff -r 0a0ef8625a32 -r 9199bf6e658d usr.bin/make/make.1
--- a/usr.bin/make/make.1 Sat Aug 22 19:27:22 2020 +0000
+++ b/usr.bin/make/make.1 Sat Aug 22 19:30:58 2020 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: make.1,v 1.287 2020/08/19 06:10:06 rillig Exp $
+.\" $NetBSD: make.1,v 1.288 2020/08/22 19:30:58 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 August 19, 2020
+.Dd August 22, 2020
.Dt MAKE 1
.Os
.Sh NAME
@@ -1140,6 +1140,9 @@
for all programs which
.Nm
executes.
+.It Ev .SHELL
+The pathname of the shell used to run target scripts.
+It is read-only.
.It Ev .TARGETS
The list of targets explicitly specified on the command line, if any.
.It Ev VPATH
diff -r 0a0ef8625a32 -r 9199bf6e658d usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h Sat Aug 22 19:27:22 2020 +0000
+++ b/usr.bin/make/nonints.h Sat Aug 22 19:30:58 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nonints.h,v 1.95 2020/08/21 23:28:11 rillig Exp $ */
+/* $NetBSD: nonints.h,v 1.96 2020/08/22 19:30:58 sjg Exp $ */
/*-
* Copyright (c) 1988, 1989, 1990, 1993
@@ -186,8 +186,15 @@
VARE_ASSIGN = 0x04
} VarEvalFlags;
+typedef enum {
+ VAR_NO_EXPORT = 0x01, /* do not export */
+ VAR_SET_READONLY = 0x02
+} VarSet_Flags;
+
+
void Var_Delete(const char *, GNode *);
void Var_Set(const char *, const char *, GNode *);
+void Var_Set_with_flags(const char *, const char *, GNode *, VarSet_Flags);
void Var_Append(const char *, const char *, GNode *);
Boolean Var_Exists(const char *, GNode *);
const char *Var_Value(const char *, GNode *, char **);
diff -r 0a0ef8625a32 -r 9199bf6e658d usr.bin/make/unit-tests/export.exp
--- a/usr.bin/make/unit-tests/export.exp Sat Aug 22 19:27:22 2020 +0000
+++ b/usr.bin/make/unit-tests/export.exp Sat Aug 22 19:30:58 2020 +0000
@@ -1,5 +1,4 @@
&=ampersand
-.MAKE.LEVEL.ENV=MAKELEVEL
MAKELEVEL=1
UT_DOLLAR=This is $UT_FU
UT_FOO=foobar is fubar
diff -r 0a0ef8625a32 -r 9199bf6e658d usr.bin/make/var.c
--- a/usr.bin/make/var.c Sat Aug 22 19:27:22 2020 +0000
+++ b/usr.bin/make/var.c Sat Aug 22 19:30:58 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.456 2020/08/22 17:34:25 rillig Exp $ */
+/* $NetBSD: var.c,v 1.457 2020/08/22 19:30:58 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.456 2020/08/22 17:34:25 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.457 2020/08/22 19:30:58 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.456 2020/08/22 17:34:25 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.457 2020/08/22 19:30:58 sjg Exp $");
#endif
#endif /* not lint */
#endif
@@ -229,7 +229,8 @@
* variable can then be resolved. */
VAR_REEXPORT = 0x20,
/* The variable came from command line. */
- VAR_FROM_CMD = 0x40
+ VAR_FROM_CMD = 0x40,
+ VAR_READONLY = 0x80
} VarFlags;
ENUM_RTTI_7(VarFlags,
@@ -281,10 +282,6 @@
VARP_ANCHOR_END = 0x08 /* Match at end of word */
} VarPatternFlags;
-typedef enum {
- VAR_NO_EXPORT = 0x01 /* do not export */
-} VarSet_Flags;
-
#define BROPEN '{'
#define BRCLOSE '}'
#define PROPEN '('
@@ -346,6 +343,12 @@
if (strcmp(name, ".PREFIX") == 0)
name = PREFIX;
break;
+ case 'S':
+ if (strcmp(name, ".SHELL") == 0 ) {
+ if (!shellPath)
+ Shell_Init();
+ }
+ break;
case 'T':
if (strcmp(name, ".TARGET") == 0)
name = TARGET;
@@ -771,7 +774,7 @@
}
/* See Var_Set for documentation. */
-static void
+void
Var_Set_with_flags(const char *name, const char *val, GNode *ctxt,
VarSet_Flags flags)
{
@@ -817,7 +820,16 @@
Var_Delete(name, VAR_GLOBAL);
}
VarAdd(name, val, ctxt);
+ if (flags & VAR_SET_READONLY) {
+ v = VarFind(name, ctxt, 0);
+ v->flags |= VAR_READONLY;
+ }
} else {
+ if ((v->flags & VAR_READONLY) && !(flags & VAR_SET_READONLY)) {
+ VAR_DEBUG("%s:%s = %s ignored (read-only)\n",
+ ctxt->name, name, val);
+ goto out;
+ }
Buf_Empty(&v->val);
if (val)
Buf_AddStr(&v->val, val);
@@ -830,8 +842,9 @@
/*
* Any variables given on the command line are automatically exported
* to the environment (as per POSIX standard)
+ * Other than internals.
*/
- if (ctxt == VAR_CMD && !(flags & VAR_NO_EXPORT)) {
+ if (ctxt == VAR_CMD && !(flags & VAR_NO_EXPORT) && name[0] != '.') {
if (v == NULL) {
/* we just added it */
v = VarFind(name, ctxt, 0);
Home |
Main Index |
Thread Index |
Old Index