aprantl created this revision.
aprantl added reviewers: JDevlieghere, friss, jingham.
aprantl added a parent revision: D81209: Move GetXcode*Directory into HostInfo
(NFC).
Teach GetXcodeSDK to look in the Xcode that contains LLDB instead of preferring
the one chosen with xcode-select. Because we're using xcrun to find matching
SDK's you can now get into a situation where LLDB, when run from a
non-xcode-selected Xcode will find a matching SDK in the xcode-selected Xcode,
which can cause anything from mild performance degradation to really confusing
Clang compile errors, if the other Xcode is, for example, older, or missing an
SDK.
rdar://problem/64000666
https://reviews.llvm.org/D81210
Files:
lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
Index: lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
===================================================================
--- lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
+++ lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
@@ -297,46 +297,47 @@
}
}
-FileSpec HostInfoMacOSX::GetXcodeContentsDirectory() {
- static FileSpec g_xcode_contents_path;
- static std::once_flag g_once_flag;
- std::call_once(g_once_flag, [&]() {
- // Try the shlib dir first.
- if (FileSpec fspec = HostInfo::GetShlibDir()) {
- if (FileSystem::Instance().Exists(fspec)) {
- std::string xcode_contents_dir =
- XcodeSDK::FindXcodeContentsDirectoryInPath(fspec.GetPath());
- if (!xcode_contents_dir.empty()) {
- g_xcode_contents_path = FileSpec(xcode_contents_dir);
- return;
- }
- }
+static FileSpec GetXcodeContentsDirectory(bool use_xcrun) {
+ // Try the shlib dir first.
+ if (FileSpec fspec = HostInfo::GetShlibDir()) {
+ if (FileSystem::Instance().Exists(fspec)) {
+ std::string xcode_contents_dir =
+ XcodeSDK::FindXcodeContentsDirectoryInPath(fspec.GetPath());
+ if (!xcode_contents_dir.empty())
+ return FileSpec(xcode_contents_dir);
}
+ }
- if (const char *developer_dir_env_var = getenv("DEVELOPER_DIR")) {
- FileSpec fspec(developer_dir_env_var);
- if (FileSystem::Instance().Exists(fspec)) {
- // FIXME: This looks like it couldn't possibly work!
- std::string xcode_contents_dir =
- XcodeSDK::FindXcodeContentsDirectoryInPath(fspec.GetPath());
- if (!xcode_contents_dir.empty()) {
- g_xcode_contents_path = FileSpec(xcode_contents_dir);
- return;
- }
- }
+ if (const char *developer_dir_env_var = getenv("DEVELOPER_DIR")) {
+ FileSpec fspec(developer_dir_env_var);
+ if (FileSystem::Instance().Exists(fspec)) {
+ // FIXME: This looks like it couldn't possibly work!
+ std::string xcode_contents_dir =
+ XcodeSDK::FindXcodeContentsDirectoryInPath(fspec.GetPath());
+ if (!xcode_contents_dir.empty())
+ return FileSpec(xcode_contents_dir);
}
+ }
- FileSpec fspec(HostInfo::GetXcodeSDKPath(XcodeSDK::GetAnyMacOS()));
- if (fspec) {
- if (FileSystem::Instance().Exists(fspec)) {
- std::string xcode_contents_dir =
- XcodeSDK::FindXcodeContentsDirectoryInPath(fspec.GetPath());
- if (!xcode_contents_dir.empty()) {
- g_xcode_contents_path = FileSpec(xcode_contents_dir);
- return;
- }
- }
+ if (!use_xcrun)
+ return {};
+ FileSpec fspec(HostInfo::GetXcodeSDKPath(XcodeSDK::GetAnyMacOS()));
+ if (fspec) {
+ if (FileSystem::Instance().Exists(fspec)) {
+ std::string xcode_contents_dir =
+ XcodeSDK::FindXcodeContentsDirectoryInPath(fspec.GetPath());
+ if (!xcode_contents_dir.empty())
+ return FileSpec(xcode_contents_dir);
}
+ }
+ return {};
+}
+
+FileSpec HostInfoMacOSX::GetXcodeContentsDirectory() {
+ static FileSpec g_xcode_contents_path;
+ static std::once_flag g_once_flag;
+ std::call_once(g_once_flag, [&]() {
+ g_xcode_contents_path = ::GetXcodeContentsDirectory(true);
});
return g_xcode_contents_path;
}
@@ -358,7 +359,19 @@
XcodeSDK::Info info = sdk.Parse();
std::string sdk_name = XcodeSDK::GetCanonicalName(info);
auto find_sdk = [](std::string sdk_name) -> std::string {
- std::string xcrun_cmd = "xcrun --show-sdk-path --sdk " + sdk_name;
+ std::string xcrun_cmd;
+ Environment env = Host::GetEnvironment();
+ std::string developer_dir = env.lookup("DEVELOPER_DIR");
+ if (developer_dir.empty()) {
+ // Avoid infinite recursion GetXcodeContentsDirectory calling GetXcodeSDK.
+ FileSpec path = ::GetXcodeContentsDirectory(false);
+ if (path.RemoveLastPathComponent())
+ developer_dir = path.GetPath();
+ }
+ if (!developer_dir.empty())
+ xcrun_cmd = "/usr/bin/env DEVELOPER_DIR=" + developer_dir + " ";
+ xcrun_cmd += "xcrun --show-sdk-path --sdk " + sdk_name;
+
int status = 0;
int signo = 0;
std::string output_str;
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits