chromium - gn 脚本使用错误的 Python 版本 ("a bytes-like object is required, not ' str'")

标签 chromium build-system build-script gn

使用 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/

相关文章:

php - 为什么从浏览器启动的 php 脚本只执行一个?

javascript - 是否有可能在*不*捆绑浏览器的情况下构建独立的 HTML5 应用程序?

Android 什么是工具链兼容性问题?

gradle - 如何让 Gradle 按一定顺序运行任务?

qt - Qbs 构建规则如何使用产品

Android Gradle Ant SCP 任务

selenium-webdriver - 如何在Windows 32位机器中配置ChromeDriver环境变量

selenium - Chromium --disable-cookie-encryption 不起作用

javascript - 创建前端开发构建系统的正确方法

android - Android.bp 和 Android.mk 之间的区别