Bazel无法运行xcrun,但是xcode和xcrun已在本地正确安装

时间:2019-10-14 23:06:12

标签: xcode bazel macos-mojave xcode11

我正在尝试运行bazel构建。在此过程中,我看到了以下错误消息

  

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

代码如下:

 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

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

1 个答案:

答案 0 :(得分:1)

看起来xcrun在PATH上,但是在执行操作时不在。使用--verbose_failures进行检查:Bazel将打印失败的命令及其envvar;查看xcrun是否在其PATH上。如果没有,那么也许您是使用--incompatible_strict_action_env构建的。另请参见--action_env