diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2025-09-10 15:17:44 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-09-10 15:17:44 -0700 |
commit | 4a4bddec3571d78c8073fa45b57bbabc8796d13d (patch) | |
tree | 86f2d605524499788b0def3a3164198c7f0a79b3 /clang/lib/Frontend/CompilerInstance.cpp | |
parent | c087da4b18192220debcd41d29de100987d1f324 (diff) | |
download | llvm-4a4bddec3571d78c8073fa45b57bbabc8796d13d.zip llvm-4a4bddec3571d78c8073fa45b57bbabc8796d13d.tar.gz llvm-4a4bddec3571d78c8073fa45b57bbabc8796d13d.tar.bz2 |
[clang] Delay normalization of `-fmodules-cache-path` (#150123)
This PR is part of an effort to remove file system usage from the
command line parsing code. The reason for that is that it's impossible
to do file system access correctly without a configured VFS, and the VFS
can only be configured after the command line is parsed. I don't want to
intertwine command line parsing and VFS configuration, so I decided to
perform the file system access after the command line is parsed and the
VFS is configured - ideally right before the file system entity is used
for the first time.
This patch delays normalization of the module cache path until
`CompilerInstance` is asked for the cache path in the current
compilation context.
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 8d1e9d6..0a23e0b 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -553,10 +553,25 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) { PP->setDependencyDirectivesGetter(*GetDependencyDirectives); } +void CompilerInstance::normalizeModuleCachePath( + FileManager &FileMgr, StringRef Path, + SmallVectorImpl<char> &NormalizedPath) { + NormalizedPath.assign(Path.begin(), Path.end()); + FileMgr.makeAbsolutePath(NormalizedPath); + llvm::sys::path::remove_dots(NormalizedPath); +} + std::string CompilerInstance::getSpecificModuleCachePath(StringRef ModuleHash) { + assert(FileMgr && "Specific module cache path requires a FileManager"); + + if (getHeaderSearchOpts().ModuleCachePath.empty()) + return ""; + // Set up the module path, including the hash for the module-creation options. - SmallString<256> SpecificModuleCache(getHeaderSearchOpts().ModuleCachePath); - if (!SpecificModuleCache.empty() && !getHeaderSearchOpts().DisableModuleHash) + SmallString<256> SpecificModuleCache; + normalizeModuleCachePath(*FileMgr, getHeaderSearchOpts().ModuleCachePath, + SpecificModuleCache); + if (!getHeaderSearchOpts().DisableModuleHash) llvm::sys::path::append(SpecificModuleCache, ModuleHash); return std::string(SpecificModuleCache); } |