Skip to content

Commit 31af288

Browse files
authored
Merge pull request #61971 from artemcm/DepScanPCMOutputPathInCache
[Dependency Scanning] Configure the Clang dependency scanner to generate PCM output paths
2 parents e6d981e + 11cd472 commit 31af288

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

lib/AST/ModuleDependencies.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ GlobalModuleDependenciesCache::GlobalModuleDependenciesCache()
230230
clang::tooling::dependencies::ScanningMode::DependencyDirectivesScan,
231231
clang::tooling::dependencies::ScanningOutputFormat::Full,
232232
clang::CASOptions(),
233-
/* Cache */ nullptr,
233+
/* Cache (llvm::cas::ActionCache) */ nullptr,
234234
/* SharedFS */ nullptr,
235235
/* ReuseFileManager */ false,
236236
/* OptimizeArgs */ false) {}

lib/ClangImporter/ClangModuleDependencyScanner.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,32 @@
2222
#include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
2323
#include "llvm/Support/FileSystem.h"
2424
#include "llvm/Support/Signals.h"
25+
#include "llvm/Support/Path.h"
2526

2627
using namespace swift;
2728

2829
using namespace clang::tooling;
2930
using namespace clang::tooling::dependencies;
3031

31-
static std::string lookupModuleOutput(const ModuleID &MID,
32-
ModuleOutputKind MOK) {
33-
// Deciding the output paths is done in swift-driver.
32+
static std::string moduleCacheRelativeLookupModuleOutput(const ModuleID &MID,
33+
ModuleOutputKind MOK,
34+
const std::string &moduleCachePathStr) {
35+
llvm::SmallString<128> outputPath(moduleCachePathStr);
36+
llvm::sys::path::append(outputPath, MID.ModuleName + "-" + MID.ContextHash);
3437
switch (MOK) {
3538
case ModuleOutputKind::ModuleFile:
36-
return "<replace-me>";
39+
llvm::sys::path::replace_extension(outputPath, getExtension(swift::file_types::TY_ClangModuleFile));
40+
break;
3741
case ModuleOutputKind::DependencyFile:
38-
return "<replace-me>";
42+
llvm::sys::path::replace_extension(outputPath, getExtension(swift::file_types::TY_Dependencies));
43+
break;
3944
case ModuleOutputKind::DependencyTargets:
4045
return MID.ModuleName + "-" + MID.ContextHash;
4146
case ModuleOutputKind::DiagnosticSerializationFile:
42-
return "<replace-me>";
47+
llvm::sys::path::replace_extension(outputPath, getExtension(swift::file_types::TY_SerializedDiagnostics));
48+
break;
4349
}
44-
llvm_unreachable("Fully covered switch above!");
50+
return outputPath.str().str();
4551
}
4652

4753
// Add search paths.
@@ -228,6 +234,12 @@ Optional<ModuleDependencies> ClangImporter::getModuleDependencies(
228234
workingDir = *(clangWorkingDirPos - 1);
229235
}
230236

237+
auto moduleCachePath = getModuleCachePathFromClang(getClangInstance());
238+
auto lookupModuleOutput = [moduleCachePath] (const ModuleID &MID,
239+
ModuleOutputKind MOK) -> std::string {
240+
return moduleCacheRelativeLookupModuleOutput(MID, MOK, moduleCachePath);
241+
};
242+
231243
auto clangDependencies = cache.getClangScannerTool().getFullDependencies(
232244
commandLineArgs, workingDir, cache.getAlreadySeenClangModules(),
233245
lookupModuleOutput, moduleName);
@@ -284,6 +296,12 @@ bool ClangImporter::addBridgingHeaderDependencies(
284296
std::string workingDir =
285297
ctx.SourceMgr.getFileSystem()->getCurrentWorkingDirectory().get();
286298

299+
auto moduleCachePath = getModuleCachePathFromClang(getClangInstance());
300+
auto lookupModuleOutput = [moduleCachePath] (const ModuleID &MID,
301+
ModuleOutputKind MOK) -> std::string {
302+
return moduleCacheRelativeLookupModuleOutput(MID, MOK, moduleCachePath);
303+
};
304+
287305
auto clangDependencies = cache.getClangScannerTool().getFullDependencies(
288306
commandLineArgs, workingDir, cache.getAlreadySeenClangModules(),
289307
lookupModuleOutput);

test/ScanDependencies/module_deps.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ import SubE
210210

211211
/// --------Clang module B
212212
// CHECK-LABEL: "modulePath": "B.pcm"
213+
// CHECK: "contextHash": [[B_CONTEXT:"{{.*}}"]],
214+
// CHECK: "-o"
215+
// CHECK-NEXT: "-Xcc"
216+
// CHECK-NEXT: "%t/clang-module-cache/B-[[B_CONTEXT]].pcm",
213217

214218
// CHECK-NEXT: sourceFiles
215219
// CHECK-DAG: module.modulemap
@@ -222,7 +226,11 @@ import SubE
222226

223227
/// --------Clang module SwiftShims
224228
// CHECK-LABEL: "modulePath": "SwiftShims.pcm",
225-
229+
// CHECK: "contextHash": [[SHIMS_CONTEXT:"{{.*}}"]],
230+
// CHECK: "-o"
231+
// CHECK-NEXT: "-Xcc"
232+
// CHECK-NEXT: "%t/clang-module-cache/SwiftShims-[[SHIMS_CONTEXT]].pcm",
233+
// CHECK: "-fmodule-file=A=%t/clang-module-cache/A-{{.*}}.pcm"
226234
// CHECK-NO-SEARCH-PATHS-NOT: "-prebuilt-module-cache-path"
227235

228236
// Check make-style dependencies

0 commit comments

Comments
 (0)