Module Name: src
Committed By: sjg
Date: Mon Jan 23 23:01:53 UTC 2023
Modified Files:
src/distrib/sets/lists/tests: mi
src/usr.bin/make: make.1 make.h parse.c var.c
src/usr.bin/make/unit-tests: Makefile
Log Message:
make: .[NO]READONLY for control of read-only variables
Reviewed by: rillig
To generate a diff of this commit:
cvs rdiff -u -r1.1247 -r1.1248 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.357 -r1.358 src/usr.bin/make/make.1
cvs rdiff -u -r1.309 -r1.310 src/usr.bin/make/make.h
cvs rdiff -u -r1.690 -r1.691 src/usr.bin/make/parse.c
cvs rdiff -u -r1.1036 -r1.1037 src/usr.bin/make/var.c
cvs rdiff -u -r1.329 -r1.330 src/usr.bin/make/unit-tests/Makefile
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1247 src/distrib/sets/lists/tests/mi:1.1248
--- src/distrib/sets/lists/tests/mi:1.1247 Sun Jan 22 17:17:24 2023
+++ src/distrib/sets/lists/tests/mi Mon Jan 23 23:01:52 2023
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1247 2023/01/22 17:17:24 rillig Exp $
+# $NetBSD: mi,v 1.1248 2023/01/23 23:01:52 sjg Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -6036,6 +6036,8 @@
./usr/tests/usr.bin/make/unit-tests/var-op-sunsh.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/var-op.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/var-op.mk tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/var-readonly.exp tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/var-readonly.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/var-recursive.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/var-recursive.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/var-scope-cmdline.exp tests-usr.bin-tests compattestfile,atf
Index: src/usr.bin/make/make.1
diff -u src/usr.bin/make/make.1:1.357 src/usr.bin/make/make.1:1.358
--- src/usr.bin/make/make.1:1.357 Sun Jan 1 21:02:09 2023
+++ src/usr.bin/make/make.1 Mon Jan 23 23:01:52 2023
@@ -1,4 +1,4 @@
-.\" $NetBSD: make.1,v 1.357 2023/01/01 21:02:09 rillig Exp $
+.\" $NetBSD: make.1,v 1.358 2023/01/23 23:01:52 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 January 1, 2023
+.Dd January 23, 2023
.Dt MAKE 1
.Os
.Sh NAME
@@ -2390,6 +2390,8 @@ Disable parallel mode.
Synonym for
.Ic .NOTPARALLEL ,
for compatibility with other pmake variants.
+.It Ic .NOREADONLY
+clear the read-only attribute from the global variables specified as sources.
.It Ic .OBJDIR
The source is a new value for
.Sq Va .OBJDIR .
@@ -2458,6 +2460,8 @@ attribute to any specified sources.
If no sources are specified, the
.Ic .PRECIOUS
attribute is applied to every target in the file.
+.It Ic .READONLY
+set the read-only attribute on the global variables specified as sources.
.It Ic .SHELL
Sets the shell that
.Nm
Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.309 src/usr.bin/make/make.h:1.310
--- src/usr.bin/make/make.h:1.309 Thu Jan 19 21:33:06 2023
+++ src/usr.bin/make/make.h Mon Jan 23 23:01:52 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: make.h,v 1.309 2023/01/19 21:33:06 rillig Exp $ */
+/* $NetBSD: make.h,v 1.310 2023/01/23 23:01:52 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -1026,6 +1026,7 @@ void Var_ReexportVars(void);
void Var_Export(VarExportMode, const char *);
void Var_ExportVars(const char *);
void Var_UnExport(bool, const char *);
+void Var_ReadOnly(const char *, bool);
void Global_Set(const char *, const char *);
void Global_Append(const char *, const char *);
Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.690 src/usr.bin/make/parse.c:1.691
--- src/usr.bin/make/parse.c:1.690 Tue Jan 3 00:00:45 2023
+++ src/usr.bin/make/parse.c Mon Jan 23 23:01:52 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.690 2023/01/03 00:00:45 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.691 2023/01/23 23:01:52 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.690 2023/01/03 00:00:45 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.691 2023/01/23 23:01:52 sjg Exp $");
/*
* A file being read.
@@ -149,6 +149,7 @@ typedef enum ParseSpecial {
SP_NOMETA, /* .NOMETA */
SP_NOMETA_CMP, /* .NOMETA_CMP */
SP_NOPATH, /* .NOPATH */
+ SP_NOREADONLY, /* .NOREADONLY */
SP_NOT, /* Not special */
SP_NOTPARALLEL, /* .NOTPARALLEL or .NO_PARALLEL */
SP_NULL, /* .NULL; not mentioned in the manual page */
@@ -161,6 +162,7 @@ typedef enum ParseSpecial {
SP_POSIX, /* .POSIX; not mentioned in the manual page */
#endif
SP_PRECIOUS, /* .PRECIOUS */
+ SP_READONLY, /* .READONLY */
SP_SHELL, /* .SHELL */
SP_SILENT, /* .SILENT */
SP_SINGLESHELL, /* .SINGLESHELL; not mentioned in the manual page */
@@ -269,6 +271,7 @@ static const struct {
{ ".NOMETA", SP_NOMETA, OP_NOMETA },
{ ".NOMETA_CMP", SP_NOMETA_CMP, OP_NOMETA_CMP },
{ ".NOPATH", SP_NOPATH, OP_NOPATH },
+ { ".NOREADONLY", SP_NOREADONLY, OP_NONE },
{ ".NOTMAIN", SP_ATTRIBUTE, OP_NOTMAIN },
{ ".NOTPARALLEL", SP_NOTPARALLEL, OP_NONE },
{ ".NO_PARALLEL", SP_NOTPARALLEL, OP_NONE },
@@ -283,6 +286,7 @@ static const struct {
{ ".POSIX", SP_POSIX, OP_NONE },
#endif
{ ".PRECIOUS", SP_PRECIOUS, OP_PRECIOUS },
+ { ".READONLY", SP_READONLY, OP_NONE },
{ ".RECURSIVE", SP_ATTRIBUTE, OP_MAKE },
{ ".SHELL", SP_SHELL, OP_NONE },
{ ".SILENT", SP_SILENT, OP_SILENT },
@@ -1306,12 +1310,18 @@ ParseDependencySourceSpecial(ParseSpecia
case SP_LIBS:
Suff_AddLib(word);
break;
+ case SP_NOREADONLY:
+ Var_ReadOnly(word, false);
+ break;
case SP_NULL:
Suff_SetNull(word);
break;
case SP_OBJDIR:
Main_SetObjdir(false, "%s", word);
break;
+ case SP_READONLY:
+ Var_ReadOnly(word, true);
+ break;
default:
break;
}
@@ -1524,9 +1534,15 @@ ParseDependencySources(char *p, GNodeTyp
}
/* Now go for the sources. */
- if (special == SP_SUFFIXES || special == SP_PATH ||
- special == SP_INCLUDES || special == SP_LIBS ||
- special == SP_NULL || special == SP_OBJDIR) {
+ switch (special) {
+ case SP_INCLUDES:
+ case SP_LIBS:
+ case SP_NOREADONLY:
+ case SP_NULL:
+ case SP_OBJDIR:
+ case SP_PATH:
+ case SP_READONLY:
+ case SP_SUFFIXES:
ParseDependencySourcesSpecial(p, special, *inout_paths);
if (*inout_paths != NULL) {
Lst_Free(*inout_paths);
@@ -1534,10 +1550,12 @@ ParseDependencySources(char *p, GNodeTyp
}
if (special == SP_PATH)
Dir_SetPATH();
- } else {
+ break;
+ default:
assert(*inout_paths == NULL);
if (!ParseDependencySourcesMundane(p, special, targetAttr))
return;
+ break;
}
MaybeUpdateMainTarget();
Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.1036 src/usr.bin/make/var.c:1.1037
--- src/usr.bin/make/var.c:1.1036 Mon Dec 5 23:41:24 2022
+++ src/usr.bin/make/var.c Mon Jan 23 23:01:52 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.1036 2022/12/05 23:41:24 rillig Exp $ */
+/* $NetBSD: var.c,v 1.1037 2023/01/23 23:01:52 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1036 2022/12/05 23:41:24 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1037 2023/01/23 23:01:52 sjg Exp $");
/*
* Variables are defined using one of the VAR=value assignments. Their
@@ -1222,6 +1222,22 @@ Var_Value(GNode *scope, const char *name
}
/*
+ * set readOnly attribute of specified var if it exists
+ */
+void
+Var_ReadOnly(const char *name, bool bf)
+{
+ Var *v;
+
+ v = VarFind(name, SCOPE_GLOBAL, false);
+ if (v == NULL) {
+ DEBUG1(VAR, "Var_ReadOnly: %s not found\n", name);
+ return;
+ }
+ v->readOnly = bf;
+}
+
+/*
* Return the unexpanded variable value from this node, without trying to look
* up the variable in any other scope.
*/
Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.329 src/usr.bin/make/unit-tests/Makefile:1.330
--- src/usr.bin/make/unit-tests/Makefile:1.329 Thu Jan 19 23:26:14 2023
+++ src/usr.bin/make/unit-tests/Makefile Mon Jan 23 23:01:52 2023
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.329 2023/01/19 23:26:14 rillig Exp $
+# $NetBSD: Makefile,v 1.330 2023/01/23 23:01:52 sjg Exp $
#
# Unit tests for make(1)
#
@@ -320,6 +320,7 @@ TESTS+= ternary
TESTS+= unexport
TESTS+= unexport-env
TESTS+= use-inference
+TESTS+= var-readonly
TESTS+= var-scope
TESTS+= var-scope-cmdline
TESTS+= var-scope-env