[Lldb-commits] [lldb] r333933 - Remove dependency from Host to clang.

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Mon Jun 4 10:41:00 PDT 2018


Author: zturner
Date: Mon Jun  4 10:41:00 2018
New Revision: 333933

URL: http://llvm.org/viewvc/llvm-project?rev=333933&view=rev
Log:
Remove dependency from Host to clang.

Host depended on clang because HostInfo had a function to get
the directory where clang was installed.  We move this over to
the clang expression parser plugin where it's more at home.

Differential Revision: https://reviews.llvm.org/D47384

Added:
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.h
    lldb/trunk/unittests/Expression/ClangParserTest.cpp
Modified:
    lldb/trunk/include/lldb/Host/HostInfoBase.h
    lldb/trunk/include/lldb/Host/macosx/HostInfoMacOSX.h
    lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h
    lldb/trunk/source/API/SBHostOS.cpp
    lldb/trunk/source/Host/common/HostInfoBase.cpp
    lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm
    lldb/trunk/source/Host/posix/HostInfoPosix.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/CMakeLists.txt
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
    lldb/trunk/unittests/Expression/CMakeLists.txt
    lldb/trunk/unittests/Host/HostInfoTest.cpp

Modified: lldb/trunk/include/lldb/Host/HostInfoBase.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/HostInfoBase.h?rev=333933&r1=333932&r2=333933&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/HostInfoBase.h (original)
+++ lldb/trunk/include/lldb/Host/HostInfoBase.h Mon Jun  4 10:41:00 2018
@@ -98,7 +98,6 @@ protected:
   static bool ComputeTempFileBaseDirectory(FileSpec &file_spec);
   static bool ComputeHeaderDirectory(FileSpec &file_spec);
   static bool ComputeSystemPluginsDirectory(FileSpec &file_spec);
-  static bool ComputeClangDirectory(FileSpec &file_spec);
   static bool ComputeUserPluginsDirectory(FileSpec &file_spec);
 
   static void ComputeHostArchitectureSupport(ArchSpec &arch_32,

Modified: lldb/trunk/include/lldb/Host/macosx/HostInfoMacOSX.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/macosx/HostInfoMacOSX.h?rev=333933&r1=333932&r2=333933&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/macosx/HostInfoMacOSX.h (original)
+++ lldb/trunk/include/lldb/Host/macosx/HostInfoMacOSX.h Mon Jun  4 10:41:00 2018
@@ -37,9 +37,6 @@ protected:
                                              ArchSpec &arch_64);
   static bool ComputeHeaderDirectory(FileSpec &file_spec);
   static bool ComputePythonDirectory(FileSpec &file_spec);
-  static bool ComputeClangDirectory(FileSpec &file_spec);
-  static bool ComputeClangDirectory(FileSpec &lldb_shlib_spec,
-                                    FileSpec &file_spec, bool verify);
   static bool ComputeSystemPluginsDirectory(FileSpec &file_spec);
   static bool ComputeUserPluginsDirectory(FileSpec &file_spec);
 };

Modified: lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h?rev=333933&r1=333932&r2=333933&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h (original)
+++ lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h Mon Jun  4 10:41:00 2018
@@ -33,13 +33,13 @@ public:
 
   static bool GetEnvironmentVar(const std::string &var_name, std::string &var);
 
+  static bool ComputePathRelativeToLibrary(FileSpec &file_spec,
+                                           llvm::StringRef dir);
+
 protected:
   static bool ComputeSupportExeDirectory(FileSpec &file_spec);
   static bool ComputeHeaderDirectory(FileSpec &file_spec);
   static bool ComputePythonDirectory(FileSpec &file_spec);
-  static bool ComputeClangDirectory(FileSpec &file_spec);
-  static bool ComputePathRelativeToLibrary(FileSpec &file_spec,
-                                           llvm::StringRef dir);
 };
 }
 

Modified: lldb/trunk/source/API/SBHostOS.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBHostOS.cpp?rev=333933&r1=333932&r2=333933&view=diff
==============================================================================
--- lldb/trunk/source/API/SBHostOS.cpp (original)
+++ lldb/trunk/source/API/SBHostOS.cpp Mon Jun  4 10:41:00 2018
@@ -17,6 +17,8 @@
 #include "lldb/Utility/FileSpec.h"
 #include "lldb/Utility/Log.h"
 
+#include "Plugins/ExpressionParser/Clang/ClangHost.h"
+
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/Path.h"
 
@@ -41,7 +43,12 @@ SBFileSpec SBHostOS::GetLLDBPythonPath()
 SBFileSpec SBHostOS::GetLLDBPath(lldb::PathType path_type) {
   SBFileSpec sb_fspec;
   FileSpec fspec;
-  if (HostInfo::GetLLDBPath(path_type, fspec))
+  bool Success = true;
+  if (path_type == ePathTypeClangDir)
+    fspec = GetClangResourceDir();
+  else
+    Success = HostInfo::GetLLDBPath(path_type, fspec);
+  if (Success)
     sb_fspec.SetFileSpec(fspec);
   return sb_fspec;
 }

Modified: lldb/trunk/source/Host/common/HostInfoBase.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/HostInfoBase.cpp?rev=333933&r1=333932&r2=333933&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/HostInfoBase.cpp (original)
+++ lldb/trunk/source/Host/common/HostInfoBase.cpp Mon Jun  4 10:41:00 2018
@@ -114,6 +114,8 @@ llvm::Optional<HostInfoBase::Architectur
 bool HostInfoBase::GetLLDBPath(lldb::PathType type, FileSpec &file_spec) {
   file_spec.Clear();
 
+  assert(type != lldb::ePathTypeClangDir);
+
 #if defined(LLDB_DISABLE_PYTHON)
   if (type == lldb::ePathTypePythonDir)
     return false;
@@ -176,21 +178,6 @@ bool HostInfoBase::GetLLDBPath(lldb::Pat
     if (success)
       result = &g_fields->m_lldb_python_dir;
   } break;
-  case lldb::ePathTypeClangDir: {
-    static llvm::once_flag g_once_flag;
-    static bool success = false;
-    llvm::call_once(g_once_flag, []() {
-      success =
-          HostInfo::ComputeClangDirectory(g_fields->m_lldb_clang_resource_dir);
-      Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
-      if (log)
-        log->Printf(
-            "HostInfoBase::GetLLDBPath(ePathTypeClangResourceDir) => '%s'",
-            g_fields->m_lldb_clang_resource_dir.GetPath().c_str());
-    });
-    if (success)
-      result = &g_fields->m_lldb_clang_resource_dir;
-  } break;
   case lldb::ePathTypeLLDBSystemPlugins: {
     static llvm::once_flag g_once_flag;
     static bool success = false;
@@ -251,6 +238,8 @@ bool HostInfoBase::GetLLDBPath(lldb::Pat
     if (success)
       result = &g_fields->m_lldb_global_tmp_dir;
   } break;
+  default:
+    llvm_unreachable("Unreachable!");
   }
 
   if (!result)
@@ -351,8 +340,6 @@ bool HostInfoBase::ComputeSystemPluginsD
   return false;
 }
 
-bool HostInfoBase::ComputeClangDirectory(FileSpec &file_spec) { return false; }
-
 bool HostInfoBase::ComputeUserPluginsDirectory(FileSpec &file_spec) {
   // TODO(zturner): Figure out how to compute the user plugins directory for
   // all platforms.

Modified: lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm?rev=333933&r1=333932&r2=333933&view=diff
==============================================================================
--- lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm (original)
+++ lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm Mon Jun  4 10:41:00 2018
@@ -227,86 +227,6 @@ bool HostInfoMacOSX::ComputePythonDirect
 #endif
 }
 
-static bool VerifyClangPath(const llvm::Twine &clang_path) {
-  if (llvm::sys::fs::is_directory(clang_path))
-    return true;
-  Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
-  if (log)
-    log->Printf("HostInfoMacOSX::ComputeClangDirectory(): "
-                "failed to stat clang resource directory at \"%s\"",
-                clang_path.str().c_str());
-  return false;
-}
-
-bool HostInfoMacOSX::ComputeClangDirectory(FileSpec &file_spec) {
-  FileSpec lldb_file_spec;
-  if (!GetLLDBPath(lldb::ePathTypeLLDBShlibDir, lldb_file_spec))
-    return false;
-  return ComputeClangDirectory(lldb_file_spec, file_spec, true);
-}
-
-bool HostInfoMacOSX::ComputeClangDirectory(FileSpec &lldb_shlib_spec,
-                                           FileSpec &file_spec, bool verify) {
-  std::string raw_path = lldb_shlib_spec.GetPath();
-
-  auto rev_it = llvm::sys::path::rbegin(raw_path);
-  auto r_end = llvm::sys::path::rend(raw_path);
-
-  // Check for a Posix-style build of LLDB.
-  while (rev_it != r_end) {
-    if (*rev_it == "LLDB.framework")
-      break;
-    ++rev_it;
-  }
-
-  if (rev_it == r_end)
-    return HostInfoPosix::ComputeClangDirectory(file_spec);
-
-  // Inside Xcode and in Xcode toolchains LLDB is always in lockstep
-  // with the Swift compiler, so it can reuse its Clang resource
-  // directory. This allows LLDB and the Swift compiler to share the
-  // same Clang module cache.
-  llvm::SmallString<256> clang_path;
-  const char *swift_clang_resource_dir = "usr/lib/swift/clang";
-  auto parent = std::next(rev_it);
-  if (parent != r_end && *parent == "SharedFrameworks") {
-    // This is the top-level LLDB in the Xcode.app bundle.
-    // E.g., "Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A"
-    raw_path.resize(parent - r_end);
-    llvm::sys::path::append(clang_path, raw_path,
-                            "Developer/Toolchains/XcodeDefault.xctoolchain",
-                            swift_clang_resource_dir);
-    if (!verify || VerifyClangPath(clang_path)) {
-      file_spec.SetFile(clang_path.c_str(), true);
-      return true;
-    }
-  } else if (parent != r_end && *parent == "PrivateFrameworks" &&
-             std::distance(parent, r_end) > 2) {
-    ++parent;
-    ++parent;
-    if (*parent == "System") {
-      // This is LLDB inside an Xcode toolchain.
-      // E.g., "Xcode.app/Contents/Developer/Toolchains/"               \
-      //       "My.xctoolchain/System/Library/PrivateFrameworks/LLDB.framework"
-      raw_path.resize(parent - r_end);
-      llvm::sys::path::append(clang_path, raw_path, swift_clang_resource_dir);
-      if (!verify || VerifyClangPath(clang_path)) {
-        file_spec.SetFile(clang_path.c_str(), true);
-        return true;
-      }
-      raw_path = lldb_shlib_spec.GetPath();
-    }
-    raw_path.resize(rev_it - r_end);
-  } else {
-    raw_path.resize(rev_it - r_end);
-  }
-
-  // Fall back to the Clang resource directory inside the framework.
-  raw_path.append("LLDB.framework/Resources/Clang");
-  file_spec.SetFile(raw_path.c_str(), true);
-  return true;
-}
-
 bool HostInfoMacOSX::ComputeSystemPluginsDirectory(FileSpec &file_spec) {
   FileSpec lldb_file_spec;
   if (!GetLLDBPath(lldb::ePathTypeLLDBShlibDir, lldb_file_spec))

Modified: lldb/trunk/source/Host/posix/HostInfoPosix.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/HostInfoPosix.cpp?rev=333933&r1=333932&r2=333933&view=diff
==============================================================================
--- lldb/trunk/source/Host/posix/HostInfoPosix.cpp (original)
+++ lldb/trunk/source/Host/posix/HostInfoPosix.cpp Mon Jun  4 10:41:00 2018
@@ -14,8 +14,6 @@
 #include "lldb/Host/posix/HostInfoPosix.h"
 #include "lldb/Utility/Log.h"
 
-#include "clang/Basic/Version.h"
-#include "clang/Config/config.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/Path.h"
@@ -168,13 +166,6 @@ bool HostInfoPosix::ComputeSupportExeDir
   return ComputePathRelativeToLibrary(file_spec, "/bin");
 }
 
-bool HostInfoPosix::ComputeClangDirectory(FileSpec &file_spec) {
-  return ComputePathRelativeToLibrary(
-      file_spec, (llvm::Twine("/lib") + CLANG_LIBDIR_SUFFIX + "/clang/" +
-                  CLANG_VERSION_STRING)
-                     .str());
-}
-
 bool HostInfoPosix::ComputeHeaderDirectory(FileSpec &file_spec) {
   FileSpec temp_file("/opt/local/include/lldb", false);
   file_spec.GetDirectory().SetCString(temp_file.GetPath().c_str());

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/CMakeLists.txt?rev=333933&r1=333932&r2=333933&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/CMakeLists.txt (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/CMakeLists.txt Mon Jun  4 10:41:00 2018
@@ -11,6 +11,7 @@ add_lldb_library(lldbPluginExpressionPar
   ClangExpressionParser.cpp
   ClangExpressionVariable.cpp
   ClangFunctionCaller.cpp
+  ClangHost.cpp
   ClangModulesDeclVendor.cpp
   ClangPersistentVariables.cpp
   ClangUserExpression.cpp

Added: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.cpp?rev=333933&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.cpp (added)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.cpp Mon Jun  4 10:41:00 2018
@@ -0,0 +1,142 @@
+//===-- ClangHost.cpp -------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ClangHost.h"
+
+#include "clang/Basic/Version.h"
+#include "clang/Config/config.h"
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Threading.h"
+
+// Project includes
+#if !defined(_WIN32)
+#include "lldb/Host/posix/HostInfoPosix.h"
+#endif
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/Log.h"
+
+#include <string>
+
+using namespace lldb_private;
+
+#if defined(_WIN32)
+static bool ComputeClangDirectory(FileSpec &file_spec) { return false; }
+#else
+static bool DefaultComputeClangDirectory(FileSpec &file_spec) {
+  return HostInfoPosix::ComputePathRelativeToLibrary(
+      file_spec, (llvm::Twine("/lib") + CLANG_LIBDIR_SUFFIX + "/clang/" +
+                  CLANG_VERSION_STRING)
+                     .str());
+}
+
+#if defined(__APPLE__)
+
+static bool VerifyClangPath(const llvm::Twine &clang_path) {
+  if (llvm::sys::fs::is_directory(clang_path))
+    return true;
+  Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
+  if (log)
+    log->Printf("VerifyClangPath(): "
+                "failed to stat clang resource directory at \"%s\"",
+                clang_path.str().c_str());
+  return false;
+}
+
+bool lldb_private::ComputeClangDirectory(FileSpec &lldb_shlib_spec,
+                                         FileSpec &file_spec, bool verify) {
+  std::string raw_path = lldb_shlib_spec.GetPath();
+
+  auto rev_it = llvm::sys::path::rbegin(raw_path);
+  auto r_end = llvm::sys::path::rend(raw_path);
+
+  // Check for a Posix-style build of LLDB.
+  while (rev_it != r_end) {
+    if (*rev_it == "LLDB.framework")
+      break;
+    ++rev_it;
+  }
+
+  if (rev_it == r_end)
+    return DefaultComputeClangDirectory(file_spec);
+
+  // Inside Xcode and in Xcode toolchains LLDB is always in lockstep
+  // with the Swift compiler, so it can reuse its Clang resource
+  // directory. This allows LLDB and the Swift compiler to share the
+  // same Clang module cache.
+  llvm::SmallString<256> clang_path;
+  const char *swift_clang_resource_dir = "usr/lib/swift/clang";
+  auto parent = std::next(rev_it);
+  if (parent != r_end && *parent == "SharedFrameworks") {
+    // This is the top-level LLDB in the Xcode.app bundle.
+    // E.g., "Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A"
+    raw_path.resize(parent - r_end);
+    llvm::sys::path::append(clang_path, raw_path,
+                            "Developer/Toolchains/XcodeDefault.xctoolchain",
+                            swift_clang_resource_dir);
+    if (!verify || VerifyClangPath(clang_path)) {
+      file_spec.SetFile(clang_path.c_str(), true);
+      return true;
+    }
+  } else if (parent != r_end && *parent == "PrivateFrameworks" &&
+             std::distance(parent, r_end) > 2) {
+    ++parent;
+    ++parent;
+    if (*parent == "System") {
+      // This is LLDB inside an Xcode toolchain.
+      // E.g., "Xcode.app/Contents/Developer/Toolchains/"               \
+      //       "My.xctoolchain/System/Library/PrivateFrameworks/LLDB.framework"
+      raw_path.resize(parent - r_end);
+      llvm::sys::path::append(clang_path, raw_path, swift_clang_resource_dir);
+      if (!verify || VerifyClangPath(clang_path)) {
+        file_spec.SetFile(clang_path.c_str(), true);
+        return true;
+      }
+      raw_path = lldb_shlib_spec.GetPath();
+    }
+    raw_path.resize(rev_it - r_end);
+  } else {
+    raw_path.resize(rev_it - r_end);
+  }
+
+  // Fall back to the Clang resource directory inside the framework.
+  raw_path.append("LLDB.framework/Resources/Clang");
+  file_spec.SetFile(raw_path.c_str(), true);
+  return true;
+}
+
+static bool ComputeClangDirectory(FileSpec &file_spec) {
+  FileSpec lldb_file_spec;
+  if (!HostInfo::GetLLDBPath(lldb::ePathTypeLLDBShlibDir, lldb_file_spec))
+    return false;
+  return ComputeClangDirectory(lldb_file_spec, file_spec, true);
+}
+#else  // __APPLE__
+
+// All non-Apple posix systems.
+static bool ComputeClangDirectory(FileSpec &file_spec) {
+  return DefaultComputeClangDirectory(file_spec);
+}
+#endif // __APPLE__
+#endif // _WIN32
+
+FileSpec lldb_private::GetClangResourceDir() {
+  static FileSpec g_cached_resource_dir;
+  static llvm::once_flag g_once_flag;
+  llvm::call_once(g_once_flag, []() {
+    ::ComputeClangDirectory(g_cached_resource_dir);
+    Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
+    if (log)
+      log->Printf("GetClangResourceDir() => '%s'",
+                  g_cached_resource_dir.GetPath().c_str());
+  });
+  return g_cached_resource_dir;
+}

Added: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.h?rev=333933&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.h (added)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangHost.h Mon Jun  4 10:41:00 2018
@@ -0,0 +1,26 @@
+//===-- ClangHost.h ---------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGHOST_H
+#define LLDB_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGHOST_H
+
+namespace lldb_private {
+
+class FileSpec;
+
+#if defined(__APPLE__)
+bool ComputeClangDirectory(FileSpec &lldb_shlib_spec, FileSpec &file_spec,
+                           bool verify);
+#endif
+
+FileSpec GetClangResourceDir();
+
+} // namespace lldb_private
+
+#endif

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp?rev=333933&r1=333932&r2=333933&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp Mon Jun  4 10:41:00 2018
@@ -25,6 +25,7 @@
 #include "llvm/Support/Threading.h"
 
 // Project includes
+#include "ClangHost.h"
 #include "ClangModulesDeclVendor.h"
 
 #include "lldb/Core/ModuleList.h"
@@ -144,18 +145,6 @@ void StoringDiagnosticConsumer::DumpDiag
   }
 }
 
-static FileSpec GetResourceDir() {
-  static FileSpec g_cached_resource_dir;
-
-  static llvm::once_flag g_once_flag;
-
-  llvm::call_once(g_once_flag, []() {
-    HostInfo::GetLLDBPath(lldb::ePathTypeClangDir, g_cached_resource_dir);
-  });
-
-  return g_cached_resource_dir;
-}
-
 ClangModulesDeclVendor::ClangModulesDeclVendor() {}
 
 ClangModulesDeclVendor::~ClangModulesDeclVendor() {}
@@ -610,7 +599,7 @@ ClangModulesDeclVendor::Create(Target &t
   }
 
   {
-    FileSpec clang_resource_dir = GetResourceDir();
+    FileSpec clang_resource_dir = GetClangResourceDir();
 
     if (llvm::sys::fs::is_directory(clang_resource_dir.GetPath())) {
       compiler_invocation_arguments.push_back("-resource-dir");

Modified: lldb/trunk/unittests/Expression/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Expression/CMakeLists.txt?rev=333933&r1=333932&r2=333933&view=diff
==============================================================================
--- lldb/trunk/unittests/Expression/CMakeLists.txt (original)
+++ lldb/trunk/unittests/Expression/CMakeLists.txt Mon Jun  4 10:41:00 2018
@@ -1,7 +1,9 @@
 add_lldb_unittest(ExpressionTests
+  ClangParserTest.cpp
   GoParserTest.cpp
 
   LINK_LIBS
     lldbCore
     lldbPluginExpressionParserGo
+    lldbPluginExpressionParserClang
   )

Added: lldb/trunk/unittests/Expression/ClangParserTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Expression/ClangParserTest.cpp?rev=333933&view=auto
==============================================================================
--- lldb/trunk/unittests/Expression/ClangParserTest.cpp (added)
+++ lldb/trunk/unittests/Expression/ClangParserTest.cpp Mon Jun  4 10:41:00 2018
@@ -0,0 +1,64 @@
+//===-- ClangParserTest.cpp --------------------------------------*- C++-*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "Plugins/ExpressionParser/Clang/ClangHost.h"
+#include "TestingSupport/TestUtilities.h"
+#include "lldb/lldb-defines.h"
+#include "gtest/gtest.h"
+
+using namespace lldb_private;
+
+#ifdef __APPLE__
+static std::string ComputeClangDir(std::string lldb_shlib_path,
+                                   bool verify = false) {
+  FileSpec clang_dir;
+  FileSpec lldb_shlib_spec(lldb_shlib_path, false);
+  ComputeClangDirectory(lldb_shlib_spec, clang_dir, verify);
+  return clang_dir.GetPath();
+}
+
+TEST_F(HostInfoTest, MacOSX) {
+  // This returns whatever the POSIX fallback returns.
+  std::string posix = "/usr/lib/liblldb.dylib";
+  EXPECT_FALSE(ComputeClangDir(posix).empty());
+
+  std::string build =
+      "/lldb-macosx-x86_64/Library/Frameworks/LLDB.framework/Versions/A";
+  std::string build_clang =
+      "/lldb-macosx-x86_64/Library/Frameworks/LLDB.framework/Resources/Clang";
+  EXPECT_EQ(ComputeClangDir(build), build_clang);
+
+  std::string xcode = "/Applications/Xcode.app/Contents/SharedFrameworks/"
+                      "LLDB.framework/Versions/A";
+  std::string xcode_clang =
+      "/Applications/Xcode.app/Contents/Developer/Toolchains/"
+      "XcodeDefault.xctoolchain/usr/lib/swift/clang";
+  EXPECT_EQ(ComputeClangDir(xcode), xcode_clang);
+
+  std::string toolchain =
+      "/Applications/Xcode.app/Contents/Developer/Toolchains/"
+      "Swift-4.1-development-snapshot.xctoolchain/System/Library/"
+      "PrivateFrameworks/LLDB.framework";
+  std::string toolchain_clang =
+      "/Applications/Xcode.app/Contents/Developer/Toolchains/"
+      "Swift-4.1-development-snapshot.xctoolchain/usr/lib/swift/clang";
+  EXPECT_EQ(ComputeClangDir(toolchain), toolchain_clang);
+
+  std::string cltools = "/Library/Developer/CommandLineTools/Library/"
+                        "PrivateFrameworks/LLDB.framework";
+  std::string cltools_clang =
+      "/Library/Developer/CommandLineTools/Library/PrivateFrameworks/"
+      "LLDB.framework/Resources/Clang";
+  EXPECT_EQ(ComputeClangDir(cltools), cltools_clang);
+
+  // Test that a bogus path is detected.
+  EXPECT_NE(ComputeClangDir(GetInputFilePath(xcode), true),
+            ComputeClangDir(GetInputFilePath(xcode)));
+}
+#endif

Modified: lldb/trunk/unittests/Host/HostInfoTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Host/HostInfoTest.cpp?rev=333933&r1=333932&r2=333933&view=diff
==============================================================================
--- lldb/trunk/unittests/Host/HostInfoTest.cpp (original)
+++ lldb/trunk/unittests/Host/HostInfoTest.cpp Mon Jun  4 10:41:00 2018
@@ -12,10 +12,6 @@
 #include "TestingSupport/TestUtilities.h"
 #include "gtest/gtest.h"
 
-#ifdef __APPLE__
-#include "lldb/Host/macosx/HostInfoMacOSX.h"
-#endif
-
 using namespace lldb_private;
 using namespace llvm;
 
@@ -47,59 +43,4 @@ TEST_F(HostInfoTest, GetAugmentedArchSpe
   // Test LLDB_ARCH_DEFAULT
   EXPECT_EQ(HostInfo::GetAugmentedArchSpec(LLDB_ARCH_DEFAULT).GetTriple(),
             HostInfo::GetArchitecture(HostInfo::eArchKindDefault).GetTriple());
-}
-
-
-#ifdef __APPLE__
-
-struct HostInfoMacOSXTest : public HostInfoMacOSX {
-  static std::string ComputeClangDir(std::string lldb_shlib_path,
-                                     bool verify = false) {
-    FileSpec clang_dir;
-    FileSpec lldb_shlib_spec(lldb_shlib_path, false);
-    ComputeClangDirectory(lldb_shlib_spec, clang_dir, verify);
-    return clang_dir.GetPath();
-  }
-};
-
-
-TEST_F(HostInfoTest, MacOSX) {
-  // This returns whatever the POSIX fallback returns.
-  std::string posix = "/usr/lib/liblldb.dylib";
-  EXPECT_FALSE(HostInfoMacOSXTest::ComputeClangDir(posix).empty());
-
-  std::string build =
-    "/lldb-macosx-x86_64/Library/Frameworks/LLDB.framework/Versions/A";
-  std::string build_clang =
-    "/lldb-macosx-x86_64/Library/Frameworks/LLDB.framework/Resources/Clang";
-  EXPECT_EQ(HostInfoMacOSXTest::ComputeClangDir(build), build_clang);
-
-  std::string xcode =
-    "/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A";
-  std::string xcode_clang =
-    "/Applications/Xcode.app/Contents/Developer/Toolchains/"
-    "XcodeDefault.xctoolchain/usr/lib/swift/clang";
-  EXPECT_EQ(HostInfoMacOSXTest::ComputeClangDir(xcode), xcode_clang);
-
-  std::string toolchain =
-      "/Applications/Xcode.app/Contents/Developer/Toolchains/"
-      "Swift-4.1-development-snapshot.xctoolchain/System/Library/"
-      "PrivateFrameworks/LLDB.framework";
-  std::string toolchain_clang =
-      "/Applications/Xcode.app/Contents/Developer/Toolchains/"
-      "Swift-4.1-development-snapshot.xctoolchain/usr/lib/swift/clang";
-  EXPECT_EQ(HostInfoMacOSXTest::ComputeClangDir(toolchain), toolchain_clang);
-
-  std::string cltools = "/Library/Developer/CommandLineTools/Library/"
-                        "PrivateFrameworks/LLDB.framework";
-  std::string cltools_clang =
-      "/Library/Developer/CommandLineTools/Library/PrivateFrameworks/"
-      "LLDB.framework/Resources/Clang";
-  EXPECT_EQ(HostInfoMacOSXTest::ComputeClangDir(cltools), cltools_clang);
-
-
-  // Test that a bogus path is detected.
-  EXPECT_NE(HostInfoMacOSXTest::ComputeClangDir(GetInputFilePath(xcode), true),
-            HostInfoMacOSXTest::ComputeClangDir(GetInputFilePath(xcode)));
-}
-#endif
+}
\ No newline at end of file




More information about the lldb-commits mailing list