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

Bazel无法运行xcrun,但xcode和xcrun已在本地正确安装,xcode,bazel,macos-mojave,xcode11,Xcode,Bazel,Macos Mojave,Xcode11,我正在尝试运行bazel构建。在这个过程中,我看到了以下错误消息 调试: /private/var/tmp/_bazel_antkong/cf188c7bd28685357ff03fcbb494066/external/bazel_tools/tools/osx/xcode_configure.bzl:87:9: 调用xcodebuild失败,开发者目录: /Applications/Xcode.app/Contents/Developer,返回代码256,stderr: java.io.IOE

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

调试: /private/var/tmp/_bazel_antkong/cf188c7bd28685357ff03fcbb494066/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/cf188c7bd28685357ff03fcbb494066/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
那么如何解决这个问题呢?

看起来xcrun在路径上,但在运行操作时没有。检查-verbose_failures:Bazel将打印失败的命令及其envvars;查看xcrun是否在其路径上。如果不是的话,那么也许你用它来建造。另见