From 2061c94e6fd9d9383421ab205d39ac92b46b149f Mon Sep 17 00:00:00 2001 From: "Simon J. Gerraty" Date: Fri, 22 Apr 2022 13:34:55 -0700 Subject: [PATCH 1/2] Import bmake-20220418 Most relevant change: o ignore '.POSIX:' if not in first non-comment line of Makefile as specified by POSIX. add unit-tests for above. --- ChangeLog | 18 +++++ FILES | 2 + VERSION | 2 +- bmake.1 | 22 +++--- bmake.cat1 | 13 ++-- cond.c | 6 +- main.c | 5 +- make.1 | 22 +++--- make.h | 13 +++- meta.c | 20 +++-- parse.c | 30 ++++---- targ.c | 5 +- unit-tests/Makefile | 28 +++---- unit-tests/depsrc-use.exp | 4 + unit-tests/depsrc-use.mk | 16 +++- unit-tests/depsrc-usebefore.exp | 46 ++++++++++-- unit-tests/depsrc-usebefore.mk | 104 +++++++++++++++++++++++--- unit-tests/deptgt-posix.exp | 1 + unit-tests/deptgt-posix.mk | 116 +++++++++++++++++++++++++++++ unit-tests/deptgt-silent-jobs.mk | 3 +- unit-tests/opt-debug-cond.mk | 6 +- unit-tests/varname-dot-suffixes.mk | 6 +- 22 files changed, 377 insertions(+), 111 deletions(-) create mode 100644 unit-tests/deptgt-posix.exp create mode 100644 unit-tests/deptgt-posix.mk diff --git a/ChangeLog b/ChangeLog index 653cf14f8802..c4d43ef82e62 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2022-04-18 Simon J Gerraty + + * VERSION (_MAKE_VERSION): 20220418 + Merge with NetBSD make, pick up + o ignore '.POSIX:' if not in first non-comment line + of Makefile as specified by POSIX. + add unit-tests for above. + o meta.c: make it easier to find usage of identifiers + o targ.c: add .USEBEFORE to Targ_PrintType + +2022-04-14 Simon J Gerraty + + * VERSION (_MAKE_VERSION): 20220414 + + * unit-tests/Makefile: simplify checks for shells with + BROKEN_TESTS, this helps with other Linux distros that + use dash. + 2022-03-30 Simon J Gerraty * VERSION (_MAKE_VERSION): 20220330 diff --git a/FILES b/FILES index 5e0c387885fb..ecdd3327a9de 100644 --- a/FILES +++ b/FILES @@ -274,6 +274,8 @@ unit-tests/deptgt-path.exp unit-tests/deptgt-path.mk unit-tests/deptgt-phony.exp unit-tests/deptgt-phony.mk +unit-tests/deptgt-posix.exp +unit-tests/deptgt-posix.mk unit-tests/deptgt-precious.exp unit-tests/deptgt-precious.mk unit-tests/deptgt-shell.exp diff --git a/VERSION b/VERSION index 9945186def18..ed97681843b1 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ # keep this compatible with sh and make -_MAKE_VERSION=20220330 +_MAKE_VERSION=20220418 diff --git a/bmake.1 b/bmake.1 index 29acad9ff0e9..8ebd54ed6e31 100644 --- a/bmake.1 +++ b/bmake.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: make.1,v 1.307 2022/03/26 15:39:58 sjg Exp $ +.\" $NetBSD: make.1,v 1.308 2022/04/18 15:06:27 rillig 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 March 24, 2022 +.Dd April 18, 2022 .Dt BMAKE 1 .Os .Sh NAME @@ -2291,17 +2291,15 @@ Apply the .Ic .PHONY attribute to any specified sources. .It Ic .POSIX -This should be the first non-comment line in a Makefile. -It results in the variable +If this is the first non-comment line in the main makefile, +the variable .Va %POSIX -being defined with the value -.Ql 1003.2 . -The first time -.Ic .POSIX -is encountered, the makefile -.Ql posix.mk -will be included if possible, -to provide POSIX compatible default rules. +is set to the value +.Ql 1003.2 +and the makefile +.Ql +is included if it exists, +to provide POSIX-compatible default rules. If .Nm is run with the diff --git a/bmake.cat1 b/bmake.cat1 index 8e58f40309ff..b4442ea67b2e 100644 --- a/bmake.cat1 +++ b/bmake.cat1 @@ -1468,12 +1468,11 @@ BMAKE(1) FreeBSD General Commands Manual BMAKE(1) .PHONY Apply the .PHONY attribute to any specified sources. - .POSIX This should be the first non-comment line in a Makefile. It re- - sults in the variable %POSIX being defined with the value - `1003.2'. The first time .POSIX is encountered, the makefile - `posix.mk' will be included if possible, to provide POSIX com- - patible default rules. If bmake is run with the -r flag, then - only `posix.mk' will contribute to the default rules. + .POSIX If this is the first non-comment line in the main makefile, the + variable %POSIX is set to the value `1003.2' and the makefile + `' is included if it exists, to provide POSIX-compati- + ble default rules. If bmake is run with the -r flag, then only + `posix.mk' will contribute to the default rules. .PRECIOUS Apply the .PRECIOUS attribute to any specified sources. If no @@ -1629,4 +1628,4 @@ BMAKE(1) FreeBSD General Commands Manual BMAKE(1) There is no way of escaping a space character in a filename. -FreeBSD 13.0 March 24, 2022 FreeBSD 13.0 +FreeBSD 13.0 April 18, 2022 FreeBSD 13.0 diff --git a/cond.c b/cond.c index 5217b41a62cc..3dd177d5acb8 100644 --- a/cond.c +++ b/cond.c @@ -1,4 +1,4 @@ -/* $NetBSD: cond.c,v 1.333 2022/03/03 19:46:31 rillig Exp $ */ +/* $NetBSD: cond.c,v 1.334 2022/04/15 09:33:20 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -95,7 +95,7 @@ #include "dir.h" /* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */ -MAKE_RCSID("$NetBSD: cond.c,v 1.333 2022/03/03 19:46:31 rillig Exp $"); +MAKE_RCSID("$NetBSD: cond.c,v 1.334 2022/04/15 09:33:20 rillig Exp $"); /* * Conditional expressions conform to this grammar: @@ -710,7 +710,7 @@ CondParser_FuncCallEmpty(CondParser *par, bool doEval, Token *out_token) return true; } -/* Parse a function call expression, such as 'defined(${file})'. */ +/* Parse a function call expression, such as 'exists(${file})'. */ static bool CondParser_FuncCall(CondParser *par, bool doEval, Token *out_token) { diff --git a/main.c b/main.c index 1f8e9481adc9..04ac7589027f 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.579 2022/03/22 23:37:09 rillig Exp $ */ +/* $NetBSD: main.c,v 1.580 2022/04/18 15:06:27 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.579 2022/03/22 23:37:09 rillig Exp $"); +MAKE_RCSID("$NetBSD: main.c,v 1.580 2022/04/18 15:06:27 rillig Exp $"); #if defined(MAKE_NATIVE) && !defined(lint) __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 " "The Regents of the University of California. " @@ -1507,6 +1507,7 @@ main_ReadFiles(void) if (!opts.noBuiltins) ReadBuiltinRules(); + posix_state = PS_MAYBE_NEXT_LINE; if (!Lst_IsEmpty(&opts.makefiles)) ReadAllMakefiles(&opts.makefiles); else diff --git a/make.1 b/make.1 index cc740811b8a8..7c44356eefc7 100644 --- a/make.1 +++ b/make.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: make.1,v 1.307 2022/03/26 15:39:58 sjg Exp $ +.\" $NetBSD: make.1,v 1.308 2022/04/18 15:06:27 rillig 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 March 24, 2022 +.Dd April 18, 2022 .Dt MAKE 1 .Os .Sh NAME @@ -2291,17 +2291,15 @@ Apply the .Ic .PHONY attribute to any specified sources. .It Ic .POSIX -This should be the first non-comment line in a Makefile. -It results in the variable +If this is the first non-comment line in the main makefile, +the variable .Va %POSIX -being defined with the value -.Ql 1003.2 . -The first time -.Ic .POSIX -is encountered, the makefile -.Ql posix.mk -will be included if possible, -to provide POSIX compatible default rules. +is set to the value +.Ql 1003.2 +and the makefile +.Ql +is included if it exists, +to provide POSIX-compatible default rules. If .Nm is run with the diff --git a/make.h b/make.h index b9538a1fd7d5..9b73b04abb74 100644 --- a/make.h +++ b/make.h @@ -1,4 +1,4 @@ -/* $NetBSD: make.h,v 1.299 2022/03/26 14:02:40 rillig Exp $ */ +/* $NetBSD: make.h,v 1.300 2022/04/18 15:06:27 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -522,6 +522,17 @@ typedef struct GNode { unsigned lineno; } GNode; +/* + * Keep track of whether to include when parsing the line + * '.POSIX:'. + */ +extern enum PosixState { + PS_NOT_YET, + PS_MAYBE_NEXT_LINE, + PS_NOW_OR_NEVER, + PS_TOO_LATE +} posix_state; + /* Error levels for diagnostics during parsing. */ typedef enum ParseErrorLevel { /* diff --git a/meta.c b/meta.c index 86155b10afb0..f400485d25c0 100644 --- a/meta.c +++ b/meta.c @@ -1,4 +1,4 @@ -/* $NetBSD: meta.c,v 1.199 2022/03/04 23:17:16 sjg Exp $ */ +/* $NetBSD: meta.c,v 1.200 2022/04/15 12:28:16 rillig Exp $ */ /* * Implement 'meta' mode. @@ -387,12 +387,10 @@ printCMDs(GNode *gn, FILE *fp) /* * Certain node types never get a .meta file */ -#define SKIP_META_TYPE(_type) do { \ - if ((gn->type & __CONCAT(OP_, _type))) { \ - if (verbose) { \ - debug_printf("Skipping meta for %s: .%s\n", \ - gn->name, __STRING(_type)); \ - } \ +#define SKIP_META_TYPE(flag, str) do { \ + if ((gn->type & (flag))) { \ + if (verbose) \ + debug_printf("Skipping meta for %s: .%s\n", gn->name, str); \ return false; \ } \ } while (false) @@ -413,12 +411,12 @@ meta_needed(GNode *gn, const char *dname, /* This may be a phony node which we don't want meta data for... */ /* Skip .meta for .BEGIN, .END, .ERROR etc as well. */ /* Or it may be explicitly flagged as .NOMETA */ - SKIP_META_TYPE(NOMETA); + SKIP_META_TYPE(OP_NOMETA, "NOMETA"); /* Unless it is explicitly flagged as .META */ if (!(gn->type & OP_META)) { - SKIP_META_TYPE(PHONY); - SKIP_META_TYPE(SPECIAL); - SKIP_META_TYPE(MAKE); + SKIP_META_TYPE(OP_PHONY, "PHONY"); + SKIP_META_TYPE(OP_SPECIAL, "SPECIAL"); + SKIP_META_TYPE(OP_MAKE, "MAKE"); } /* Check if there are no commands to execute. */ diff --git a/parse.c b/parse.c index 06243d008e64..398c594f523e 100644 --- a/parse.c +++ b/parse.c @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.668 2022/03/25 21:16:04 sjg Exp $ */ +/* $NetBSD: parse.c,v 1.670 2022/04/18 16:09:05 sjg Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -121,7 +121,7 @@ #include "pathnames.h" /* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: parse.c,v 1.668 2022/03/25 21:16:04 sjg Exp $"); +MAKE_RCSID("$NetBSD: parse.c,v 1.670 2022/04/18 16:09:05 sjg Exp $"); /* * A file being read. @@ -309,6 +309,7 @@ static const struct { { ".WAIT", SP_WAIT, OP_NONE }, }; +enum PosixState posix_state = PS_NOT_YET; static IncludedFile * GetInclude(size_t i) @@ -1267,23 +1268,14 @@ HandleDependencySourcesEmpty(ParseSpecial special, SearchPathList *paths) break; #ifdef POSIX case SP_POSIX: - Global_Set("%POSIX", "1003.2"); - { - static bool first_posix = true; - + if (posix_state == PS_NOW_OR_NEVER) { /* - * Since .POSIX: should be the first - * operative line in a makefile, - * if '-r' flag is used, no default rules have - * been read yet, in which case 'posix.mk' can - * be a substiute for 'sys.mk'. - * If '-r' is not used, then 'posix.mk' acts - * as an extension of 'sys.mk'. + * With '-r', 'posix.mk' (if it exists) + * can effectively substitute for 'sys.mk', + * otherwise it is an extension. */ - if (first_posix) { - first_posix = false; - IncludeFile("posix.mk", true, false, true); - } + Global_Set("%POSIX", "1003.2"); + IncludeFile("posix.mk", true, false, true); } break; #endif @@ -2605,6 +2597,10 @@ ReadHighLevelLine(void) for (;;) { line = ReadLowLevelLine(LK_NONEMPTY); + if (posix_state == PS_MAYBE_NEXT_LINE) + posix_state = PS_NOW_OR_NEVER; + else + posix_state = PS_TOO_LATE; if (line == NULL) return NULL; diff --git a/targ.c b/targ.c index 52c5531845d8..7ce495c73b01 100644 --- a/targ.c +++ b/targ.c @@ -1,4 +1,4 @@ -/* $NetBSD: targ.c,v 1.176 2022/01/07 20:50:35 rillig Exp $ */ +/* $NetBSD: targ.c,v 1.177 2022/04/15 12:19:28 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -107,7 +107,7 @@ #include "dir.h" /* "@(#)targ.c 8.2 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: targ.c,v 1.176 2022/01/07 20:50:35 rillig Exp $"); +MAKE_RCSID("$NetBSD: targ.c,v 1.177 2022/04/15 12:19:28 rillig Exp $"); /* * All target nodes that appeared on the left-hand side of one of the @@ -410,6 +410,7 @@ Targ_PrintType(GNodeType type) { OP_IGNORE, false, "IGNORE" }, { OP_EXEC, false, "EXEC" }, { OP_USE, false, "USE" }, + { OP_USEBEFORE, false, "USEBEFORE" }, { OP_OPTIONAL, false, "OPTIONAL" }, }; size_t i; diff --git a/unit-tests/Makefile b/unit-tests/Makefile index 7141223714e2..c3b64abad84a 100644 --- a/unit-tests/Makefile +++ b/unit-tests/Makefile @@ -1,6 +1,6 @@ -# $Id: Makefile,v 1.178 2022/03/26 23:10:27 sjg Exp $ +# $Id: Makefile,v 1.180 2022/04/18 21:25:37 sjg Exp $ # -# $NetBSD: Makefile,v 1.311 2022/03/26 12:44:57 rillig Exp $ +# $NetBSD: Makefile,v 1.312 2022/04/18 15:06:28 rillig Exp $ # # Unit tests for make(1) # @@ -142,6 +142,7 @@ TESTS+= deptgt-order TESTS+= deptgt-path TESTS+= deptgt-path-suffix TESTS+= deptgt-phony +TESTS+= deptgt-posix TESTS+= deptgt-precious TESTS+= deptgt-shell TESTS+= deptgt-silent @@ -440,31 +441,26 @@ TESTS+= varparse-mod TESTS+= varparse-undef-partial TESTS+= varquote -# for now at least -.if ${.SHELL:T} == "ksh" +# some shells have quirks +_shell := ${.SHELL:tA:T} +.if ${_shell} == "dash" +# dash fails -x output +BROKEN_TESTS+= opt-debug-x-trace +.elif ${_shell} == "ksh" BROKEN_TESTS+= sh-flags .endif + .if ${.MAKE.OS:NDarwin} == "" BROKEN_TESTS+= shell-ksh .endif -.if ${.MAKE.OS} == "Linux" && ${.SHELL:tA:T} != "bash" -.if exists(/etc/os-release) -distro!= . /etc/os-release && echo $$NAME -.endif -# dash fails -x output -# .SHELL is not bash so may be dash -# if distro is Ubuntu or we cannot tell, assume the worst -.if ${distro:U:NUbuntu} == "" -BROKEN_TESTS+= opt-debug-x-trace -.endif -.endif + .if ${.MAKE.OS} == "SCO_SV" BROKEN_TESTS+= \ opt-debug-graph[23] \ varmod-localtime \ varmod-to-separator \ -.if ${.SHELL:T} == "bash" +.if ${_shell} == "bash" BROKEN_TESTS+= job-output-null .else BROKEN_TESTS+= \ diff --git a/unit-tests/depsrc-use.exp b/unit-tests/depsrc-use.exp index c9810bda462d..d31b9e70eb30 100644 --- a/unit-tests/depsrc-use.exp +++ b/unit-tests/depsrc-use.exp @@ -2,5 +2,9 @@ first 1 first 2 second 1 second 2 +first-first 1 +first-first 2 +first-second 1 +first-second 2 directly exit status 0 diff --git a/unit-tests/depsrc-use.mk b/unit-tests/depsrc-use.mk index 3f73a5f04ad9..ea2cf25bfb6a 100644 --- a/unit-tests/depsrc-use.mk +++ b/unit-tests/depsrc-use.mk @@ -1,7 +1,11 @@ -# $NetBSD: depsrc-use.mk,v 1.5 2021/12/28 14:22:51 rillig Exp $ +# $NetBSD: depsrc-use.mk,v 1.6 2022/04/18 14:38:24 rillig Exp $ # # Tests for the special source .USE in dependency declarations, # which allows to append common commands to other targets. +# +# See also: +# .USEBEFORE +# depsrc-usebefore.mk # Before make.h 1.280 from 2021-12-28, a .USEBEFORE target was accidentally # regarded as a candidate for the main target. On the other hand, a .USE @@ -10,9 +14,15 @@ not-a-main-candidate: .USE all: action directly -first: .USE +first: .USE first-first first-second @echo first 1 # Using ${.TARGET} here would expand to "action" @echo first 2 +first-first: .USE + @echo first-first 1 + @echo first-first 2 +first-second: .USE + @echo first-second 1 + @echo first-second 2 second: .USE @echo second 1 @@ -22,7 +32,7 @@ second: .USE # This may happen as the result of expanding a .for loop. empty: .USE -# It's possible but uncommon to directly make a .USEBEFORE target. +# It's possible but uncommon to directly make a .USE target. directly: .USE @echo directly diff --git a/unit-tests/depsrc-usebefore.exp b/unit-tests/depsrc-usebefore.exp index c9810bda462d..d84299b66275 100644 --- a/unit-tests/depsrc-usebefore.exp +++ b/unit-tests/depsrc-usebefore.exp @@ -1,6 +1,42 @@ -first 1 -first 2 -second 1 -second 2 -directly +after-2-before-2 1 +after-2-before-2 2 +after-2-before-1 1 +after-2-before-1 2 +after-1-before-2 1 +after-1-before-2 2 +after-1-before-1 1 +after-1-before-1 2 +before-2-before-2 1 +before-2-before-2 2 +before-2-before-1 1 +before-2-before-1 2 +before-1-before-2 1 +before-1-before-2 2 +before-1-before-1 1 +before-1-before-1 2 +before-2 1 +before-2 2 +before-1 1 +before-1 2 +after-1 1 +after-1 2 +after-2 1 +after-2 2 +before-1-after-1 1 +before-1-after-1 2 +before-1-after-2 1 +before-1-after-2 2 +before-2-after-1 1 +before-2-after-1 2 +before-2-after-2 1 +before-2-after-2 2 +after-1-after-1 1 +after-1-after-1 2 +after-1-after-2 1 +after-1-after-2 2 +after-2-after-1 1 +after-2-after-1 2 +after-2-after-2 1 +after-2-after-2 2 +`directly' is up to date. exit status 0 diff --git a/unit-tests/depsrc-usebefore.mk b/unit-tests/depsrc-usebefore.mk index 58b3145e4f3f..672fb7144856 100644 --- a/unit-tests/depsrc-usebefore.mk +++ b/unit-tests/depsrc-usebefore.mk @@ -1,8 +1,14 @@ -# $NetBSD: depsrc-usebefore.mk,v 1.7 2021/12/28 14:22:51 rillig Exp $ +# $NetBSD: depsrc-usebefore.mk,v 1.9 2022/04/18 14:41:42 rillig Exp $ # # Tests for the special source .USEBEFORE in dependency declarations, # which allows to prepend common commands to other targets. # +# If a target depends on several .USE or .USEBEFORE nodes, the commands get +# appended or prepended in declaration order. For .USE nodes, this is the +# expected order, for .USEBEFORE nodes the order is somewhat reversed, and for +# .USE or .USEBEFORE nodes that depend on other .USE or .USEBEFORE nodes, it +# gets even more complicated. +# # See also: # .USE # depsrc-use.mk @@ -12,22 +18,98 @@ # target was not. not-a-main-candidate: .USEBEFORE -all: action directly +all: + @${MAKE} -r -f ${MAKEFILE} ordering + @${MAKE} -r -f ${MAKEFILE} directly -first: .USEBEFORE - @echo first 1 # Using ${.TARGET} here would expand to "action" - @echo first 2 # Using ${.TARGET} here would expand to "action" +ordering: before-1 before-2 after-1 after-2 -second: .USEBEFORE - @echo second 1 - @echo second 2 +before-1: .USEBEFORE before-1-before-1 before-1-before-2 before-1-after-1 before-1-after-2 + @echo before-1 1 + @echo before-1 2 + +before-1-before-1: .USEBEFORE + @echo before-1-before-1 1 + @echo before-1-before-1 2 + +before-1-before-2: .USEBEFORE + @echo before-1-before-2 1 + @echo before-1-before-2 2 + +before-1-after-1: .USE + @echo before-1-after-1 1 + @echo before-1-after-1 2 + +before-1-after-2: .USE + @echo before-1-after-2 1 + @echo before-1-after-2 2 + +before-2: .USEBEFORE before-2-before-1 before-2-before-2 before-2-after-1 before-2-after-2 + @echo before-2 1 + @echo before-2 2 + +before-2-before-1: .USEBEFORE + @echo before-2-before-1 1 + @echo before-2-before-1 2 + +before-2-before-2: .USEBEFORE + @echo before-2-before-2 1 + @echo before-2-before-2 2 + +before-2-after-1: .USE + @echo before-2-after-1 1 + @echo before-2-after-1 2 + +before-2-after-2: .USE + @echo before-2-after-2 1 + @echo before-2-after-2 2 + +after-1: .USE after-1-before-1 after-1-before-2 after-1-after-1 after-1-after-2 + @echo after-1 1 + @echo after-1 2 + +after-1-before-1: .USEBEFORE + @echo after-1-before-1 1 + @echo after-1-before-1 2 + +after-1-before-2: .USEBEFORE + @echo after-1-before-2 1 + @echo after-1-before-2 2 + +after-1-after-1: .USE + @echo after-1-after-1 1 + @echo after-1-after-1 2 + +after-1-after-2: .USE + @echo after-1-after-2 1 + @echo after-1-after-2 2 + +after-2: .USE after-2-before-1 after-2-before-2 after-2-after-1 after-2-after-2 + @echo after-2 1 + @echo after-2 2 + +after-2-before-1: .USEBEFORE + @echo after-2-before-1 1 + @echo after-2-before-1 2 + +after-2-before-2: .USEBEFORE + @echo after-2-before-2 1 + @echo after-2-before-2 2 + +after-2-after-1: .USE + @echo after-2-after-1 1 + @echo after-2-after-1 2 + +after-2-after-2: .USE + @echo after-2-after-2 1 + @echo after-2-after-2 2 # It is possible but uncommon to have a .USEBEFORE target with no commands. # This may happen as the result of expanding a .for loop. empty: .USEBEFORE -# It is possible but uncommon to directly make a .USEBEFORE target. +# It is technically possible to directly make a .USEBEFORE target, but it +# doesn't make sense since GNode_IsOODate considers such a target to always be +# up to date. directly: .USEBEFORE @echo directly - -action: second first empty diff --git a/unit-tests/deptgt-posix.exp b/unit-tests/deptgt-posix.exp new file mode 100644 index 000000000000..39a9383953dd --- /dev/null +++ b/unit-tests/deptgt-posix.exp @@ -0,0 +1 @@ +exit status 0 diff --git a/unit-tests/deptgt-posix.mk b/unit-tests/deptgt-posix.mk new file mode 100644 index 000000000000..ae41af15ffec --- /dev/null +++ b/unit-tests/deptgt-posix.mk @@ -0,0 +1,116 @@ +# $NetBSD: deptgt-posix.mk,v 1.2 2022/04/18 15:59:39 sjg Exp $ +# +# Tests for the special target '.POSIX', which enables POSIX mode. +# +# As of 2022-04-18, this only means that the variable '%POSIX' is defined and +# that the variables and rules specified by POSIX replace the default ones. +# This is done by loading , if available. That file is not included +# in NetBSD, but only in the bmake distribution. As of 2022-04-18, POSIX +# support is not complete. +# +# Implementation node: this test needs to be isolated from the usual test +# to prevent unit-tests/posix.mk from interfering with the posix.mk from the +# system directory that this test uses. +# +# See also: +# https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html + +TESTTMP= ${TMPDIR:U/tmp}/make.test.deptgt-posix +SYSDIR= ${TESTTMP}/sysdir +MAIN_MK= ${TESTTMP}/main.mk +INCLUDED_MK= ${TESTTMP}/included.mk + +all: .PHONY +.SILENT: + +set-up-sysdir: .USEBEFORE + mkdir -p ${SYSDIR} + printf '%s\n' > ${SYSDIR}/sys.mk \ + 'CC=sys-cc' \ + 'SEEN_SYS_MK=yes' + printf '%s\n' > ${SYSDIR}/posix.mk \ + 'CC=posix-cc' + +check-is-posix: .USE + printf '%s\n' >> ${MAIN_MK} \ + '.if $${CC} != "posix-cc"' \ + '. error' \ + '.endif' \ + '.if $${%POSIX} != "1003.2"' \ + '. error' \ + '.endif' \ + 'all: .PHONY' + +check-not-posix: .USE + printf '%s\n' >> ${MAIN_MK} \ + '.if $${CC} != "sys-cc"' \ + '. error' \ + '.endif' \ + '.if defined(%POSIX)' \ + '. error' \ + '.endif' \ + 'all: .PHONY' + +check-not-seen-sys-mk: .USE + printf '%s\n' >> ${MAIN_MK} \ + '.if defined(SEEN_SYS_MK)' \ + '. error' \ + '.endif' + +run: .USE + (cd "${TESTTMP}" && MAKEFLAGS=${MAKEFLAGS.${.TARGET}:Q} ${MAKE} \ + -m "${SYSDIR}" -f ${MAIN_MK:T}) + rm -rf ${TESTTMP} + +# If the main makefile has a '.for' loop as its first non-comment line, a +# strict reading of POSIX 2018 makes the makefile non-conforming. +all: after-for +after-for: .PHONY set-up-sysdir check-not-posix run + printf '%s\n' > ${MAIN_MK} \ + '# comment' \ + '' \ + '.for i in once' \ + '.POSIX:' \ + '.endfor' + +# If the main makefile has an '.if' conditional as its first non-comment line, +# a strict reading of POSIX 2018 makes the makefile non-conforming. +all: after-if +after-if: .PHONY set-up-sysdir check-not-posix run + printf '%s\n' > ${MAIN_MK} \ + '# comment' \ + '' \ + '.if 1' \ + '.POSIX:' \ + '.endif' + +# If the main makefile first includes another makefile and that included +# makefile tries to switch to POSIX mode, that's too late. +all: in-included-file +in-included-file: .PHONY set-up-sysdir check-not-posix run + printf 'include included.mk\n' > ${MAIN_MK} + printf '.POSIX:\n' > ${INCLUDED_MK} + +# If the main makefile switches to POSIX mode in its very first line, before +# and comment lines or empty lines, that works. +all: in-first-line +in-first-line: .PHONY set-up-sysdir check-is-posix run + printf '%s\n' > ${MAIN_MK} \ + '.POSIX:' + +# The only allowed lines before switching to POSIX mode are comment lines. +# POSIX defines that empty and blank lines are called comment lines as well. +all: after-comment-lines +after-comment-lines: .PHONY set-up-sysdir check-is-posix run + printf '%s\n' > ${MAIN_MK} \ + '# comment' \ + '' \ + '.POSIX:' + +# Running make with the option '-r' skips the builtin rules from . +# In that mode, '.POSIX:' just loads , which works as well. +MAKEFLAGS.no-builtins= -r +all: no-builtins +no-builtins: .PHONY set-up-sysdir check-is-posix check-not-seen-sys-mk run + printf '%s\n' > ${MAIN_MK} \ + '.POSIX:' diff --git a/unit-tests/deptgt-silent-jobs.mk b/unit-tests/deptgt-silent-jobs.mk index e16cca3b8016..aed85932281b 100644 --- a/unit-tests/deptgt-silent-jobs.mk +++ b/unit-tests/deptgt-silent-jobs.mk @@ -1,4 +1,4 @@ -# $NetBSD: deptgt-silent-jobs.mk,v 1.2 2022/02/12 11:14:48 rillig Exp $ +# $NetBSD: deptgt-silent-jobs.mk,v 1.3 2022/04/15 09:33:20 rillig Exp $ # # Ensure that the special dependency target '.SILENT' only affects the amount # of output, but not the kind of error handling. @@ -28,7 +28,6 @@ compat: @${MAKE} -r -f ${MAKEFILE} test VARIANT=compat # expect: jobs: testing 1 -# expect: echo 'jobs: testing 2' # expect: jobs: testing 2 # expect: jobs: testing 3 jobs: diff --git a/unit-tests/opt-debug-cond.mk b/unit-tests/opt-debug-cond.mk index 056996cf0ece..28ad59587789 100644 --- a/unit-tests/opt-debug-cond.mk +++ b/unit-tests/opt-debug-cond.mk @@ -1,4 +1,4 @@ -# $NetBSD: opt-debug-cond.mk,v 1.2 2022/01/23 16:09:38 rillig Exp $ +# $NetBSD: opt-debug-cond.mk,v 1.3 2022/04/15 09:33:20 rillig Exp $ # # Tests for the -dc command line option, which adds debug logging for the # evaluation of conditional expressions, such as in .if directives and @@ -7,11 +7,11 @@ .MAKEFLAGS: -dc # expect: CondParser_Eval: ${:U12345} > ${:U55555} -# expect: lhs = 12345.000000, rhs = 55555.000000, op = > +# expect: Comparing 12345.000000 > 55555.000000 .if ${:U12345} > ${:U55555} # expect: CondParser_Eval: "string" != "string" -# expect: lhs = "string", rhs = "string", op = != +# expect: Comparing "string" != "string" .elif "string" != "string" # expect: CondParser_Eval: "nonempty" diff --git a/unit-tests/varname-dot-suffixes.mk b/unit-tests/varname-dot-suffixes.mk index babbe20d1c7c..f9f995fcd845 100644 --- a/unit-tests/varname-dot-suffixes.mk +++ b/unit-tests/varname-dot-suffixes.mk @@ -1,4 +1,4 @@ -# $NetBSD: varname-dot-suffixes.mk,v 1.2 2022/01/15 12:35:18 rillig Exp $ +# $NetBSD: varname-dot-suffixes.mk,v 1.3 2022/04/15 09:33:20 rillig Exp $ # # Tests for the special "variable" .SUFFIXES, which lists the suffixes that # have been registered for use in suffix transformation rules. Suffixes are @@ -51,7 +51,7 @@ # Deleting .SUFFIXES has no effect since there is no actual variable of that # name. .MAKEFLAGS: -dv -# expect: Global:delete .SUFFIXES (not found) +# expect: Global: delete .SUFFIXES (not found) .undef .SUFFIXES .MAKEFLAGS: -d0 .if ${.SUFFIXES} != ".c .o .1 .err .tar.gz" @@ -97,7 +97,7 @@ _:= ${preserve:L:_=.SUFFIXES} # expect: Command: .SUFFIXES = 1 ignored (read-only) # expect: Command: .SUFFIXES = 2 ignored (read-only) # XXX: Missing space after ':' -# expect: Command:delete .SUFFIXES (not found) +# expect: Command: delete .SUFFIXES (not found) .if ${1 2:L:@.SUFFIXES@${.SUFFIXES}@} != ".c .o .1 .err .tar.gz .c .o .1 .err .tar.gz" . error .endif From 92bfae0e6bd53a7a0d6fe55e70a916d86cf26e8b Mon Sep 17 00:00:00 2001 From: "Simon J. Gerraty" Date: Fri, 22 Apr 2022 13:38:42 -0700 Subject: [PATCH 2/2] Add -m to post.sh --- import.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/import.sh b/import.sh index 08f352609fe8..a233cba9c9cc 100755 --- a/import.sh +++ b/import.sh @@ -84,7 +84,7 @@ if [ -z "$ECHO" ]; then test -s $TF.rm && xargs rm -f < $TF.rm $GIT add -A $GIT diff --staged | tee $SB/tmp/bmake-import.diff - { echo "$GIT tag -a vendor/NetBSD/bmake/$VERSION" + { echo "$GIT tag -a -m \"Tag bmake/$VERSION\" vendor/NetBSD/bmake/$VERSION" echo "echo \"When ready do: $GIT push --follow-tags\"" } > $SB/tmp/bmake-post.sh echo "After you commit, run $SB/tmp/bmake-post.sh"