@@ -38,10 +38,14 @@ using namespace clang::tooling;
3838using namespace clang ::tooling::dependencies;
3939
4040static 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) {
4344 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 );
4549 switch (MOK) {
4650 case ModuleOutputKind::ModuleFile:
4751 llvm::sys::path::replace_extension (
@@ -52,7 +56,7 @@ moduleCacheRelativeLookupModuleOutput(const ModuleID &MID, ModuleOutputKind MOK,
5256 outputPath, getExtension (swift::file_types::TY_Dependencies));
5357 break ;
5458 case ModuleOutputKind::DependencyTargets:
55- return MID. ModuleName + " -" + MID .ContextHash ;
59+ return MD. ID . ModuleName + " -" + MD. ID .ContextHash ;
5660 case ModuleOutputKind::DiagnosticSerializationFile:
5761 llvm::sys::path::replace_extension (
5862 outputPath, getExtension (swift::file_types::TY_SerializedDiagnostics));
@@ -137,7 +141,8 @@ getClangPrefixMapper(DependencyScanningTool &clangScanningTool,
137141ModuleDependencyVector ClangImporter::bridgeClangModuleDependencies (
138142 clang::tooling::dependencies::DependencyScanningTool &clangScanningTool,
139143 clang::tooling::dependencies::ModuleDepsGraph &clangDependencies,
140- StringRef moduleOutputPath, RemapPathCallback callback) {
144+ StringRef moduleOutputPath, StringRef stableModuleOutputPath,
145+ RemapPathCallback callback) {
141146 const auto &ctx = Impl.SwiftContext ;
142147 ModuleDependencyVector result;
143148
@@ -168,7 +173,8 @@ ModuleDependencyVector ClangImporter::bridgeClangModuleDependencies(
168173 swiftArgs.push_back (clangModuleDep.ID .ModuleName );
169174
170175 auto pcmPath = moduleCacheRelativeLookupModuleOutput (
171- clangModuleDep.ID , ModuleOutputKind::ModuleFile, moduleOutputPath);
176+ clangModuleDep, ModuleOutputKind::ModuleFile, moduleOutputPath,
177+ stableModuleOutputPath);
172178 swiftArgs.push_back (" -o" );
173179 swiftArgs.push_back (pcmPath);
174180
@@ -421,11 +427,10 @@ ClangImporter::getModuleDependencies(Identifier moduleName,
421427 }
422428 std::string workingDir = *optionalWorkingDir;
423429 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);
429434 };
430435
431436 auto clangModuleDependencies =
@@ -446,7 +451,8 @@ ClangImporter::getModuleDependencies(Identifier moduleName,
446451
447452 return bridgeClangModuleDependencies (clangScanningTool,
448453 *clangModuleDependencies,
449- moduleOutputPath, [&](StringRef path) {
454+ moduleOutputPath, sdkModuleOutputPath,
455+ [&](StringRef path) {
450456 if (mapper)
451457 return mapper->mapToString (path);
452458 return path.str ();
@@ -477,11 +483,13 @@ bool ClangImporter::getHeaderDependencies(
477483 }
478484 std::string workingDir = *optionalWorkingDir;
479485 auto moduleOutputPath = cache.getModuleOutputPath ();
486+ auto sdkModuleOutputPath = cache.getSDKModuleOutputPath ();
480487 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);
485493 };
486494 auto dependencies = clangScanningTool.getTranslationUnitDependencies (
487495 commandLineArgs, workingDir, cache.getAlreadySeenClangModules (),
@@ -492,7 +500,7 @@ bool ClangImporter::getHeaderDependencies(
492500 // Record module dependencies for each new module we found.
493501 auto bridgedDeps = bridgeClangModuleDependencies (
494502 clangScanningTool, dependencies->ModuleGraph ,
495- cache. getModuleOutputPath () ,
503+ moduleOutputPath, sdkModuleOutputPath ,
496504 [&cache](StringRef path) {
497505 return cache.getScanService ().remapPath (path);
498506 });
0 commit comments