[Lldb-commits] [PATCH] D88866: [lldb] Add another fallback to GetXcodeSDK

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Oct 5 19:03:25 PDT 2020


JDevlieghere created this revision.
JDevlieghere added a reviewer: aprantl.
JDevlieghere requested review of this revision.

If we tried getting the SDK from `xcrun` with the developer dir set and it failed, try without the developer dir.


https://reviews.llvm.org/D88866

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
@@ -373,26 +373,13 @@
 static std::string GetXcodeSDK(XcodeSDK sdk) {
   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;
-    std::string developer_dir = GetEnvDeveloperDir();
-    if (developer_dir.empty())
-      if (FileSpec fspec = HostInfo::GetShlibDir())
-        if (FileSystem::Instance().Exists(fspec)) {
-          FileSpec path(
-              XcodeSDK::FindXcodeContentsDirectoryInPath(fspec.GetPath()));
-          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;
 
+  auto xcrun = [](llvm::StringRef xcrun_cmd) -> std::string {
     int status = 0;
     int signo = 0;
     std::string output_str;
     lldb_private::Status error =
-        Host::RunShellCommand(xcrun_cmd.c_str(), FileSpec(), &status, &signo,
+        Host::RunShellCommand(xcrun_cmd, FileSpec(), &status, &signo,
                               &output_str, std::chrono::seconds(15));
 
     // Check that xcrun return something useful.
@@ -414,6 +401,32 @@
     return output.str();
   };
 
+  auto find_sdk = [&](std::string sdk_name) -> std::string {
+    std::string developer_dir = GetEnvDeveloperDir();
+    if (developer_dir.empty())
+      if (FileSpec fspec = HostInfo::GetShlibDir())
+        if (FileSystem::Instance().Exists(fspec)) {
+          FileSpec path(
+              XcodeSDK::FindXcodeContentsDirectoryInPath(fspec.GetPath()));
+          if (path.RemoveLastPathComponent())
+            developer_dir = path.GetPath();
+        }
+
+    std::string xcrun_cmd = "xcrun --show-sdk-path --sdk " + sdk_name;
+
+    // If we have a developer_dir try that first.
+    if (!developer_dir.empty()) {
+      std::string env_xcrun_cmd =
+          "/usr/bin/env DEVELOPER_DIR=\"" + developer_dir + "\" " + xcrun_cmd;
+      std::string output_str = xcrun(env_xcrun_cmd);
+      if (!output_str.empty())
+        return output_str;
+    }
+
+    // If we didn't find the SDK with the developer dir set, try without.
+    return xcrun(xcrun_cmd);
+  };
+
   std::string path = find_sdk(sdk_name);
   while (path.empty()) {
     // Try an alternate spelling of the name ("macosx10.9internal").


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88866.296344.patch
Type: text/x-patch
Size: 2665 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20201006/88b16389/attachment.bin>


More information about the lldb-commits mailing list