|
90 | 90 | #include "clang/Serialization/ASTReader.h" |
91 | 91 | #include "clang/Serialization/ASTWriter.h" |
92 | 92 | #include "clang/Serialization/ObjectFilePCHContainerReader.h" |
| 93 | +#include "clang/Tooling/DependencyScanning/ModuleDepCollector.h" |
93 | 94 | #include "clang/Tooling/DependencyScanning/ScanAndUpdateArgs.h" |
94 | 95 | #include "llvm/ADT/IntrusiveRefCntPtr.h" |
95 | 96 | #include "llvm/ADT/STLExtras.h" |
@@ -1062,27 +1063,6 @@ std::string ClangImporter::getOriginalSourceFile(StringRef PCHFilename) { |
1062 | 1063 | Impl.Instance->getPCHContainerReader(), Impl.Instance->getDiagnostics()); |
1063 | 1064 | } |
1064 | 1065 |
|
1065 | | -void ClangImporter::addClangInvovcationDependencies( |
1066 | | - std::vector<std::string> &files) { |
1067 | | - auto addFiles = [&files](const auto &F) { |
1068 | | - files.insert(files.end(), F.begin(), F.end()); |
1069 | | - }; |
1070 | | - auto &invocation = *Impl.Invocation; |
1071 | | - // FIXME: Add file dependencies that are not accounted. The long term solution |
1072 | | - // is to do a dependency scanning for clang importer and use that directly. |
1073 | | - SmallVector<std::string, 4> HeaderMapFileNames; |
1074 | | - Impl.Instance->getPreprocessor().getHeaderSearchInfo().getHeaderMapFileNames( |
1075 | | - HeaderMapFileNames); |
1076 | | - addFiles(HeaderMapFileNames); |
1077 | | - addFiles(invocation.getHeaderSearchOpts().VFSOverlayFiles); |
1078 | | - // FIXME: Should not depend on working directory. Build system/swift driver |
1079 | | - // should not pass working directory here but if that option is passed, |
1080 | | - // repect that and add that into CASFS. |
1081 | | - auto CWD = invocation.getFileSystemOpts().WorkingDir; |
1082 | | - if (!CWD.empty()) |
1083 | | - files.push_back(CWD); |
1084 | | -} |
1085 | | - |
1086 | 1066 | std::optional<std::string> |
1087 | 1067 | ClangImporter::getPCHFilename(const ClangImporterOptions &ImporterOptions, |
1088 | 1068 | StringRef SwiftPCHHash, bool &isExplicit) { |
@@ -1210,9 +1190,8 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments( |
1210 | 1190 | clang::frontend::ActionKind::GenerateModule || |
1211 | 1191 | CI->getFrontendOpts().ProgramAction == |
1212 | 1192 | clang::frontend::ActionKind::GeneratePCH) && |
1213 | | - ctx.ClangImporterOpts.HasClangIncludeTreeRoot) { |
1214 | | - CI->getFrontendOpts().CASIncludeTreeID = |
1215 | | - ctx.CASOpts.ClangIncludeTrees.back(); |
| 1193 | + !ctx.CASOpts.ClangIncludeTree.empty()) { |
| 1194 | + CI->getFrontendOpts().CASIncludeTreeID = ctx.CASOpts.ClangIncludeTree; |
1216 | 1195 | CI->getFrontendOpts().Inputs.clear(); |
1217 | 1196 | } |
1218 | 1197 | } |
@@ -1271,7 +1250,7 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments( |
1271 | 1250 |
|
1272 | 1251 | std::vector<std::string> FilteredModuleMapFiles; |
1273 | 1252 | for (auto ModuleMapFile : CI->getFrontendOpts().ModuleMapFiles) { |
1274 | | - if (ctx.ClangImporterOpts.HasClangIncludeTreeRoot) { |
| 1253 | + if (ctx.CASOpts.HasImmutableFileSystem) { |
1275 | 1254 | // There is no need to add any module map file here. Issue a warning and |
1276 | 1255 | // drop the option. |
1277 | 1256 | Impl.diagnose(SourceLoc(), diag::module_map_ignored, ModuleMapFile); |
@@ -1351,7 +1330,7 @@ ClangImporter::create(ASTContext &ctx, |
1351 | 1330 | fileMapping.requiresBuiltinHeadersInSystemModules; |
1352 | 1331 |
|
1353 | 1332 | // Avoid creating indirect file system when using include tree. |
1354 | | - if (!ctx.ClangImporterOpts.HasClangIncludeTreeRoot) { |
| 1333 | + if (!ctx.CASOpts.HasImmutableFileSystem) { |
1355 | 1334 | // Wrap Swift's FS to allow Clang to override the working directory |
1356 | 1335 | VFS = llvm::vfs::RedirectingFileSystem::create( |
1357 | 1336 | fileMapping.redirectedFiles, true, *ctx.SourceMgr.getFileSystem()); |
@@ -2756,7 +2735,6 @@ ClangImporter::Implementation::Implementation( |
2756 | 2735 | !ctx.ClangImporterOpts.BridgingHeader.empty()), |
2757 | 2736 | DisableOverlayModules(ctx.ClangImporterOpts.DisableOverlayModules), |
2758 | 2737 | EnableClangSPI(ctx.ClangImporterOpts.EnableClangSPI), |
2759 | | - UseClangIncludeTree(ctx.ClangImporterOpts.UseClangIncludeTree), |
2760 | 2738 | importSymbolicCXXDecls( |
2761 | 2739 | ctx.LangOpts.hasFeature(Feature::ImportSymbolicCXXDecls)), |
2762 | 2740 | IsReadingBridgingPCH(false), |
@@ -4281,15 +4259,14 @@ ClangImporter::getSwiftExplicitModuleDirectCC1Args() const { |
4281 | 4259 | PPOpts.MacroIncludes.clear(); |
4282 | 4260 | PPOpts.Includes.clear(); |
4283 | 4261 |
|
4284 | | - // CodeGenOptions. |
4285 | | - auto &CGOpts = instance.getCodeGenOpts(); |
4286 | | - CGOpts.DebugCompilationDir.clear(); |
| 4262 | + // Clear benign CodeGenOptions. |
| 4263 | + clang::tooling::dependencies::resetBenignCodeGenOptions( |
| 4264 | + clang::frontend::ActionKind::GenerateModule, instance.getLangOpts(), |
| 4265 | + instance.getCodeGenOpts()); |
4287 | 4266 |
|
4288 | | - if (Impl.SwiftContext.ClangImporterOpts.UseClangIncludeTree) { |
4289 | | - // FileSystemOptions. |
4290 | | - auto &FSOpts = instance.getFileSystemOpts(); |
4291 | | - FSOpts.WorkingDir.clear(); |
4292 | | - } |
| 4267 | + // FileSystemOptions. |
| 4268 | + auto &FSOpts = instance.getFileSystemOpts(); |
| 4269 | + FSOpts.WorkingDir.clear(); |
4293 | 4270 |
|
4294 | 4271 | if (!Impl.SwiftContext.SearchPathOpts.ScannerPrefixMapper.empty()) { |
4295 | 4272 | // Remap all the paths if requested. |
|
0 commit comments