[Lldb-commits] [lldb] d9c898a - Revert "Factor out xcrun into a function (NFC)"

Adrian Prantl via lldb-commits lldb-commits at lists.llvm.org
Fri May 26 13:51:57 PDT 2023


Author: Adrian Prantl
Date: 2023-05-26T13:51:46-07:00
New Revision: d9c898ab60b0b9291b23d66530961fe436a03a8a

URL: https://github.com/llvm/llvm-project/commit/d9c898ab60b0b9291b23d66530961fe436a03a8a
DIFF: https://github.com/llvm/llvm-project/commit/d9c898ab60b0b9291b23d66530961fe436a03a8a.diff

LOG: Revert "Factor out xcrun into a function (NFC)"

This reverts commit 97ca34996dbe5a61e79d7c559af7b15dc39c08a5.

Added: 
    

Modified: 
    lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm

Removed: 
    


################################################################################
diff  --git a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
index 22298da9bf62e..5a39ed370747a 100644
--- a/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
+++ b/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm
@@ -373,69 +373,6 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) {
   return g_developer_directory;
 }
 
-static llvm::Expected<std::string>
-xcrun(const std::string &sdk, llvm::ArrayRef<llvm : StringRef> arguments,
-      llvm::StringRef developer_dir = "") {
-  Args args;
-  if (!developer_dir.empty()) {
-    args.AppendArgument("/usr/bin/env");
-    args.AppendArgument("DEVELOPER_DIR=" + developer_dir.str());
-  }
-  args.AppendArgument("/usr/bin/xcrun");
-  args.AppendArgument("--sdk");
-  args.AppendArgument(sdk);
-  for (auto arg: arguments)
-    args.AppendArguent(arg);
-
-  Log *log = GetLog(LLDBLog::Host);
-  if (log) {
-    std::string cmdstr;
-    args.GetCommandString(cmdstr);
-    log->Printf("GetXcodeSDK() running shell cmd '%s'", cmdstr.c_str());
-  }
-
-  int status = 0;
-  int signo = 0;
-  std::string output_str;
-  // The first time after Xcode was updated or freshly installed,
-  // xcrun can take surprisingly long to build up its database.
-  auto timeout = std::chrono::seconds(60);
-  bool run_in_shell = false;
-  lldb_private::Status error = Host::RunShellCommand(
-      args, FileSpec(), &status, &signo, &output_str, timeout, run_in_shell);
-
-  // Check that xcrun returned something useful.
-  if (error.Fail()) {
-    // Catastrophic error.
-    LLDB_LOG(log, "xcrun failed to execute: %s", error.AsCString());
-    return error.ToError();
-  }
-  if (status != 0) {
-    // xcrun didn't find a matching SDK. Not an error, we'll try
-    // 
diff erent spellings.
-    LLDB_LOG(log, "xcrun returned exit code %d", status);
-    return "";
-  }
-  if (output_str.empty()) {
-    LLDB_LOG(log, "xcrun returned no results");
-    return "";
-  }
-
-  // Convert to a StringRef so we can manipulate the string without modifying
-  // the underlying data.
-  llvm::StringRef output(output_str);
-
-  // Remove any trailing newline characters.
-  output = output.rtrim();
-
-  // Strip any leading newline characters and everything before them.
-  const size_t last_newline = output.rfind('\n');
-  if (last_newline != llvm::StringRef::npos)
-    output = output.substr(last_newline + 1);
-
-  return output.str();
-};
-
 llvm::Expected<std::string> GetXcodeSDK(XcodeSDK sdk) {
   XcodeSDK::Info info = sdk.Parse();
   std::string sdk_name = XcodeSDK::GetCanonicalName(info);
@@ -445,13 +382,75 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) {
 
   Log *log = GetLog(LLDBLog::Host);
 
+  auto xcrun = [](const std::string &sdk,
+                  llvm::StringRef developer_dir =
+                      "") -> llvm::Expected<std::string> {
+    Args args;
+    if (!developer_dir.empty()) {
+      args.AppendArgument("/usr/bin/env");
+      args.AppendArgument("DEVELOPER_DIR=" + developer_dir.str());
+    }
+    args.AppendArgument("/usr/bin/xcrun");
+    args.AppendArgument("--show-sdk-path");
+    args.AppendArgument("--sdk");
+    args.AppendArgument(sdk);
+
+    Log *log = GetLog(LLDBLog::Host);
+    if (log) {
+      std::string cmdstr;
+      args.GetCommandString(cmdstr);
+      log->Printf("GetXcodeSDK() running shell cmd '%s'", cmdstr.c_str());
+    }
+
+    int status = 0;
+    int signo = 0;
+    std::string output_str;
+    // The first time after Xcode was updated or freshly installed,
+    // xcrun can take surprisingly long to build up its database.
+    auto timeout = std::chrono::seconds(60);
+    bool run_in_shell = false;
+    lldb_private::Status error = Host::RunShellCommand(
+        args, FileSpec(), &status, &signo, &output_str, timeout, run_in_shell);
+
+    // Check that xcrun returned something useful.
+    if (error.Fail()) {
+      // Catastrophic error.
+      LLDB_LOG(log, "xcrun failed to execute: %s", error.AsCString());
+      return error.ToError();
+    }
+    if (status != 0) {
+      // xcrun didn't find a matching SDK. Not an error, we'll try
+      // 
diff erent spellings.
+      LLDB_LOG(log, "xcrun returned exit code %d", status);
+      return "";
+    }
+    if (output_str.empty()) {
+      LLDB_LOG(log, "xcrun returned no results");
+      return "";
+    }
+
+    // Convert to a StringRef so we can manipulate the string without modifying
+    // the underlying data.
+    llvm::StringRef output(output_str);
+
+    // Remove any trailing newline characters.
+    output = output.rtrim();
+
+    // Strip any leading newline characters and everything before them.
+    const size_t last_newline = output.rfind('\n');
+    if (last_newline != llvm::StringRef::npos)
+      output = output.substr(last_newline + 1);
+
+    return output.str();
+  };
+
   auto find_sdk =
-      [](const std::string &sdk_name) -> llvm::Expected<std::string> {
+      [&xcrun](const std::string &sdk_name) -> llvm::Expected<std::string> {
     // Invoke xcrun with the developer dir specified in the environment.
     std::string developer_dir = GetEnvDeveloperDir();
     if (!developer_dir.empty()) {
       // Don't fallback if DEVELOPER_DIR was set.
-      return xcrun(sdk_name, {"--show-sdk-path"}, developer_dir);
+      return xcrun(sdk_name, developer_dir);
     }
 
     // Invoke xcrun with the shlib dir.
@@ -462,8 +461,7 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) {
         llvm::StringRef shlib_developer_dir =
             llvm::sys::path::parent_path(contents_dir);
         if (!shlib_developer_dir.empty()) {
-          auto sdk = xcrun(sdk_name, {"--show-sdk-path"},
-                           std::move(shlib_developer_dir));
+          auto sdk = xcrun(sdk_name, std::move(shlib_developer_dir));
           if (!sdk)
             return sdk.takeError();
           if (!sdk->empty())


        


More information about the lldb-commits mailing list