[utils] Force subprocess output to be read in text mode

In Python 3, subprocess output is read as binary data by default, which isn’t what we want.

Instead of reading process output as byte strings, then manually decoding them into strings, simply pass `text=True` to functions in the `subprocess` module, so that we get properly decoded strings right out the box.

This fixes places that forget to do the decoding step — most especially, the `update-checkout` script. That script prints Git output as byte strings, which leads to unreadable results.

Additionally, in shell.run, use the same pipe for capturing both stdout and stderr. The distinction is pretty pointless in this use case; however, keeping the two channels separate means that we lose the original ordering of printed messages, which does matter.
This commit is contained in:
Karoy Lorentey
2022-03-07 16:59:36 -08:00
parent 30d3950ade
commit bcddc9b7b9
5 changed files with 19 additions and 21 deletions

View File

@@ -32,7 +32,8 @@ def main(arguments):
# (rdar://78851265)
def unrpathize(filename):
dylibsOutput = subprocess.check_output(
['xcrun', 'dyldinfo', '-dylibs', filename])
['xcrun', 'dyldinfo', '-dylibs', filename],
text=True)
# Do not rewrite @rpath-relative load commands for these libraries:
# they are test support libraries that are never installed under
@@ -60,8 +61,7 @@ def unrpathize(filename):
# Build a command to invoke install_name_tool.
command = ['install_name_tool']
for binaryline in dylibsOutput.splitlines():
line = binaryline.decode("utf-8", "strict")
for line in dylibsOutput.splitlines():
match = dylib_regex.match(line)
if match and match.group('filename') not in allow_list:
command.append('-change')