瀏覽代碼

fetch: Decode gclient output if returning stdout

In Python 3 the output of a subprocess is bytes, so they need to be decoded to be used as a string.

This previously caused the following error if there was an existing checkout during a fetch:
Traceback (most recent call last):
  File "C:\Google\depot_tools\\fetch.py", line 318, in <module>
    sys.exit(main())
  File "C:\Google\depot_tools\\fetch.py", line 313, in main
    return run(options, spec, root)
  File "C:\Google\depot_tools\\fetch.py", line 299, in run
    if not options.force and checkout.exists():
  File "C:\Google\depot_tools\\fetch.py", line 98, in exists
    return (os.path.exists(os.path.join(gclient_root, b'.gclient')) or
  File "C:\Program Files\Python38\lib\ntpath.py", line 109, in join
    genericpath._check_arg_types('join', path, *paths)
  File "C:\Program Files\Python38\lib\genericpath.py", line 151, in _check_arg_types
    raise TypeError("Can't mix strings and bytes in path components") from None
TypeError: Can't mix strings and bytes in path components

Bug: 939847
Change-Id: Ibf5b4923268595ba439586d688894f92696ecbb7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1701403
Auto-Submit: Raul Tambre <raul@tambre.ee>
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Commit-Queue: Raul Tambre <raul@tambre.ee>
Raul Tambre 6 年之前
父節點
當前提交
43271f94de
共有 1 個文件被更改,包括 1 次插入1 次删除
  1. 1 1
      fetch.py

+ 1 - 1
fetch.py

@@ -68,7 +68,7 @@ class Checkout(object):
     if self.options.dry_run:
     if self.options.dry_run:
       return ''
       return ''
     if return_stdout:
     if return_stdout:
-      return subprocess.check_output(cmd, **kwargs)
+      return subprocess.check_output(cmd, **kwargs).decode()
     else:
     else:
       try:
       try:
         subprocess.check_call(cmd, **kwargs)
         subprocess.check_call(cmd, **kwargs)