Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions clang/lib/Frontend/CompilerInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,14 +546,11 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
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;
normalizeModuleCachePath(*FileMgr, getHeaderSearchOpts().ModuleCachePath,
SpecificModuleCache);
if (!getHeaderSearchOpts().DisableModuleHash)
if (!SpecificModuleCache.empty() && !getHeaderSearchOpts().DisableModuleHash)
llvm::sys::path::append(SpecificModuleCache, ModuleHash);
return std::string(SpecificModuleCache);
}
Expand Down
6 changes: 4 additions & 2 deletions clang/lib/Lex/HeaderSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2186,6 +2186,8 @@ std::string HeaderSearch::suggestPathToFileForDiagnostics(
void clang::normalizeModuleCachePath(FileManager &FileMgr, StringRef Path,
SmallVectorImpl<char> &NormalizedPath) {
NormalizedPath.assign(Path.begin(), Path.end());
FileMgr.makeAbsolutePath(NormalizedPath);
llvm::sys::path::remove_dots(NormalizedPath);
if (!NormalizedPath.empty()) {
FileMgr.makeAbsolutePath(NormalizedPath);
llvm::sys::path::remove_dots(NormalizedPath);
}
}
11 changes: 5 additions & 6 deletions clang/lib/Tooling/DependencyScanning/DependencyScannerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,13 +524,12 @@ bool initializeScanCompilerInstance(
// Use the dependency scanning optimized file system if requested to do so.
if (DepFS) {
DepFS->resetBypassedPathPrefix();
if (!ScanInstance.getHeaderSearchOpts().ModuleCachePath.empty()) {
SmallString<256> ModulesCachePath;
normalizeModuleCachePath(
ScanInstance.getFileManager(),
ScanInstance.getHeaderSearchOpts().ModuleCachePath, ModulesCachePath);
SmallString<256> ModulesCachePath;
normalizeModuleCachePath(ScanInstance.getFileManager(),
ScanInstance.getHeaderSearchOpts().ModuleCachePath,
ModulesCachePath);
if (!ModulesCachePath.empty())
DepFS->setBypassedPathPrefix(ModulesCachePath);
}

ScanInstance.setDependencyDirectivesGetter(
std::make_unique<ScanningDependencyDirectivesGetter>(
Expand Down
17 changes: 17 additions & 0 deletions clang/test/Modules/explicit-build-cwd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// This test checks that explicitly building the same module from different
// working directories results in the same PCM contents.

// RUN: rm -rf %t
// RUN: split-file %s %t
// RUN: mkdir %t/one
// RUN: mkdir %t/two

//--- module.modulemap
module M { header "M.h" }

//--- M.h

// RUN: cd %t/one && %clang_cc1 -fmodules -emit-module %t/module.modulemap -fmodule-name=M -o %t/M_one.pcm
// RUN: cd %t/two && %clang_cc1 -fmodules -emit-module %t/module.modulemap -fmodule-name=M -o %t/M_two.pcm

// RUN: diff %t/M_one.pcm %t/M_two.pcm