@@ -40,11 +40,22 @@ using namespace clang::tooling::dependencies;
40
40
static std::string
41
41
moduleCacheRelativeLookupModuleOutput (const ModuleDeps &MD, ModuleOutputKind MOK,
42
42
const StringRef moduleCachePath,
43
- const StringRef stableModuleCachePath) {
43
+ const StringRef stableModuleCachePath,
44
+ const StringRef runtimeResourcePath) {
44
45
llvm::SmallString<128 > outputPath (moduleCachePath);
45
46
if (MD.IsInStableDirectories )
46
47
outputPath = stableModuleCachePath;
47
48
49
+ // FIXME: This is a hack to treat Clang modules defined in the compiler's
50
+ // own resource directory as stable, when they are not reported as such
51
+ // by the Clang scanner.
52
+ if (!runtimeResourcePath.empty () &&
53
+ hasPrefix (llvm::sys::path::begin (MD.ClangModuleMapFile ),
54
+ llvm::sys::path::end (MD.ClangModuleMapFile ),
55
+ llvm::sys::path::begin (runtimeResourcePath),
56
+ llvm::sys::path::end (runtimeResourcePath)))
57
+ outputPath = stableModuleCachePath;
58
+
48
59
llvm::sys::path::append (outputPath, MD.ID .ModuleName + " -" + MD.ID .ContextHash );
49
60
switch (MOK) {
50
61
case ModuleOutputKind::ModuleFile:
@@ -174,7 +185,7 @@ ModuleDependencyVector ClangImporter::bridgeClangModuleDependencies(
174
185
175
186
auto pcmPath = moduleCacheRelativeLookupModuleOutput (
176
187
clangModuleDep, ModuleOutputKind::ModuleFile, moduleOutputPath,
177
- stableModuleOutputPath);
188
+ stableModuleOutputPath, ctx. SearchPathOpts . RuntimeResourcePath );
178
189
swiftArgs.push_back (" -o" );
179
190
swiftArgs.push_back (pcmPath);
180
191
@@ -427,10 +438,11 @@ ClangImporter::getModuleDependencies(Identifier moduleName,
427
438
}
428
439
std::string workingDir = *optionalWorkingDir;
429
440
auto lookupModuleOutput =
430
- [moduleOutputPath, sdkModuleOutputPath]
441
+ [moduleOutputPath, sdkModuleOutputPath, &ctx ]
431
442
(const ModuleDeps &MD, ModuleOutputKind MOK) -> std::string {
432
443
return moduleCacheRelativeLookupModuleOutput (MD, MOK, moduleOutputPath,
433
- sdkModuleOutputPath);
444
+ sdkModuleOutputPath,
445
+ ctx.SearchPathOpts .RuntimeResourcePath );
434
446
};
435
447
436
448
auto clangModuleDependencies =
@@ -485,11 +497,12 @@ bool ClangImporter::getHeaderDependencies(
485
497
auto moduleOutputPath = cache.getModuleOutputPath ();
486
498
auto sdkModuleOutputPath = cache.getSDKModuleOutputPath ();
487
499
auto lookupModuleOutput =
488
- [moduleOutputPath, sdkModuleOutputPath]
500
+ [moduleOutputPath, sdkModuleOutputPath, &ctx ]
489
501
(const ModuleDeps &MD, ModuleOutputKind MOK) -> std::string {
490
502
return moduleCacheRelativeLookupModuleOutput (MD, MOK,
491
503
moduleOutputPath,
492
- sdkModuleOutputPath);
504
+ sdkModuleOutputPath,
505
+ ctx.SearchPathOpts .RuntimeResourcePath );
493
506
};
494
507
auto dependencies = clangScanningTool.getTranslationUnitDependencies (
495
508
commandLineArgs, workingDir, cache.getAlreadySeenClangModules (),
0 commit comments