]> granicus.if.org Git - clang/commitdiff
[modules] Stop dropping 'module.timestamp' files into the current directory
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 15 Aug 2015 00:34:15 +0000 (00:34 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 15 Aug 2015 00:34:15 +0000 (00:34 +0000)
when building with implicit modules disabled.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@245136 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/CompilerInstance.cpp
lib/Frontend/FrontendAction.cpp
lib/Lex/HeaderSearch.cpp
test/Modules/explicit-build-extra-files.cpp [new file with mode: 0644]

index a31b33ec379a24ae39ab52784cd3864da897ac6e..c678da982ed6eac107bc153d7926c43b25bfb959 100644 (file)
@@ -331,7 +331,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
 
   PP->setPreprocessedOutput(getPreprocessorOutputOpts().ShowCPP);
 
-  if (PP->getLangOpts().Modules)
+  if (PP->getLangOpts().Modules && PP->getLangOpts().ImplicitModules)
     PP->getHeaderSearchInfo().setModuleCachePath(getSpecificModuleCachePath());
 
   // Handle generating dependencies, if requested.
@@ -1154,6 +1154,7 @@ static void pruneModuleCache(const HeaderSearchOptions &HSOpts) {
   struct stat StatBuf;
   llvm::SmallString<128> TimestampFile;
   TimestampFile = HSOpts.ModuleCachePath;
+  assert(!TimestampFile.empty());
   llvm::sys::path::append(TimestampFile, "modules.timestamp");
 
   // Try to stat() the timestamp file.
@@ -1232,8 +1233,8 @@ void CompilerInstance::createModuleManager() {
 
     // If we're implicitly building modules but not currently recursively
     // building a module, check whether we need to prune the module cache.
-    if (getLangOpts().ImplicitModules &&
-        getSourceManager().getModuleBuildStack().empty() &&
+    if (getSourceManager().getModuleBuildStack().empty() &&
+        !getPreprocessor().getHeaderSearchInfo().getModuleCachePath().empty() &&
         getHeaderSearchOpts().ModuleCachePruneInterval > 0 &&
         getHeaderSearchOpts().ModuleCachePruneAfter > 0) {
       pruneModuleCache(getHeaderSearchOpts());
@@ -1600,6 +1601,8 @@ void CompilerInstance::makeModuleVisible(Module *Mod,
 
 GlobalModuleIndex *CompilerInstance::loadGlobalModuleIndex(
     SourceLocation TriggerLoc) {
+  if (getPreprocessor().getHeaderSearchInfo().getModuleCachePath().empty())
+    return nullptr;
   if (!ModuleManager)
     createModuleManager();
   // Can't do anything if we don't have the module manager.
index 36135e816fb39454155ce8e9b2774498b748c3c1..5b7494da58c03b9a178880e9271b96a2d4a9400e 100644 (file)
@@ -442,9 +442,11 @@ bool FrontendAction::Execute() {
   // there were any module-build failures.
   if (CI.shouldBuildGlobalModuleIndex() && CI.hasFileManager() &&
       CI.hasPreprocessor()) {
-    GlobalModuleIndex::writeIndex(
-        CI.getFileManager(), CI.getPCHContainerReader(),
-        CI.getPreprocessor().getHeaderSearchInfo().getModuleCachePath());
+    StringRef Cache =
+        CI.getPreprocessor().getHeaderSearchInfo().getModuleCachePath();
+    if (!Cache.empty())
+      GlobalModuleIndex::writeIndex(CI.getFileManager(),
+                                    CI.getPCHContainerReader(), Cache);
   }
 
   return true;
index 5282e8d42e8d3e386b4d57aa55d8427bee79e3a6..eea47198d642f87bbeaabb0c9813f03f1577c5e7 100644 (file)
@@ -129,10 +129,10 @@ std::string HeaderSearch::getModuleFileName(StringRef ModuleName,
                                             StringRef ModuleMapPath) {
   // If we don't have a module cache path or aren't supposed to use one, we
   // can't do anything.
-  if (ModuleCachePath.empty() || !LangOpts.ImplicitModules) 
+  if (getModuleCachePath().empty())
     return std::string();
 
-  SmallString<256> Result(ModuleCachePath);
+  SmallString<256> Result(getModuleCachePath());
   llvm::sys::fs::make_absolute(Result);
 
   if (HSOpts->DisableModuleHash) {
diff --git a/test/Modules/explicit-build-extra-files.cpp b/test/Modules/explicit-build-extra-files.cpp
new file mode 100644 (file)
index 0000000..6cec420
--- /dev/null
@@ -0,0 +1,14 @@
+// REQUIRES: shell
+//
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: cd %t
+// RUN: echo 'module X {}' > %t/x
+// RUN: echo 'module Y {}' > %t/y
+//
+// RUN: %clang_cc1 -emit-module -fmodules -fmodule-name=X %t/x -x c++ -o %t/x.pcm
+// RUN: %clang_cc1 -emit-module -fmodules -fmodule-name=Y %t/y -x c++ -o %t/y.pcm
+// RUN: %clang_cc1 -fmodules -fmodule-file=%t/x.pcm -fmodule-file=%t/y.pcm -x c++ /dev/null -fsyntax-only
+//
+// RUN: not test -f %t/modules.timestamp
+// RUN: not test -f %t/modules.idx