Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/coreclr/scripts/jitutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,31 @@ def set_pipeline_variable(name, value):
print(define_variable_format.format(name, value)) # set variable



################################################################################
##
## Helper functions
##
################################################################################

def decode_string(str_to_decode):
"""Decode a UTF-8 encoded bytes to string.

Args:
str_to_decode (byte stream): Byte stream to decode

Returns:
String output. If there any encoding/decoding errors, it will replace it with
UnicodeEncodeError.
"""
try:
output = str_to_decode.decode("utf-8", errors='replace')
except UnicodeEncodeError:
output = "UnicodeEncodeError"
except UnicodeDecodeError:
output = "UnicodeDecodeError"
return output

def run_command(command_to_run, _cwd=None, _exit_on_fail=False, _output_file=None):
""" Runs the command.

Expand Down Expand Up @@ -119,15 +138,15 @@ def run_command(command_to_run, _cwd=None, _exit_on_fail=False, _output_file=Non
if proc.poll() is not None:
break
if output:
output_str = output.strip().decode("utf-8", errors='replace')
output_str = decode_string(output.strip())
print(output_str)
of.write(output_str + "\n")
else:
command_stdout, command_stderr = proc.communicate()
if len(command_stdout) > 0:
print(command_stdout.decode("utf-8", errors='replace'))
print(decode_string(command_stdout))
if len(command_stderr) > 0:
print(command_stderr.decode("utf-8", errors='replace'))
print(decode_string(command_stderr))

return_code = proc.returncode
if _exit_on_fail and return_code != 0:
Expand Down