Skip to content

Commit e162ea6

Browse files
authored
Merge pull request swiftlang#35799 from artemcm/BatchScanMatchInvocationImporterArgs
[Dependency Scanning] Batch Scanning: Update ClangImporter arguments when re-using a compiler instance.
2 parents daa4fff + 1825cbf commit e162ea6

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,18 @@ using CompilerArgInstanceCacheMap =
916916
llvm::StringMap<std::pair<std::unique_ptr<CompilerInstance>,
917917
std::unique_ptr<ModuleDependenciesCache>>>;
918918

919+
static void
920+
updateCachedInstanceSearchPaths(CompilerInstance &cachedInstance,
921+
const CompilerInstance &invocationInstance) {
922+
cachedInstance.getASTContext().SearchPathOpts =
923+
invocationInstance.getASTContext().SearchPathOpts;
924+
// The Clang Importer arguments must also match those of the current
925+
// invocation instead of the cached one because they include search
926+
// path directives for Clang.
927+
cachedInstance.getASTContext().ClangImporterOpts =
928+
invocationInstance.getASTContext().ClangImporterOpts;
929+
}
930+
919931
static bool
920932
forEachBatchEntry(CompilerInstance &invocationInstance,
921933
ModuleDependenciesCache &invocationCache,
@@ -950,13 +962,9 @@ forEachBatchEntry(CompilerInstance &invocationInstance,
950962
// before.
951963
pInstance = (*subInstanceMap)[entry.arguments].first.get();
952964
pCache = (*subInstanceMap)[entry.arguments].second.get();
953-
// We must update the search paths of this instance to instead reflect those of the current
954-
// invocation's.
955-
for (auto &path : invocationInstance.getASTContext().SearchPathOpts.ImportSearchPaths)
956-
pInstance->getASTContext().addSearchPath(path, false, false);
957-
for (auto &path : invocationInstance.getASTContext().SearchPathOpts.FrameworkSearchPaths)
958-
pInstance->getASTContext().addSearchPath(path.Path, true, path.IsSystem);
959-
965+
// We must update the search paths of this instance to instead reflect
966+
// those of the current scanner invocation.
967+
updateCachedInstanceSearchPaths(*pInstance, invocationInstance);
960968
} else {
961969
// Create a new instance by the arguments and save it in the map.
962970
subInstanceMap->insert(

0 commit comments

Comments
 (0)