This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] [utils] Improve Python 3 compatibility for merge_archives.py
ClosedPublic

Authored by broadwaylamb on Aug 23 2019, 6:06 AM.

Details

Summary

Popen.communicate() method in Python 2 returns a pair of strings, and in Python 3 it returns a pair of byte-like objects unless universal_newlines is set to True. This led to the following error when using Python 3:

Traceback (most recent call last):
  File "<home>/llvm-project/libcxx/utils/merge_archives.py", line 156, in <module>
    main()
  File "<home>/llvm-project/libcxx/utils/merge_archives.py", line 152, in main
    cwd=temp_directory_root, verbose=args.verbose)
  File "<home>/llvm-project/libcxx/utils/merge_archives.py", line 70, in execute_command_verbose
    out, err, exitCode = execute_command(cmd, cwd=cwd)
  File "<home>/llvm-project/libcxx/utils/merge_archives.py", line 58, in execute_command
    p = subprocess.Popen(cmd, **kwargs)
  File "<python>/lib/subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "<python>/lib/subprocess.py", line 1119, in _execute_child
    args = list2cmdline(args)
  File "<python>/lib/subprocess.py", line 530, in list2cmdline
    needquote = (" " in arg) or ("\t" in arg) or not arg
TypeError: a bytes-like object is required, not 'str'

With this patch merge_archives.py works fine with Python 3

Diff Detail

Repository
rL LLVM

Event Timeline

broadwaylamb created this revision.Aug 23 2019, 6:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 23 2019, 6:06 AM
ldionne accepted this revision.Aug 23 2019, 8:02 AM
This revision is now accepted and ready to land.Aug 23 2019, 8:02 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptAug 23 2019, 8:07 AM