@@ -81,25 +81,6 @@ std::vector<std::string> ClangImporter::getClangDepScanningInvocationArguments(
8181 return commandLineArgs;
8282}
8383
84- static std::unique_ptr<llvm::PrefixMapper>
85- getClangPrefixMapper (DependencyScanningTool &clangScanningTool,
86- ModuleDeps &clangModuleDep,
87- clang::CompilerInvocation &depsInvocation) {
88- std::unique_ptr<llvm::PrefixMapper> Mapper;
89- if (clangModuleDep.IncludeTreeID ) {
90- Mapper = std::make_unique<llvm::PrefixMapper>();
91- } else if (clangModuleDep.CASFileSystemRootID ) {
92- assert (clangScanningTool.getCachingFileSystem ());
93- Mapper = std::make_unique<llvm::TreePathPrefixMapper>(
94- clangScanningTool.getCachingFileSystem ());
95- }
96-
97- if (Mapper)
98- DepscanPrefixMapping::configurePrefixMapper (depsInvocation, *Mapper);
99-
100- return Mapper;
101- }
102-
10384ModuleDependencyVector ClangImporter::bridgeClangModuleDependencies (
10485 const ASTContext &ctx,
10586 clang::tooling::dependencies::DependencyScanningTool &clangScanningTool,
@@ -147,63 +128,30 @@ ModuleDependencyVector ClangImporter::bridgeClangModuleDependencies(
147128 // Swift frontend option for input file path (Foo.modulemap).
148129 swiftArgs.push_back (remapPath (clangModuleDep.ClangModuleMapFile ));
149130
150- // Handle VFSOverlay. If caching is enabled, there is no need for overlay.
151- if (!ctx.CASOpts .EnableCaching ) {
152- for (auto &overlay : ctx.SearchPathOpts .VFSOverlayFiles ) {
153- swiftArgs.push_back (" -vfsoverlay" );
154- swiftArgs.push_back (remapPath (overlay));
155- }
156- }
157-
158- // Add args reported by the scanner.
159-
160- // Round-trip clang args to canonicalize and clear the options that swift
161- // compiler doesn't need.
162- clang::CompilerInvocation depsInvocation;
163- clang::DiagnosticsEngine clangDiags (new clang::DiagnosticIDs (),
164- new clang::DiagnosticOptions (),
165- new clang::IgnoringDiagConsumer ());
166-
167- llvm::SmallVector<const char *> clangArgs;
168- llvm::for_each (
169- clangModuleDep.getBuildArguments (),
170- [&](const std::string &Arg) { clangArgs.push_back (Arg.c_str ()); });
171-
172- bool success = clang::CompilerInvocation::CreateFromArgs (
173- depsInvocation, clangArgs, clangDiags);
174- (void )success;
175- assert (success && " clang option from dep scanner round trip failed" );
176-
177- // Create a prefix mapper that matches clang's configuration.
178- auto Mapper =
179- getClangPrefixMapper (clangScanningTool, clangModuleDep, depsInvocation);
180-
181- // Clear the cache key for module. The module key is computed from clang
182- // invocation, not swift invocation.
183- depsInvocation.getFrontendOpts ().ModuleCacheKeys .clear ();
184- depsInvocation.getFrontendOpts ().PathPrefixMappings .clear ();
185- depsInvocation.getFrontendOpts ().OutputFile .clear ();
131+ auto invocation = clangModuleDep.getUnderlyingCompilerInvocation ();
132+ // Clear some options from clang scanner.
133+ invocation.getMutFrontendOpts ().ModuleCacheKeys .clear ();
134+ invocation.getMutFrontendOpts ().PathPrefixMappings .clear ();
135+ invocation.getMutFrontendOpts ().OutputFile .clear ();
186136
187137 // Reset CASOptions since that should be coming from swift.
188- depsInvocation. getCASOpts () = clang::CASOptions ();
189- depsInvocation. getFrontendOpts ().CASIncludeTreeID .clear ();
138+ invocation. getMutCASOpts () = clang::CASOptions ();
139+ invocation. getMutFrontendOpts ().CASIncludeTreeID .clear ();
190140
191141 // FIXME: workaround for rdar://105684525: find the -ivfsoverlay option
192142 // from clang scanner and pass to swift.
193- for (auto overlay : depsInvocation.getHeaderSearchOpts ().VFSOverlayFiles ) {
194- if (llvm::is_contained (ctx.SearchPathOpts .VFSOverlayFiles , overlay))
195- continue ;
196- swiftArgs.push_back (" -vfsoverlay" );
197- swiftArgs.push_back (overlay);
143+ if (!ctx.CASOpts .EnableCaching ) {
144+ auto &overlayFiles = invocation.getMutHeaderSearchOpts ().VFSOverlayFiles ;
145+ for (auto overlay : overlayFiles) {
146+ swiftArgs.push_back (" -vfsoverlay" );
147+ swiftArgs.push_back (overlay);
148+ }
149+ // Clear overlay files since they are forwarded from swift to clang.
150+ overlayFiles.clear ();
198151 }
199152
200- llvm::BumpPtrAllocator allocator;
201- llvm::StringSaver saver (allocator);
202- clangArgs.clear ();
203- depsInvocation.generateCC1CommandLine (
204- clangArgs,
205- [&saver](const llvm::Twine &T) { return saver.save (T).data (); });
206-
153+ // Add args reported by the scanner.
154+ auto clangArgs = invocation.getCC1CommandLine ();
207155 llvm::for_each (clangArgs, addClangArg);
208156
209157 // CASFileSystemRootID.
@@ -221,10 +169,7 @@ ModuleDependencyVector ClangImporter::bridgeClangModuleDependencies(
221169 swiftArgs.push_back (" -clang-include-tree-root" );
222170 swiftArgs.push_back (IncludeTree);
223171 }
224-
225- std::string mappedPCMPath = pcmPath;
226- if (Mapper)
227- Mapper->mapInPlace (mappedPCMPath);
172+ std::string mappedPCMPath = remapPath (pcmPath);
228173
229174 std::vector<LinkLibrary> LinkLibraries;
230175 for (const auto &ll : clangModuleDep.LinkLibraries )
0 commit comments