使用 gn
构建 Chromium 或 libwebrtc 时在 macOS (Catalina 10.15) 上,我从 Python 构建脚本中收到关于 bytes
的错误和 str
.例如:
src [heads/master●] % gn gen out/ios_64 --args='target_os="ios" target_cpu="arm64"'
ERROR at //build/config/ios/ios_sdk.gni:109:21: Script returned non-zero exit code.
_ios_sdk_result = exec_script(script_name, ios_sdk_info_args, "scope")
^----------
Current dir: /Users/lynn/code/webrtc_ios/src/out/ios_64/
Command: python /Users/lynn/code/webrtc_ios/src/build/config/mac/sdk_info.py --get_sdk_info iphoneos
Returned 1.
stderr:
Traceback (most recent call last):
File "/Users/lynn/code/webrtc_ios/src/build/config/mac/sdk_info.py", line 107, in <module>
FillXcodeVersion(settings, args.developer_dir)
File "/Users/lynn/code/webrtc_ios/src/build/config/mac/sdk_info.py", line 59, in FillXcodeVersion
settings['xcode_version'] = FormatVersion(lines[0].split()[-1])
File "/Users/lynn/code/webrtc_ios/src/build/config/mac/sdk_info.py", line 43, in FormatVersion
major, minor, patch = SplitVersion(version)
File "/Users/lynn/code/webrtc_ios/src/build/config/mac/sdk_info.py", line 30, in SplitVersion
version = version.split('.')
TypeError: a bytes-like object is required, not 'str'
See //build/config/sysroot.gni:67:3: whence it was imported.
import("//build/config/ios/ios_sdk.gni")
^--------------------------------------
See //build/config/linux/pkg_config.gni:5:1: whence it was imported.
import("//build/config/sysroot.gni")
^----------------------------------
See //BUILD.gn:15:1: whence it was imported.
import("//build/config/linux/pkg_config.gni")
^-------------------------------------------
当我将有问题的 Python 脚本编辑为
print(sys.version)
时,它表明它正在运行 Python 3,即使脚本应该在 .vpython
中定义的捆绑虚拟 Python 2.7 环境中运行。 .如何配置
gn
使用适当的 Python 版本运行这些脚本?
最佳答案
好像exec_script
正在使用机器 Python 版本运行这些脚本。 gn help exec_script
说:
The default script interpreter is Python ("python" on POSIX, "python.exe" or "python.bat" on Windows). This can be configured by the script_executable variable, see "gn help dotfile".
对我来说,
python
指向 Python 3。所以我不得不将这一行添加到 .gn dotfile 的末尾:script_executable = "vpython"
现在构建使用在
.vpython
中定义的虚拟 Python。 ,这是 Python 2.7。(
vpython
可执行文件由 Chromium depot_tools 提供,就像 gn
一样。)
关于chromium - gn 脚本使用错误的 Python 版本 ("a bytes-like object is required, not ' str'"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59071125/