Home | History | Annotate | Line # | Download | only in unit-tests
opt-debug-file.mk revision 1.5
      1 # $NetBSD: opt-debug-file.mk,v 1.5 2021/12/27 22:04:20 rillig Exp $
      2 #
      3 # Tests for the -dF command line option, which redirects the debug log
      4 # to a file instead of writing it to stderr.
      5 
      6 # Enable debug logging for variable assignments and evaluation (-dv)
      7 # and redirect the debug logging to the given file.
      8 .MAKEFLAGS: -dvFopt-debug-file.debuglog
      9 
     10 # This output goes to the debug log file.
     11 VAR=	value ${:Uexpanded}
     12 
     13 # Hide the logging output for the remaining actions.
     14 # As of 2020-10-03, it is not possible to disable debug logging again.
     15 .MAKEFLAGS: -dF/dev/null
     16 
     17 # Make sure that the debug logging file contains some logging.
     18 DEBUG_OUTPUT:=	${:!cat opt-debug-file.debuglog!}
     19 # Grmbl.  Because of the := operator in the above line, the variable
     20 # value contains ${:Uexpanded}.  This variable expression is expanded
     21 # upon further processing.  Therefore, don't read from untrusted input.
     22 #.MAKEFLAGS: -dc -dFstderr
     23 .if !${DEBUG_OUTPUT:tW:M*VAR = value expanded*}
     24 .  error ${DEBUG_OUTPUT}
     25 .endif
     26 
     27 # To get the unexpanded text that was actually written to the debug log
     28 # file, the content of that log file must not be stored in a variable.
     29 # XXX: In the :M modifier, a dollar is escaped as '$$', not '\$'.
     30 .if !${:!cat opt-debug-file.debuglog!:tW:M*VAR = value $${:Uexpanded}*}
     31 .  error
     32 .endif
     33 
     34 
     35 # If the debug log file cannot be opened, make prints an error message.
     36 .MAKEFLAGS: -dFopt-debug-file.debuglog/file
     37 
     38 # Clean up
     39 _!=	rm opt-debug-file.debuglog
     40 
     41 all:
     42