directive-export-impl.mk revision 1.3 1 1.3 rillig # $NetBSD: directive-export-impl.mk,v 1.3 2021/04/03 23:08:30 rillig Exp $
2 1.1 rillig #
3 1.1 rillig # Test for the implementation of exporting variables to child processes.
4 1.1 rillig # This involves marking variables for export, actually exporting them,
5 1.1 rillig # or marking them for being re-exported.
6 1.1 rillig #
7 1.1 rillig # See also:
8 1.1 rillig # Var_Export
9 1.1 rillig # ExportVar
10 1.1 rillig # VarExportedMode (global)
11 1.3 rillig # VarFlags.exported (per variable)
12 1.3 rillig # VarFlags.reexport (per variable)
13 1.1 rillig # VarExportMode (per call of Var_Export and ExportVar)
14 1.1 rillig
15 1.1 rillig : ${:U:sh} # side effect: initialize .SHELL
16 1.1 rillig
17 1.1 rillig .MAKEFLAGS: -dcpv
18 1.1 rillig
19 1.1 rillig # This is a variable that references another variable. At this point, the
20 1.1 rillig # other variable is still undefined.
21 1.1 rillig UT_VAR= <${REF}>
22 1.1 rillig
23 1.1 rillig # At this point, ExportVar("UT_VAR", VEM_PLAIN) is called. Since the
24 1.1 rillig # variable value refers to another variable, ExportVar does not actually
25 1.3 rillig # export the variable but only marks it as VarFlags.exported and
26 1.3 rillig # VarFlags.reexport. After that, ExportVars registers the variable name in
27 1.3 rillig # .MAKE.EXPORTED. That's all for now.
28 1.1 rillig .export UT_VAR
29 1.1 rillig
30 1.3 rillig # The following expression has both flags 'exported' and 'reexport' set.
31 1.3 rillig # These flags do not show up anywhere, not even in the debug log.
32 1.1 rillig : ${UT_VAR:N*}
33 1.1 rillig
34 1.1 rillig # At the last moment before actually forking off the child process for the
35 1.1 rillig # :!...! modifier, Cmd_Exec calls Var_ReexportVars to have all relevant
36 1.1 rillig # variables exported. Since this variable has both of the above-mentioned
37 1.1 rillig # flags set, it is actually exported to the environment. The variable flags
38 1.1 rillig # are not modified though, since the next time the :!...! modifier is
39 1.1 rillig # evaluated, the referenced variables could have changed, therefore the
40 1.1 rillig # variable will be exported anew for each ':sh' modifier, ':!...!' modifier,
41 1.1 rillig # '!=' variable assignment.
42 1.1 rillig .if ${:!echo "\$UT_VAR"!} != "<>"
43 1.1 rillig . error
44 1.1 rillig .endif
45 1.1 rillig
46 1.3 rillig # The following expression still has 'exported' and 'reexport' set.
47 1.3 rillig # These flags do not show up anywhere though, not even in the debug log.
48 1.3 rillig # These flags means that the variable is still marked as being re-exported
49 1.3 rillig # for each child process.
50 1.1 rillig : ${UT_VAR:N*}
51 1.1 rillig
52 1.1 rillig # Now the referenced variable gets defined. This does not influence anything
53 1.1 rillig # in the process of exporting the variable value, though.
54 1.1 rillig REF= defined
55 1.1 rillig
56 1.1 rillig # Nothing surprising here. The variable UT_VAR gets exported, and this time,
57 1.1 rillig # REF is defined and gets expanded into the exported environment variable.
58 1.1 rillig .if ${:!echo "\$UT_VAR"!} != "<defined>"
59 1.1 rillig . error
60 1.1 rillig .endif
61 1.1 rillig
62 1.1 rillig all:
63 1.1 rillig .MAKEFLAGS: -d0
64