Module Name:    src
Committed By:   sjg
Date:           Sat Aug 22 19:30:59 UTC 2020

Modified Files:
        src/usr.bin/make: job.c make.1 nonints.h var.c
        src/usr.bin/make/unit-tests: export.exp

Log Message:
Add .SHELL as read-only variable

The .SHELL variable represents the shellPath used to run
scripts.

Reviewed by: rillig, christos


To generate a diff of this commit:
cvs rdiff -u -r1.212 -r1.213 src/usr.bin/make/job.c
cvs rdiff -u -r1.287 -r1.288 src/usr.bin/make/make.1
cvs rdiff -u -r1.95 -r1.96 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.456 -r1.457 src/usr.bin/make/var.c
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/export.exp

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/job.c
diff -u src/usr.bin/make/job.c:1.212 src/usr.bin/make/job.c:1.213
--- src/usr.bin/make/job.c:1.212	Sat Aug 22 15:43:32 2020
+++ src/usr.bin/make/job.c	Sat Aug 22 19:30:58 2020
@@ -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 @@ Shell_Init(void)
 #endif
 	shellPath = str_concat3(_PATH_DEFSHELLDIR, "/", shellName);
     }
+    Var_Set_with_flags(".SHELL", shellPath, VAR_CMD, VAR_SET_READONLY);
     if (commandShell->exit == NULL) {
 	commandShell->exit = "";
     }

Index: src/usr.bin/make/make.1
diff -u src/usr.bin/make/make.1:1.287 src/usr.bin/make/make.1:1.288
--- src/usr.bin/make/make.1:1.287	Wed Aug 19 06:10:06 2020
+++ src/usr.bin/make/make.1	Sat Aug 22 19:30:58 2020
@@ -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 @@ is set to the value of
 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

Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.95 src/usr.bin/make/nonints.h:1.96
--- src/usr.bin/make/nonints.h:1.95	Fri Aug 21 23:28:11 2020
+++ src/usr.bin/make/nonints.h	Sat Aug 22 19:30:58 2020
@@ -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 @@ typedef enum {
     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 **);

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.456 src/usr.bin/make/var.c:1.457
--- src/usr.bin/make/var.c:1.456	Sat Aug 22 17:34:25 2020
+++ src/usr.bin/make/var.c	Sat Aug 22 19:30:58 2020
@@ -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 @@ typedef enum {
      * 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 @@ typedef enum {
     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 @@ VarFind(const char *name, GNode *ctxt, V
 	    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 @@ Var_UnExport(const char *str)
 }
 
 /* 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_Set_with_flags(const char *name, con
 	    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 @@ Var_Set_with_flags(const char *name, con
     /*
      * 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);

Index: src/usr.bin/make/unit-tests/export.exp
diff -u src/usr.bin/make/unit-tests/export.exp:1.3 src/usr.bin/make/unit-tests/export.exp:1.4
--- src/usr.bin/make/unit-tests/export.exp:1.3	Mon Jul 27 19:53:37 2020
+++ src/usr.bin/make/unit-tests/export.exp	Sat Aug 22 19:30:58 2020
@@ -1,5 +1,4 @@
 &=ampersand
-.MAKE.LEVEL.ENV=MAKELEVEL
 MAKELEVEL=1
 UT_DOLLAR=This is $UT_FU
 UT_FOO=foobar is fubar

Reply via email to