簡體   English   中英

Bazel 無法運行 xcrun 但 xcode 和 xcrun 已在本地正確安裝

[英]Bazel fails to run xcrun but xcode and xcrun are installed properly locally

我正在嘗試運行 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: Cannot run program "xcrun" (in directory "/private/var/tmp/_bazel_antkong/cf188c7bd288685357ff03fcbb494066/external/local_config_xcode"): error=2, No such file or directory, 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 ,我可以成功運行它。 這是部分 output:

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在 PATH 上,但在運行操作時不在。 使用--verbose_failures檢查這一點:Bazel 將打印失敗的命令及其環境變量; 查看xcrun是否在其 PATH 上。 如果沒有,那么也許你是用--incompatible_strict_action_env 構建的。 另請參見--action_env

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM