@@ -38,10 +38,14 @@ using namespace clang::tooling;
38
38
using namespace clang ::tooling::dependencies;
39
39
40
40
static std::string
41
- moduleCacheRelativeLookupModuleOutput (const ModuleID &MID, ModuleOutputKind MOK,
42
- const StringRef moduleCachePath) {
41
+ moduleCacheRelativeLookupModuleOutput (const ModuleDeps &MD, ModuleOutputKind MOK,
42
+ const StringRef moduleCachePath,
43
+ const StringRef stableModuleCachePath) {
43
44
llvm::SmallString<128 > outputPath (moduleCachePath);
44
- llvm::sys::path::append (outputPath, MID.ModuleName + " -" + MID.ContextHash );
45
+ if (MD.IsInStableDirectories )
46
+ outputPath = stableModuleCachePath;
47
+
48
+ llvm::sys::path::append (outputPath, MD.ID .ModuleName + " -" + MD.ID .ContextHash );
45
49
switch (MOK) {
46
50
case ModuleOutputKind::ModuleFile:
47
51
llvm::sys::path::replace_extension (
@@ -52,7 +56,7 @@ moduleCacheRelativeLookupModuleOutput(const ModuleID &MID, ModuleOutputKind MOK,
52
56
outputPath, getExtension (swift::file_types::TY_Dependencies));
53
57
break ;
54
58
case ModuleOutputKind::DependencyTargets:
55
- return MID. ModuleName + " -" + MID .ContextHash ;
59
+ return MD. ID . ModuleName + " -" + MD. ID .ContextHash ;
56
60
case ModuleOutputKind::DiagnosticSerializationFile:
57
61
llvm::sys::path::replace_extension (
58
62
outputPath, getExtension (swift::file_types::TY_SerializedDiagnostics));
@@ -137,7 +141,8 @@ getClangPrefixMapper(DependencyScanningTool &clangScanningTool,
137
141
ModuleDependencyVector ClangImporter::bridgeClangModuleDependencies (
138
142
clang::tooling::dependencies::DependencyScanningTool &clangScanningTool,
139
143
clang::tooling::dependencies::ModuleDepsGraph &clangDependencies,
140
- StringRef moduleOutputPath, RemapPathCallback callback) {
144
+ StringRef moduleOutputPath, StringRef stableModuleOutputPath,
145
+ RemapPathCallback callback) {
141
146
const auto &ctx = Impl.SwiftContext ;
142
147
ModuleDependencyVector result;
143
148
@@ -168,7 +173,8 @@ ModuleDependencyVector ClangImporter::bridgeClangModuleDependencies(
168
173
swiftArgs.push_back (clangModuleDep.ID .ModuleName );
169
174
170
175
auto pcmPath = moduleCacheRelativeLookupModuleOutput (
171
- clangModuleDep.ID , ModuleOutputKind::ModuleFile, moduleOutputPath);
176
+ clangModuleDep, ModuleOutputKind::ModuleFile, moduleOutputPath,
177
+ stableModuleOutputPath);
172
178
swiftArgs.push_back (" -o" );
173
179
swiftArgs.push_back (pcmPath);
174
180
@@ -421,11 +427,10 @@ ClangImporter::getModuleDependencies(Identifier moduleName,
421
427
}
422
428
std::string workingDir = *optionalWorkingDir;
423
429
auto lookupModuleOutput =
424
- [moduleOutputPath](const ModuleDeps &MD,
425
- ModuleOutputKind MOK) -> std::string {
426
- // ACTODO: Once the clang scanner gets the required functionality,
427
- // use sdkModuleOutputPath for modules whose modulemap is a part of the SDK.
428
- return moduleCacheRelativeLookupModuleOutput (MD.ID , MOK, moduleOutputPath);
430
+ [moduleOutputPath, sdkModuleOutputPath]
431
+ (const ModuleDeps &MD, ModuleOutputKind MOK) -> std::string {
432
+ return moduleCacheRelativeLookupModuleOutput (MD, MOK, moduleOutputPath,
433
+ sdkModuleOutputPath);
429
434
};
430
435
431
436
auto clangModuleDependencies =
@@ -446,7 +451,8 @@ ClangImporter::getModuleDependencies(Identifier moduleName,
446
451
447
452
return bridgeClangModuleDependencies (clangScanningTool,
448
453
*clangModuleDependencies,
449
- moduleOutputPath, [&](StringRef path) {
454
+ moduleOutputPath, sdkModuleOutputPath,
455
+ [&](StringRef path) {
450
456
if (mapper)
451
457
return mapper->mapToString (path);
452
458
return path.str ();
@@ -477,11 +483,13 @@ bool ClangImporter::getHeaderDependencies(
477
483
}
478
484
std::string workingDir = *optionalWorkingDir;
479
485
auto moduleOutputPath = cache.getModuleOutputPath ();
486
+ auto sdkModuleOutputPath = cache.getSDKModuleOutputPath ();
480
487
auto lookupModuleOutput =
481
- [moduleOutputPath](const ModuleDeps &MD,
482
- ModuleOutputKind MOK) -> std::string {
483
- return moduleCacheRelativeLookupModuleOutput (MD.ID , MOK,
484
- moduleOutputPath);
488
+ [moduleOutputPath, sdkModuleOutputPath]
489
+ (const ModuleDeps &MD, ModuleOutputKind MOK) -> std::string {
490
+ return moduleCacheRelativeLookupModuleOutput (MD, MOK,
491
+ moduleOutputPath,
492
+ sdkModuleOutputPath);
485
493
};
486
494
auto dependencies = clangScanningTool.getTranslationUnitDependencies (
487
495
commandLineArgs, workingDir, cache.getAlreadySeenClangModules (),
@@ -492,7 +500,7 @@ bool ClangImporter::getHeaderDependencies(
492
500
// Record module dependencies for each new module we found.
493
501
auto bridgedDeps = bridgeClangModuleDependencies (
494
502
clangScanningTool, dependencies->ModuleGraph ,
495
- cache. getModuleOutputPath () ,
503
+ moduleOutputPath, sdkModuleOutputPath ,
496
504
[&cache](StringRef path) {
497
505
return cache.getScanService ().remapPath (path);
498
506
});
0 commit comments