@@ -81,25 +81,6 @@ std::vector<std::string> ClangImporter::getClangDepScanningInvocationArguments(
81
81
return commandLineArgs;
82
82
}
83
83
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
-
103
84
ModuleDependencyVector ClangImporter::bridgeClangModuleDependencies (
104
85
const ASTContext &ctx,
105
86
clang::tooling::dependencies::DependencyScanningTool &clangScanningTool,
@@ -147,63 +128,30 @@ ModuleDependencyVector ClangImporter::bridgeClangModuleDependencies(
147
128
// Swift frontend option for input file path (Foo.modulemap).
148
129
swiftArgs.push_back (remapPath (clangModuleDep.ClangModuleMapFile ));
149
130
150
- // Handle VFSOverlay. If include tree is used, there is no need for overlay.
151
- if (!ctx.ClangImporterOpts .UseClangIncludeTree ) {
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 ();
186
136
187
137
// 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 ();
190
140
191
141
// FIXME: workaround for rdar://105684525: find the -ivfsoverlay option
192
142
// 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.ClangImporterOpts .UseClangIncludeTree ) {
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 ();
198
151
}
199
152
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 = clangModuleDep.getBuildArguments ();
207
155
llvm::for_each (clangArgs, addClangArg);
208
156
209
157
// CASFileSystemRootID.
@@ -227,10 +175,7 @@ ModuleDependencyVector ClangImporter::bridgeClangModuleDependencies(
227
175
swiftArgs.push_back (" -clang-include-tree-root" );
228
176
swiftArgs.push_back (IncludeTree);
229
177
}
230
-
231
- std::string mappedPCMPath = pcmPath;
232
- if (Mapper)
233
- Mapper->mapInPlace (mappedPCMPath);
178
+ std::string mappedPCMPath = remapPath (pcmPath);
234
179
235
180
std::vector<LinkLibrary> LinkLibraries;
236
181
for (const auto &ll : clangModuleDep.LinkLibraries )
0 commit comments