Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make/unit-tests make: .[NO]READONLY for control of r...



details:   https://anonhg.NetBSD.org/src/rev/a09d68841c0b
branches:  trunk
changeset: 373206:a09d68841c0b
user:      sjg <sjg%NetBSD.org@localhost>
date:      Mon Jan 23 23:01:52 2023 +0000

description:
make: .[NO]READONLY for control of read-only variables

Reviewed by: rillig

diffstat:

 distrib/sets/lists/tests/mi      |   4 +++-
 usr.bin/make/make.1              |   8 ++++++--
 usr.bin/make/make.h              |   3 ++-
 usr.bin/make/parse.c             |  30 ++++++++++++++++++++++++------
 usr.bin/make/unit-tests/Makefile |   3 ++-
 usr.bin/make/var.c               |  20 ++++++++++++++++++--
 6 files changed, 55 insertions(+), 13 deletions(-)

diffs (231 lines):

diff -r a304fab1a443 -r a09d68841c0b distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Mon Jan 23 22:20:59 2023 +0000
+++ b/distrib/sets/lists/tests/mi       Mon Jan 23 23:01:52 2023 +0000
@@ -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
diff -r a304fab1a443 -r a09d68841c0b usr.bin/make/make.1
--- a/usr.bin/make/make.1       Mon Jan 23 22:20:59 2023 +0000
+++ b/usr.bin/make/make.1       Mon Jan 23 23:01:52 2023 +0000
@@ -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 @@
 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 @@
 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
diff -r a304fab1a443 -r a09d68841c0b usr.bin/make/make.h
--- a/usr.bin/make/make.h       Mon Jan 23 22:20:59 2023 +0000
+++ b/usr.bin/make/make.h       Mon Jan 23 23:01:52 2023 +0000
@@ -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_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 *);
diff -r a304fab1a443 -r a09d68841c0b usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Mon Jan 23 22:20:59 2023 +0000
+++ b/usr.bin/make/parse.c      Mon Jan 23 23:01:52 2023 +0000
@@ -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 @@
        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 @@
        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 @@
     { ".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 @@
     { ".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 @@
        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 @@
        }
 
        /* 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 @@
                }
                if (special == SP_PATH)
                        Dir_SetPATH();
-       } else {
+               break;
+       default:
                assert(*inout_paths == NULL);
                if (!ParseDependencySourcesMundane(p, special, targetAttr))
                        return;
+               break;
        }
 
        MaybeUpdateMainTarget();
diff -r a304fab1a443 -r a09d68841c0b usr.bin/make/unit-tests/Makefile
--- a/usr.bin/make/unit-tests/Makefile  Mon Jan 23 22:20:59 2023 +0000
+++ b/usr.bin/make/unit-tests/Makefile  Mon Jan 23 23:01:52 2023 +0000
@@ -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+=                unexport
 TESTS+=                unexport-env
 TESTS+=                use-inference
+TESTS+=                var-readonly
 TESTS+=                var-scope
 TESTS+=                var-scope-cmdline
 TESTS+=                var-scope-env
diff -r a304fab1a443 -r a09d68841c0b usr.bin/make/var.c
--- a/usr.bin/make/var.c        Mon Jan 23 22:20:59 2023 +0000
+++ b/usr.bin/make/var.c        Mon Jan 23 23:01:52 2023 +0000
@@ -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 @@
 }
 
 /*
+ * 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.
  */



Home | Main Index | Thread Index | Old Index