[Lldb-commits] [PATCH] D43099: Make LLDB's clang module cache path customizable

Adrian Prantl via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Feb 8 16:05:25 PST 2018


aprantl created this revision.
aprantl added a reviewer: jingham.

This patch makes LLDB's clang module cache path customizable via `settings set target.clang-modules-cache-path <path>` and uses it in the LLDB testsuite to reuse the same location inside the build directory for LLDB and clang.


https://reviews.llvm.org/D43099

Files:
  include/lldb/Target/Target.h
  packages/Python/lldbsuite/test/lldbtest.py
  source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
  source/Target/Target.cpp


Index: source/Target/Target.cpp
===================================================================
--- source/Target/Target.cpp
+++ source/Target/Target.cpp
@@ -3509,6 +3509,9 @@
      OptionValue::eTypeString, nullptr, nullptr,
      "A list of trap handler function names, e.g. a common Unix user process "
      "one is _sigtramp."},
+    {"clang-modules-cache-path",
+     OptionValue::eTypeFileSpec, false, 0, nullptr, nullptr,
+     "The path to the clang modules cache directory (-fmodules-cache-path)."},
     {"display-runtime-support-values", OptionValue::eTypeBoolean, false, false,
      nullptr, nullptr, "If true, LLDB will show variables that are meant to "
                        "support the operation of a language's runtime "
@@ -3558,6 +3561,7 @@
   ePropertyMemoryModuleLoadLevel,
   ePropertyDisplayExpressionsInCrashlogs,
   ePropertyTrapHandlerNames,
+  ePropertyClangModulesCachePath,
   ePropertyDisplayRuntimeSupportValues,
   ePropertyNonStopModeEnabled,
   ePropertyExperimental
@@ -3937,6 +3941,15 @@
   return option_value->GetCurrentValue();
 }
 
+FileSpec &TargetProperties::GetClangModulesCachePath() {
+  const uint32_t idx = ePropertyClangModulesCachePath;
+  OptionValueFileSpec *option_value =
+      m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpec(nullptr, false,
+                                                               idx);
+  assert(option_value);
+  return option_value->GetCurrentValue();
+}
+
 FileSpecList &TargetProperties::GetClangModuleSearchPaths() {
   const uint32_t idx = ePropertyClangModuleSearchPaths;
   OptionValueFileSpecList *option_value =
Index: source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
===================================================================
--- source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
+++ source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
@@ -590,14 +590,17 @@
   // Add additional search paths with { "-I", path } or { "-F", path } here.
 
   {
-    llvm::SmallString<128> DefaultModuleCache;
-    const bool erased_on_reboot = false;
-    llvm::sys::path::system_temp_directory(erased_on_reboot,
-                                           DefaultModuleCache);
-    llvm::sys::path::append(DefaultModuleCache, "org.llvm.clang");
-    llvm::sys::path::append(DefaultModuleCache, "ModuleCache");
+    llvm::SmallString<128> Path;
+    target.GetClangModulesCachePath().GetPath(Path);
+    if (Path.empty()) {
+      // This code is copied from the Clang driver.
+      const bool erased_on_reboot = false;
+      llvm::sys::path::system_temp_directory(erased_on_reboot, Path);
+      llvm::sys::path::append(Path, "org.llvm.clang");
+      llvm::sys::path::append(Path, "ModuleCache");
+    }
     std::string module_cache_argument("-fmodules-cache-path=");
-    module_cache_argument.append(DefaultModuleCache.str().str());
+    module_cache_argument.append(Path.str());
     compiler_invocation_arguments.push_back(module_cache_argument);
   }
 
Index: packages/Python/lldbsuite/test/lldbtest.py
===================================================================
--- packages/Python/lldbsuite/test/lldbtest.py
+++ packages/Python/lldbsuite/test/lldbtest.py
@@ -859,6 +859,10 @@
                 self.darwinWithFramework = False
         self.makeBuildDir()
 
+        # set the clang modules cache path.
+        mod_cache = os.path.join(self.getBuildDir(), "module-cache")
+        self.runCmd("settings set target.clang-modules-cache-path " + mod_cache)
+
     def setAsync(self, value):
         """ Sets async mode to True/False and ensures it is reset after the testcase completes."""
         old_async = self.dbg.GetAsync()
Index: include/lldb/Target/Target.h
===================================================================
--- include/lldb/Target/Target.h
+++ include/lldb/Target/Target.h
@@ -126,6 +126,8 @@
 
   FileSpecList &GetDebugFileSearchPaths();
 
+  FileSpec &GetClangModulesCachePath();
+
   FileSpecList &GetClangModuleSearchPaths();
 
   bool GetEnableAutoImportClangModules() const;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43099.133527.patch
Type: text/x-patch
Size: 4071 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180209/bb3551e0/attachment.bin>


More information about the lldb-commits mailing list