【问题标题】:Bazel fails to run xcrun but xcode and xcrun are installed properly locallyBazel 无法运行 xcrun 但 xcode 和 xcrun 已在本地正确安装
【发布时间】:2020-02-11 13:40:43
【问题描述】:

我正在尝试运行 bazel 构建。在这个过程中我看到了以下错误信息

调试: /private/var/tmp/_bazel_antkong/cf188c7bd288685357ff03fcbb494066/external/bazel_tools/tools/osx/xcode_configure.bzl:87:9: 调用 xcodebuild 失败,开发者目录: /Applications/Xcode.app/Contents/Developer,返回码 256,标准错误: java.io.IOException:无法运行程序“xcrun”(在目录中 “/private/var/tmp/_bazel_antkong/cf188c7bd288685357ff03fcbb494066/external/local_config_xcode”): 错误=2,没有这样的文件或目录,标准输出:

代码如下:

 46 def _xcode_version_output(repository_ctx, name, version, aliases, developer_dir):
 47     """Returns a string containing an xcode_version build target."""
 48     build_contents = ""
 49     decorated_aliases = []
 50     error_msg = ""
 51     for alias in aliases:
 52         decorated_aliases.append("'%s'" % alias)
 53     xcodebuild_result = repository_ctx.execute(
 54         ["xcrun", "xcodebuild", "-version", "-sdk"],
 55         30,
 56         {"DEVELOPER_DIR": developer_dir},
 57     )
 58     if (xcodebuild_result.return_code != 0):
 59         error_msg = (
 60             "Invoking xcodebuild failed, developer dir: {devdir} ," +
 61             "return code {code}, stderr: {err}, stdout: {out}"
 62         ).format(
 63             devdir = developer_dir,
 64             code = xcodebuild_result.return_code,
 65             err = xcodebuild_result.stderr,
 66             out = xcodebuild_result.stdout,
 67         )
 68     ios_sdk_version = _search_sdk_output(xcodebuild_result.stdout, "iphoneos")
 69     tvos_sdk_version = _search_sdk_output(xcodebuild_result.stdout, "appletvos")
 70     macos_sdk_version = _search_sdk_output(xcodebuild_result.stdout, "macosx")
 71     watchos_sdk_version = _search_sdk_output(xcodebuild_result.stdout, "watchos")
 72     build_contents += "xcode_version(\n  name = '%s'," % name
 73     build_contents += "\n  version = '%s'," % version
 74     if aliases:
 75         build_contents += "\n  aliases = [%s]," % " ,".join(decorated_aliases)
 76     if ios_sdk_version:
 77         build_contents += "\n  default_ios_sdk_version = '%s'," % ios_sdk_version
 78     if tvos_sdk_version:
 79         build_contents += "\n  default_tvos_sdk_version = '%s'," % tvos_sdk_version
 80     if macos_sdk_version:
 81         build_contents += "\n  default_macos_sdk_version = '%s'," % macos_sdk_version
 82     if watchos_sdk_version:
 83         build_contents += "\n  default_watchos_sdk_version = '%s'," % watchos_sdk_version
 84     build_contents += "\n)\n"
 85     if error_msg:
 86         build_contents += "\n# Error: " + error_msg.replace("\n", " ") + "\n"
 87         print(error_msg)
 88     return build_contents

但是,如果我直接运行xcrun,我可以成功运行它。这是部分输出:

WatchOS6.0.sdk - watchOS 6.0 (watchos6.0)
SDKVersion: 6.0
Path: /Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS6.0.sdk
PlatformVersion: 6.0
PlatformPath: /Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform
BuildID: 7CDF745C-BD9D-11E9-9623-6BA52C36DD1A
ProductBuildVersion: 17R566
ProductCopyright: 1983-2019 Apple Inc.
ProductName: Watch OS
ProductVersion: 6.0

WatchSimulator6.0.sdk - Simulator - watchOS 6.0 (watchsimulator6.0)
SDKVersion: 6.0
Path: /Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator6.0.sdk
PlatformVersion: 6.0
PlatformPath: /Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform
BuildID: 7CDF745C-BD9D-11E9-9623-6BA52C36DD1A
ProductBuildVersion: 17R566
ProductCopyright: 1983-2019 Apple Inc.
ProductName: Watch OS
ProductVersion: 6.0

Xcode 11.1

那么我该如何解决这个问题呢?

【问题讨论】:

    标签: xcode bazel macos-mojave xcode11


    【解决方案1】:

    看起来xcrun 在 PATH 上,但在运行操作时却不在。使用--verbose_failures 进行检查:Bazel 将打印失败的命令及其环境变量;查看xcrun 是否在其路径上。如果不是,那么也许你是用--incompatible_strict_action_env 构建的。另见--action_env

    【讨论】:

      猜你喜欢
      • 2014-10-14
      • 2012-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-16
      • 1970-01-01
      • 2020-02-07
      • 1970-01-01
      相关资源
      最近更新 更多