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(1): add tests for the .BEGIN node



details:   https://anonhg.NetBSD.org/src/rev/95868184541f
branches:  trunk
changeset: 946088:95868184541f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Nov 15 20:47:01 2020 +0000

description:
make(1): add tests for the .BEGIN node

diffstat:

 usr.bin/make/unit-tests/deptgt-begin.exp |   3 ++
 usr.bin/make/unit-tests/deptgt-begin.mk  |  37 +++++++++++++++++++++++++++++++-
 2 files changed, 39 insertions(+), 1 deletions(-)

diffs (62 lines):

diff -r b54e756c31cf -r 95868184541f usr.bin/make/unit-tests/deptgt-begin.exp
--- a/usr.bin/make/unit-tests/deptgt-begin.exp  Sun Nov 15 20:20:58 2020 +0000
+++ b/usr.bin/make/unit-tests/deptgt-begin.exp  Sun Nov 15 20:47:01 2020 +0000
@@ -1,4 +1,7 @@
+make: "deptgt-begin.mk" line 17: warning: duplicate script for target ".BEGIN" ignored
+make: "deptgt-begin.mk" line 8: warning: using previous script for ".BEGIN" defined here
 : parse time
+: Making before-begin before .BEGIN.
 : .BEGIN
 : all
 exit status 0
diff -r b54e756c31cf -r 95868184541f usr.bin/make/unit-tests/deptgt-begin.mk
--- a/usr.bin/make/unit-tests/deptgt-begin.mk   Sun Nov 15 20:20:58 2020 +0000
+++ b/usr.bin/make/unit-tests/deptgt-begin.mk   Sun Nov 15 20:47:01 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: deptgt-begin.mk,v 1.3 2020/08/29 17:34:21 rillig Exp $
+# $NetBSD: deptgt-begin.mk,v 1.4 2020/11/15 20:47:01 rillig Exp $
 #
 # Tests for the special target .BEGIN in dependency declarations,
 # which is a container for commands that are run before any other
@@ -7,6 +7,41 @@
 .BEGIN:
        : $@
 
+# To register a custom action to be run at the beginning, the simplest way is
+# to directly place some commands on the '.BEGIN' target.  This doesn't scale
+# though, since the ':' dependency operator prevents that any other place may
+# add its commands after this.
+#
+# There are several ways to resolve this situation, which are detailed below.
+.BEGIN:
+       : Making another $@.
+
+# One way to run commands at the beginning is to define a custom target and
+# make the .BEGIN depend on that target.  This way, the commands from the
+# custom target are run even before the .BEGIN target.
+.BEGIN: before-begin
+before-begin: .PHONY .NOTMAIN
+       : Making $@ before .BEGIN.
+
+# Another way is to define a custom target and make that a .USE dependency.
+# This way, its commands are appended to the commands of the .BEGIN target
+# just before the .BEGIN target is made.
+#
+# XXX: For some reason, the commands from the .USE target are not run.
+# XXX: .USE nodes should not be candidates for the .MAIN node.
+.BEGIN: use
+use: .USE .NOTMAIN
+       : Making $@ from a .USE dependency.
+
+# Same as with .USE, but run the commands before the main commands from the
+# .BEGIN target.
+#
+# XXX: For some reason, the commands from the .USEBEFORE target are not run.
+# XXX: .USEBEFORE nodes should not be candidates for the .MAIN node.
+.BEGIN: use-before
+use-before: .USEBEFORE .NOTMAIN
+       : Making $@ from a .USEBEFORE dependency.
+
 all:
        : $@
 



Home | Main Index | Thread Index | Old Index