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