[libcxx-commits] [PATCH] D66649: [libcxx] [utils] Improve Python 3 compatibility for merge_archives.py

Sergej Jaskiewicz via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Aug 23 06:07:14 PDT 2019


broadwaylamb created this revision.
broadwaylamb added reviewers: EricWF, mclow.lists.
Herald added subscribers: libcxx-commits, ldionne, christof.
Herald added a project: libc++.

`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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66649

Files:
  libcxx/utils/merge_archives.py


Index: libcxx/utils/merge_archives.py
===================================================================
--- libcxx/utils/merge_archives.py
+++ libcxx/utils/merge_archives.py
@@ -50,7 +50,8 @@
         'stdin': subprocess.PIPE,
         'stdout': subprocess.PIPE,
         'stderr': subprocess.PIPE,
-        'cwd': cwd
+        'cwd': cwd,
+        'universal_newlines': True
     }
     p = subprocess.Popen(cmd, **kwargs)
     out, err = p.communicate()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66649.216820.patch
Type: text/x-patch
Size: 458 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190823/87c1e3ef/attachment.bin>


More information about the libcxx-commits mailing list