Module Name: src Committed By: rillig Date: Sat Nov 23 22:59:52 UTC 2024
Modified Files: src/usr.bin/make: main.c var.c src/usr.bin/make/unit-tests: varname-dot-make-level.exp varname-dot-make-level.mk Log Message: make: fix confusing error message when overriding a read-only variable To generate a diff of this commit: cvs rdiff -u -r1.635 -r1.636 src/usr.bin/make/main.c cvs rdiff -u -r1.1140 -r1.1141 src/usr.bin/make/var.c cvs rdiff -u -r1.3 -r1.4 \ src/usr.bin/make/unit-tests/varname-dot-make-level.exp cvs rdiff -u -r1.4 -r1.5 \ src/usr.bin/make/unit-tests/varname-dot-make-level.mk 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/main.c diff -u src/usr.bin/make/main.c:1.635 src/usr.bin/make/main.c:1.636 --- src/usr.bin/make/main.c:1.635 Sun Nov 10 02:39:14 2024 +++ src/usr.bin/make/main.c Sat Nov 23 22:59:51 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.635 2024/11/10 02:39:14 sjg Exp $ */ +/* $NetBSD: main.c,v 1.636 2024/11/23 22:59:51 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -111,7 +111,7 @@ #include "trace.h" /* "@(#)main.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: main.c,v 1.635 2024/11/10 02:39:14 sjg Exp $"); +MAKE_RCSID("$NetBSD: main.c,v 1.636 2024/11/23 22:59:51 rillig Exp $"); #if defined(MAKE_NATIVE) __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 " "The Regents of the University of California. " @@ -1392,7 +1392,8 @@ main_Init(int argc, char **argv) /* Set some other useful variables. */ { - char buf[64], *ep = getenv(MAKE_LEVEL_ENV); + char buf[64]; + const char *ep = getenv(MAKE_LEVEL_ENV); makelevel = ep != NULL && ep[0] != '\0' ? atoi(ep) : 0; if (makelevel < 0) Index: src/usr.bin/make/var.c diff -u src/usr.bin/make/var.c:1.1140 src/usr.bin/make/var.c:1.1141 --- src/usr.bin/make/var.c:1.1140 Sat Aug 31 06:21:27 2024 +++ src/usr.bin/make/var.c Sat Nov 23 22:59:51 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.1140 2024/08/31 06:21:27 rillig Exp $ */ +/* $NetBSD: var.c,v 1.1141 2024/11/23 22:59:51 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -128,7 +128,7 @@ #include "metachar.h" /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: var.c,v 1.1140 2024/08/31 06:21:27 rillig Exp $"); +MAKE_RCSID("$NetBSD: var.c,v 1.1141 2024/11/23 22:59:51 rillig Exp $"); /* * Variables are defined using one of the VAR=value assignments. Their @@ -1035,7 +1035,14 @@ Var_SetWithFlags(GNode *scope, const cha * * See ExistsInCmdline. */ - Var_Delete(SCOPE_GLOBAL, name); + Var *gl = VarFind(name, SCOPE_GLOBAL, false); + if (gl != NULL && gl->readOnlyLoud) + Parse_Error(PARSE_FATAL, + "Cannot override " + "read-only global variable \"%s\" " + "with a command line variable", name); + else + Var_Delete(SCOPE_GLOBAL, name); } if (strcmp(name, ".SUFFIXES") == 0) { /* special: treat as read-only */ Index: src/usr.bin/make/unit-tests/varname-dot-make-level.exp diff -u src/usr.bin/make/unit-tests/varname-dot-make-level.exp:1.3 src/usr.bin/make/unit-tests/varname-dot-make-level.exp:1.4 --- src/usr.bin/make/unit-tests/varname-dot-make-level.exp:1.3 Sat Nov 23 22:48:09 2024 +++ src/usr.bin/make/unit-tests/varname-dot-make-level.exp Sat Nov 23 22:59:51 2024 @@ -1,7 +1,7 @@ level 1: variable 0, env 1 level 2: variable 1, env 2 level 3: variable 2, env 3 -make: Cannot delete ".MAKE.LEVEL.ENV" as it is read-only +make: Cannot override read-only global variable ".MAKE.LEVEL.ENV" with a command line variable make: Fatal errors encountered -- cannot continue make: stopped in unit-tests *** Error code 1 (continuing) Index: src/usr.bin/make/unit-tests/varname-dot-make-level.mk diff -u src/usr.bin/make/unit-tests/varname-dot-make-level.mk:1.4 src/usr.bin/make/unit-tests/varname-dot-make-level.mk:1.5 --- src/usr.bin/make/unit-tests/varname-dot-make-level.mk:1.4 Sat Nov 23 22:48:09 2024 +++ src/usr.bin/make/unit-tests/varname-dot-make-level.mk Sat Nov 23 22:59:51 2024 @@ -1,4 +1,4 @@ -# $NetBSD: varname-dot-make-level.mk,v 1.4 2024/11/23 22:48:09 rillig Exp $ +# $NetBSD: varname-dot-make-level.mk,v 1.5 2024/11/23 22:59:51 rillig Exp $ # # Tests for the special .MAKE.LEVEL variable, which informs about the # recursion level. It is related to the environment variable MAKELEVEL, @@ -24,7 +24,6 @@ level_3: .PHONY .endif -# FIXME: The error message "Cannot delete" is confusing. -# expect: make: Cannot delete ".MAKE.LEVEL.ENV" as it is read-only +# expect: make: Cannot override read-only global variable ".MAKE.LEVEL.ENV" with a command line variable set-env: @${MAKE} -f /dev/null .MAKE.LEVEL.ENV=MAKELEVEL