@@ -176,6 +176,68 @@ def new(*args):
176176 else :
177177 logging .StreamHandler .emit = add_coloring_to_emit_ansi (logging .StreamHandler .emit )
178178
179+
180+ # https://docs.python.org/3/library/subprocess.html#subprocess.CompletedProcess
181+ class Py2CompletedProcess :
182+ def __init__ (self , process , args ):
183+ (self .stdout , self .stderr ) = process .communicate ()
184+ self .args = args
185+ self .returncode = process .returncode
186+
187+ def __repr__ (self ):
188+ _repr = ['args=%s, returncode=%s' % (self .args , self .returncode )]
189+ if self .stdout is not None :
190+ _repr += 'stdout=' + self .stdout
191+ if self .stderr is not None :
192+ _repr += 'stderr=' + self .stderr
193+ return 'CompletedProcess(%s)' % ', ' .join (_repr )
194+
195+ def check_returncode (self ):
196+ if self .returncode is not 0 :
197+ raise subprocess .CalledProcessError (returncode = self .returncode , cmd = self .args , output = self .stdout )
198+
199+ def run_base (cmd , check = False , * args , ** kw ):
200+ if hasattr (subprocess , "run" ):
201+ return subprocess .run (cmd , check = check , * args , ** kw )
202+
203+ # Python 2 compatibility: Introduce Python 3 subprocess.run-like behavior
204+ result = Py2CompletedProcess (Popen (cmd , * args , ** kw ), cmd )
205+ if check :
206+ result .check_returncode ()
207+ return result
208+
209+ def run_process (cmd , universal_newlines = True , * args , ** kw ):
210+ return run_base (cmd , universal_newlines = universal_newlines , * args , ** kw )
211+
212+ def execute (cmd , * args , ** kw ):
213+ try :
214+ cmd [0 ] = Building .remove_quotes (cmd [0 ])
215+ return Popen (cmd , universal_newlines = True , * args , ** kw ).communicate () # let compiler frontend print directly, so colors are saved (PIPE kills that)
216+ except :
217+ if not isinstance (cmd , str ):
218+ cmd = ' ' .join (cmd )
219+ logging .error ('Invoking Process failed: <<< ' + cmd + ' >>>' )
220+ raise
221+
222+ def check_execute (cmd , * args , ** kw ):
223+ # TODO: use in more places. execute doesn't actually check that return values
224+ # are nonzero
225+ try :
226+ subprocess .check_output (cmd , * args , ** kw )
227+ logging .debug ("Successfuly executed %s" % " " .join (cmd ))
228+ except subprocess .CalledProcessError as e :
229+ logging .error ("'%s' failed with output:\n %s" % (" " .join (e .cmd ), e .output ))
230+ raise
231+
232+ def check_call (cmd , * args , ** kw ):
233+ try :
234+ subprocess .check_call (cmd , * args , ** kw )
235+ logging .debug ("Successfully executed %s" % " " .join (cmd ))
236+ except subprocess .CalledProcessError as e :
237+ logging .error ("'%s' failed" % " " .join (cmd ))
238+ raise
239+
240+
179241# Emscripten configuration is done through the --em-config command line option or
180242# the EM_CONFIG environment variable. If the specified string value contains newline
181243# or semicolon-separated definitions, then these definitions will be used to configure
@@ -2536,65 +2598,6 @@ def make_shared_library(js_file, wasm_file):
25362598 f .close ()
25372599 return wso
25382600
2539- # https://docs.python.org/3/library/subprocess.html#subprocess.CompletedProcess
2540- class Py2CompletedProcess :
2541- def __init__ (self , process , args ):
2542- (self .stdout , self .stderr ) = process .communicate ()
2543- self .args = args
2544- self .returncode = process .returncode
2545-
2546- def __repr__ (self ):
2547- _repr = ['args=%s, returncode=%s' % (self .args , self .returncode )]
2548- if self .stdout is not None :
2549- _repr += 'stdout=' + self .stdout
2550- if self .stderr is not None :
2551- _repr += 'stderr=' + self .stderr
2552- return 'CompletedProcess(%s)' % ', ' .join (_repr )
2553-
2554- def check_returncode (self ):
2555- if self .returncode is not 0 :
2556- raise subprocess .CalledProcessError (returncode = self .returncode , cmd = self .args , output = self .stdout )
2557-
2558- def run_base (cmd , check = False , * args , ** kw ):
2559- if hasattr (subprocess , "run" ):
2560- return subprocess .run (cmd , check = check , * args , ** kw )
2561-
2562- # Python 2 compatibility: Introduce Python 3 subprocess.run-like behavior
2563- result = Py2CompletedProcess (Popen (cmd , * args , ** kw ), cmd )
2564- if check :
2565- result .check_returncode ()
2566- return result
2567-
2568- def run_process (cmd , universal_newlines = True , * args , ** kw ):
2569- return run_base (cmd , universal_newlines = universal_newlines , * args , ** kw )
2570-
2571- def execute (cmd , * args , ** kw ):
2572- try :
2573- cmd [0 ] = Building .remove_quotes (cmd [0 ])
2574- return Popen (cmd , universal_newlines = True , * args , ** kw ).communicate () # let compiler frontend print directly, so colors are saved (PIPE kills that)
2575- except :
2576- if not isinstance (cmd , str ):
2577- cmd = ' ' .join (cmd )
2578- logging .error ('Invoking Process failed: <<< ' + cmd + ' >>>' )
2579- raise
2580-
2581- def check_execute (cmd , * args , ** kw ):
2582- # TODO: use in more places. execute doesn't actually check that return values
2583- # are nonzero
2584- try :
2585- subprocess .check_output (cmd , * args , ** kw )
2586- logging .debug ("Successfuly executed %s" % " " .join (cmd ))
2587- except subprocess .CalledProcessError as e :
2588- logging .error ("'%s' failed with output:\n %s" % (" " .join (e .cmd ), e .output ))
2589- raise
2590-
2591- def check_call (cmd , * args , ** kw ):
2592- try :
2593- subprocess .check_call (cmd , * args , ** kw )
2594- logging .debug ("Successfully executed %s" % " " .join (cmd ))
2595- except subprocess .CalledProcessError as e :
2596- logging .error ("'%s' failed" % " " .join (cmd ))
2597- raise
25982601
25992602def suffix (name ):
26002603 """Return the file extension *not* including the '.'."""
0 commit comments