Home | History | Annotate | Line # | Download | only in unit-tests
directive-export-impl.mk revision 1.1
      1  1.1  rillig # $NetBSD: directive-export-impl.mk,v 1.1 2020/12/29 01:45:06 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.1  rillig #	VAR_EXPORTED (per variable)
     12  1.1  rillig #	VAR_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.1  rillig # export the variable but only marks it as VAR_EXPORTED and VAR_REEXPORT.
     26  1.1  rillig # After that, ExportVars registers the variable name in .MAKE.EXPORTED.
     27  1.1  rillig # That's all for now.
     28  1.1  rillig .export UT_VAR
     29  1.1  rillig 
     30  1.1  rillig # Evaluating this expression shows the variable flags in the debug log,
     31  1.1  rillig # which are VAR_EXPORTED|VAR_REEXPORT.
     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.1  rillig # Evaluating this expression shows the variable flags in the debug log,
     47  1.1  rillig # which are still VAR_EXPORTED|VAR_REEXPORT, which means that the variable
     48  1.1  rillig # is still marked as being re-exported for each child process.
     49  1.1  rillig : ${UT_VAR:N*}
     50  1.1  rillig 
     51  1.1  rillig # Now the referenced variable gets defined.  This does not influence anything
     52  1.1  rillig # in the process of exporting the variable value, though.
     53  1.1  rillig REF=		defined
     54  1.1  rillig 
     55  1.1  rillig # Nothing surprising here.  The variable UT_VAR gets exported, and this time,
     56  1.1  rillig # REF is defined and gets expanded into the exported environment variable.
     57  1.1  rillig .if ${:!echo "\$UT_VAR"!} != "<defined>"
     58  1.1  rillig .  error
     59  1.1  rillig .endif
     60  1.1  rillig 
     61  1.1  rillig all:
     62  1.1  rillig .MAKEFLAGS: -d0
     63