Skip to content

Commit 6e845bb

Browse files
committed
Centralize module cache normalization
1 parent 0e174e9 commit 6e845bb

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

clang/include/clang/Frontend/CompilerInstance.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,8 @@ class CompilerInstance : public ModuleLoader {
699699
GetDependencyDirectives = std::move(Getter);
700700
}
701701

702+
static SmallString<256> normalizeModuleCachePath(FileManager &FileMgr,
703+
StringRef ModuleCachePath);
702704
std::string getSpecificModuleCachePath(StringRef ModuleHash);
703705
std::string getSpecificModuleCachePath() {
704706
return getSpecificModuleCachePath(getInvocation().getModuleHash());

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,14 +547,24 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
547547
PP->setDependencyDirectivesGetter(*GetDependencyDirectives);
548548
}
549549

550+
SmallString<256>
551+
CompilerInstance::normalizeModuleCachePath(FileManager &FileMgr,
552+
StringRef ModuleCachePath) {
553+
SmallString<256> NormalizedModuleCachePath(ModuleCachePath);
554+
FileMgr.makeAbsolutePath(NormalizedModuleCachePath);
555+
llvm::sys::path::remove_dots(NormalizedModuleCachePath);
556+
return NormalizedModuleCachePath;
557+
}
558+
550559
std::string CompilerInstance::getSpecificModuleCachePath(StringRef ModuleHash) {
560+
assert(FileMgr && "Specific module cache path requires a FileManager");
561+
551562
if (getHeaderSearchOpts().ModuleCachePath.empty())
552563
return "";
553564

554565
// Set up the module path, including the hash for the module-creation options.
555-
SmallString<256> SpecificModuleCache(getHeaderSearchOpts().ModuleCachePath);
556-
FileMgr->makeAbsolutePath(SpecificModuleCache);
557-
llvm::sys::path::remove_dots(SpecificModuleCache);
566+
SmallString<256> SpecificModuleCache =
567+
normalizeModuleCachePath(*FileMgr, getHeaderSearchOpts().ModuleCachePath);
558568
if (!getHeaderSearchOpts().DisableModuleHash)
559569
llvm::sys::path::append(SpecificModuleCache, ModuleHash);
560570
return std::string(SpecificModuleCache);

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "clang/Basic/TargetInfo.h"
5858
#include "clang/Basic/TargetOptions.h"
5959
#include "clang/Basic/Version.h"
60+
#include "clang/Frontend/CompilerInstance.h"
6061
#include "clang/Lex/HeaderSearch.h"
6162
#include "clang/Lex/HeaderSearchOptions.h"
6263
#include "clang/Lex/MacroInfo.h"
@@ -1710,13 +1711,12 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, StringRef isysroot) {
17101711
const HeaderSearchOptions &HSOpts =
17111712
PP.getHeaderSearchInfo().getHeaderSearchOpts();
17121713

1714+
auto HSOpts_ModuleCachePath = CompilerInstance::normalizeModuleCachePath(
1715+
PP.getFileManager(), HSOpts.ModuleCachePath);
1716+
17131717
AddString(HSOpts.Sysroot, Record);
17141718
AddString(HSOpts.ResourceDir, Record);
1715-
1716-
SmallString<256> ModuleCachePath(HSOpts.ModuleCachePath);
1717-
(void)cleanPathForOutput(PP.getFileManager(), ModuleCachePath);
1718-
AddString(ModuleCachePath, Record);
1719-
1719+
AddString(HSOpts_ModuleCachePath, Record);
17201720
AddString(HSOpts.ModuleUserBuildPath, Record);
17211721
Record.push_back(HSOpts.DisableModuleHash);
17221722
Record.push_back(HSOpts.ImplicitModuleMaps);

clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,10 +448,8 @@ class DependencyScanningAction {
448448

449449
// Use the dependency scanning optimized file system if requested to do so.
450450
if (DepFS) {
451-
SmallString<256> ModulesCachePath(
452-
ScanInstance.getHeaderSearchOpts().ModuleCachePath);
453-
FileMgr->makeAbsolutePath(ModulesCachePath);
454-
llvm::sys::path::remove_dots(ModulesCachePath);
451+
auto ModulesCachePath = CompilerInstance::normalizeModuleCachePath(
452+
*FileMgr, ScanInstance.getHeaderSearchOpts().ModuleCachePath);
455453
DepFS->resetBypassedPathPrefix();
456454
if (!ModulesCachePath.empty())
457455
DepFS->setBypassedPathPrefix(ModulesCachePath);

0 commit comments

Comments
 (0)