@@ -30,7 +30,7 @@ def __init__(self):
3030 self .is_submake = False
3131
3232
33- def execute (cmd_str , symbol_table , use_default_shell = True ):
33+ def execute (cmd_str , symbol_table , use_default_shell = True , capture = True ):
3434 """execute a string with the shell, returning a bunch of useful info"""
3535
3636 # capture a timestamp so we can match shell debug messages
@@ -79,7 +79,7 @@ def execute(cmd_str, symbol_table, use_default_shell=True):
7979 if shell :
8080 cmd .extend (shell_list )
8181 if shellflags :
82- cmd .append ( shellflags )
82+ cmd .extend ([ f for f in shellflags . split ()] )
8383 cmd .append (cmd_str )
8484
8585 env = symbol_table .get_exports ()
@@ -115,21 +115,36 @@ def execute(cmd_str, symbol_table, use_default_shell=True):
115115# outfile.write(" ".join(cmd))
116116# outfile.write("\n\n\n")
117117
118+ # definitely need to capture stdout when we're running a sub-make because
119+ # that's how we determine the shell arguments to the actual sub-make
120+ if cmd_str .startswith (submake .getname ()):
121+ capture = True
122+
123+ logger .debug ("cmd=>>>%s<<<" , cmd )
124+
118125 try :
119- p = subprocess .run (cmd ,
120- shell = False ,
121- stdout = subprocess .PIPE ,
122- stderr = subprocess .PIPE ,
123- universal_newlines = True ,
124- check = False , # we'll check returncode ourselves
125- env = env
126- )
126+ if capture :
127+ p = subprocess .run (cmd ,
128+ shell = False ,
129+ stdout = subprocess .PIPE ,
130+ universal_newlines = True ,
131+ check = False , # we'll check returncode ourselves
132+ env = env
133+ )
134+ else :
135+ p = subprocess .run (cmd ,
136+ shell = False ,
137+ universal_newlines = True ,
138+ check = False , # we'll check returncode ourselves
139+ env = env
140+ )
141+
127142 logger .debug ("shell ts=%f exit status=%r" , ts , p .returncode )
128143# if p.returncode != 0:
129144# breakpoint()
130145 return_status .exit_code = p .returncode
131146 return_status .stdout = p .stdout
132- return_status .stderr = p .stderr
147+ # return_status.stderr = p.stderr
133148 except OSError as err :
134149 logger .error ("shell ts=%f error=\" %s\" " , ts , err )
135150 return_status .exit_code = 127
@@ -165,9 +180,10 @@ def execute_tokens(token_list, symbol_table):
165180 symbol_table .allow_recursion ()
166181
167182 # GNU Make returns one whitespace separated string, no CR/LF
168- # "all other newlines are replaced by spaces." gnu_make.pdf
183+ # "If the result of the execution ends in a newline, that one newline is
184+ # removed; all other newlines are replaced by spaces." GNU Make PDF
169185 exe_result .stdout = exe_result .stdout .strip ().replace ("\n " , " " )
170- exe_result .stderr = exe_result .stderr .strip ().replace ("\n " , " " )
186+ # exe_result.stderr = exe_result.stderr.strip().replace("\n", " ")
171187
172188 # save shell status
173189 pos = token_list [0 ].get_pos ()
@@ -188,7 +204,7 @@ def execute_tokens(token_list, symbol_table):
188204 # otherwise report stderr (if any)
189205 if exe_result .stderr :
190206 logger .error ("command at %r failed with exit_code=%d" , pos , exe_result .exit_code )
191- error_message (pos , exe_result .stderr )
207+ # error_message(pos, exe_result.stderr)
192208 else :
193209 logger .error ("command at %r failed with exit_code=%d (but stderr empty)" , pos , exe_result .exit_code )
194210
0 commit comments