[clang] fac39d1 - [clang] Allow CLANG_MODULE_CACHE_PATH env var to override module caching behavior

Alex Brachet via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 9 09:56:23 PDT 2022


Author: Alex Brachet
Date: 2022-06-09T16:55:37Z
New Revision: fac39d14b129fa545fc7633ef8e0be9ddf45cab2

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

LOG: [clang] Allow CLANG_MODULE_CACHE_PATH env var to override module caching behavior

CLANG_MODULE_CACHE_PATH can be used to change where clang should
put the module cache, or can be set to "" to disable caching entirely.

Differential revision: https://reviews.llvm.org/D126678

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/Clang.cpp
    clang/test/Driver/modules-cache-path.m

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index fe79921524727..ceac142653ebe 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3600,6 +3600,11 @@ static void RenderBuiltinOptions(const ToolChain &TC, const llvm::Triple &T,
 }
 
 bool Driver::getDefaultModuleCachePath(SmallVectorImpl<char> &Result) {
+  if (const char *Str = std::getenv("CLANG_MODULE_CACHE_PATH")) {
+    Twine Path{Str};
+    Path.toVector(Result);
+    return Path.getSingleStringRef() != "";
+  }
   if (llvm::sys::path::cache_directory(Result)) {
     llvm::sys::path::append(Result, "clang");
     llvm::sys::path::append(Result, "ModuleCache");

diff  --git a/clang/test/Driver/modules-cache-path.m b/clang/test/Driver/modules-cache-path.m
index 51df6739a5055..1da27d2143631 100644
--- a/clang/test/Driver/modules-cache-path.m
+++ b/clang/test/Driver/modules-cache-path.m
@@ -1,2 +1,10 @@
 // RUN: %clang -fmodules -### %s 2>&1 | FileCheck %s -check-prefix=CHECK-DEFAULT
 // CHECK-DEFAULT: -fmodules-cache-path={{.*}}clang{{[/\\]+}}ModuleCache
+
+// RUN: env CLANG_MODULE_CACHE_PATH=/dev/null \
+// RUN:   %clang -fmodules -### %s 2>&1 | FileCheck %s -check-prefix=OVERRIDE
+// OVERRIDE: -fmodules-cache-path=/dev/null
+
+// RUN: env CLANG_MODULE_CACHE_PATH= \
+// RUN:   %clang -fmodules -### %s 2>&1 | FileCheck %s -check-prefix=DISABLE
+// DISABLE-NOT: -fmodules-cache-path=


        


More information about the cfe-commits mailing list