@@ -82,124 +82,117 @@ std::vector<std::string> ClangImporter::getClangDepScanningInvocationArguments(
82
82
return commandLineArgs;
83
83
}
84
84
85
- ModuleDependencyVector ClangImporter::bridgeClangModuleDependencies (
85
+ ModuleDependencyInfo
86
+ ClangImporter::bridgeClangModuleDependency (
86
87
const ASTContext &ctx,
87
- clang::tooling::dependencies::DependencyScanningTool &clangScanningTool,
88
- clang::tooling::dependencies::ModuleDepsGraph &clangDependencies,
89
- LookupModuleOutputCallback lookupModuleOutput,
90
- RemapPathCallback callback) {
91
- ModuleDependencyVector result;
92
-
88
+ const clang::tooling::dependencies::ModuleDeps &clangModuleDep,
89
+ LookupModuleOutputCallback lookupModuleOutput, RemapPathCallback callback) {
93
90
auto remapPath = [&](StringRef path) {
94
91
if (callback)
95
92
return callback (path);
96
93
return path.str ();
97
94
};
98
95
99
- for (auto &clangModuleDep : clangDependencies) {
100
- // File dependencies for this module.
101
- std::vector<std::string> fileDeps;
102
- clangModuleDep.forEachFileDep (
103
- [&fileDeps](StringRef fileDep) { fileDeps.emplace_back (fileDep); });
104
-
105
- std::vector<std::string> swiftArgs;
106
- auto addClangArg = [&](Twine arg) {
107
- swiftArgs.push_back (" -Xcc" );
108
- swiftArgs.push_back (arg.str ());
109
- };
110
-
111
- // We are using Swift frontend mode.
112
- swiftArgs.push_back (" -frontend" );
113
-
114
- // Swift frontend action: -emit-pcm
115
- swiftArgs.push_back (" -emit-pcm" );
116
- swiftArgs.push_back (" -module-name" );
117
- swiftArgs.push_back (clangModuleDep.ID .ModuleName );
118
-
119
- auto pcmPath = lookupModuleOutput (clangModuleDep,
120
- ModuleOutputKind::ModuleFile);
121
- swiftArgs.push_back (" -o" );
122
- swiftArgs.push_back (pcmPath);
123
-
124
- // Ensure that the resulting PCM build invocation uses Clang frontend
125
- // directly
126
- swiftArgs.push_back (" -direct-clang-cc1-module-build" );
127
-
128
- // Swift frontend option for input file path (Foo.modulemap).
129
- swiftArgs.push_back (remapPath (clangModuleDep.ClangModuleMapFile ));
130
-
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 ();
136
-
137
- // Reset CASOptions since that should be coming from swift.
138
- invocation.getMutCASOpts () = clang::CASOptions ();
139
- invocation.getMutFrontendOpts ().CASIncludeTreeID .clear ();
140
-
141
- // FIXME: workaround for rdar://105684525: find the -ivfsoverlay option
142
- // from clang scanner and pass to swift.
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
- }
96
+ // File dependencies for this module.
97
+ std::vector<std::string> fileDeps;
98
+ clangModuleDep.forEachFileDep (
99
+ [&fileDeps](StringRef fileDep) { fileDeps.emplace_back (fileDep); });
150
100
151
- // Add args reported by the scanner.
152
- auto clangArgs = invocation.getCC1CommandLine ();
153
- llvm::for_each (clangArgs, addClangArg);
101
+ std::vector<std::string> swiftArgs;
102
+ auto addClangArg = [&](Twine arg) {
103
+ swiftArgs.push_back (" -Xcc" );
104
+ swiftArgs.push_back (arg.str ());
105
+ };
154
106
155
- // CASFileSystemRootID.
156
- std::string RootID = clangModuleDep.CASFileSystemRootID
157
- ? clangModuleDep.CASFileSystemRootID ->toString ()
158
- : " " ;
107
+ // We are using Swift frontend mode.
108
+ swiftArgs.push_back (" -frontend" );
159
109
160
- std::string IncludeTree =
161
- clangModuleDep.IncludeTreeID ? *clangModuleDep.IncludeTreeID : " " ;
110
+ // Swift frontend action: -emit-pcm
111
+ swiftArgs.push_back (" -emit-pcm" );
112
+ swiftArgs.push_back (" -module-name" );
113
+ swiftArgs.push_back (clangModuleDep.ID .ModuleName );
162
114
163
- ctx.CASOpts .enumerateCASConfigurationFlags (
164
- [&](StringRef Arg) { swiftArgs.push_back (Arg.str ()); });
115
+ auto pcmPath =
116
+ lookupModuleOutput (clangModuleDep, ModuleOutputKind::ModuleFile);
117
+ swiftArgs.push_back (" -o" );
118
+ swiftArgs.push_back (pcmPath);
165
119
166
- if (!IncludeTree.empty ()) {
167
- swiftArgs.push_back (" -clang-include-tree-root" );
168
- swiftArgs.push_back (IncludeTree);
169
- }
170
- std::string mappedPCMPath = remapPath (pcmPath);
171
-
172
- std::vector<LinkLibrary> LinkLibraries;
173
- for (const auto &ll : clangModuleDep.LinkLibraries )
174
- LinkLibraries.emplace_back (
175
- ll.Library ,
176
- ll.IsFramework ? LibraryKind::Framework : LibraryKind::Library,
177
- /* static=*/ false );
178
-
179
- // Module-level dependencies.
180
- llvm::StringSet<> alreadyAddedModules;
181
- auto dependencies = ModuleDependencyInfo::forClangModule (
182
- pcmPath, mappedPCMPath, clangModuleDep.ClangModuleMapFile ,
183
- clangModuleDep.ID .ContextHash , swiftArgs, fileDeps,
184
- LinkLibraries, RootID, IncludeTree, /* module-cache-key*/ " " ,
185
- clangModuleDep.IsSystem );
186
-
187
- std::vector<ModuleDependencyID> directDependencyIDs;
188
- for (const auto &moduleName : clangModuleDep.ClangModuleDeps ) {
189
- // FIXME: This assumes, conservatively, that all Clang module imports
190
- // are exported. We need to fix this once the clang scanner gains the appropriate
191
- // API to query this.
192
- dependencies.addModuleImport (moduleName.ModuleName , /* isExported */ true ,
193
- AccessLevel::Public, &alreadyAddedModules);
194
- // It is safe to assume that all dependencies of a Clang module are Clang modules.
195
- directDependencyIDs.push_back ({moduleName.ModuleName , ModuleDependencyKind::Clang});
120
+ // Ensure that the resulting PCM build invocation uses Clang frontend
121
+ // directly
122
+ swiftArgs.push_back (" -direct-clang-cc1-module-build" );
123
+
124
+ // Swift frontend option for input file path (Foo.modulemap).
125
+ swiftArgs.push_back (remapPath (clangModuleDep.ClangModuleMapFile ));
126
+
127
+ auto invocation = clangModuleDep.getUnderlyingCompilerInvocation ();
128
+ // Clear some options from clang scanner.
129
+ invocation.getMutFrontendOpts ().ModuleCacheKeys .clear ();
130
+ invocation.getMutFrontendOpts ().PathPrefixMappings .clear ();
131
+ invocation.getMutFrontendOpts ().OutputFile .clear ();
132
+
133
+ // Reset CASOptions since that should be coming from swift.
134
+ invocation.getMutCASOpts () = clang::CASOptions ();
135
+ invocation.getMutFrontendOpts ().CASIncludeTreeID .clear ();
136
+
137
+ // FIXME: workaround for rdar://105684525: find the -ivfsoverlay option
138
+ // from clang scanner and pass to swift.
139
+ if (!ctx.CASOpts .EnableCaching ) {
140
+ auto &overlayFiles = invocation.getMutHeaderSearchOpts ().VFSOverlayFiles ;
141
+ for (auto overlay : overlayFiles) {
142
+ swiftArgs.push_back (" -vfsoverlay" );
143
+ swiftArgs.push_back (overlay);
196
144
}
197
- dependencies.setImportedClangDependencies (directDependencyIDs);
198
- result.push_back (std::make_pair (ModuleDependencyID{clangModuleDep.ID .ModuleName ,
199
- ModuleDependencyKind::Clang},
200
- dependencies));
201
145
}
202
- return result;
146
+
147
+ // Add args reported by the scanner.
148
+ auto clangArgs = invocation.getCC1CommandLine ();
149
+ llvm::for_each (clangArgs, addClangArg);
150
+
151
+ // CASFileSystemRootID.
152
+ std::string RootID = clangModuleDep.CASFileSystemRootID
153
+ ? clangModuleDep.CASFileSystemRootID ->toString ()
154
+ : " " ;
155
+
156
+ std::string IncludeTree =
157
+ clangModuleDep.IncludeTreeID ? *clangModuleDep.IncludeTreeID : " " ;
158
+
159
+ ctx.CASOpts .enumerateCASConfigurationFlags (
160
+ [&](StringRef Arg) { swiftArgs.push_back (Arg.str ()); });
161
+
162
+ if (!IncludeTree.empty ()) {
163
+ swiftArgs.push_back (" -clang-include-tree-root" );
164
+ swiftArgs.push_back (IncludeTree);
165
+ }
166
+ std::string mappedPCMPath = remapPath (pcmPath);
167
+
168
+ std::vector<LinkLibrary> LinkLibraries;
169
+ for (const auto &ll : clangModuleDep.LinkLibraries )
170
+ LinkLibraries.emplace_back (ll.Library ,
171
+ ll.IsFramework ? LibraryKind::Framework
172
+ : LibraryKind::Library,
173
+ /* static=*/ false );
174
+
175
+ // Module-level dependencies.
176
+ llvm::StringSet<> alreadyAddedModules;
177
+ auto bridgedDependencyInfo = ModuleDependencyInfo::forClangModule (
178
+ pcmPath, mappedPCMPath, clangModuleDep.ClangModuleMapFile ,
179
+ clangModuleDep.ID .ContextHash , swiftArgs, fileDeps, LinkLibraries, RootID,
180
+ IncludeTree, /* module-cache-key*/ " " , clangModuleDep.IsSystem );
181
+
182
+ std::vector<ModuleDependencyID> directDependencyIDs;
183
+ for (const auto &moduleName : clangModuleDep.ClangModuleDeps ) {
184
+ // FIXME: This assumes, conservatively, that all Clang module imports
185
+ // are exported. We need to fix this once the clang scanner gains the
186
+ // appropriate API to query this.
187
+ bridgedDependencyInfo.addModuleImport (moduleName.ModuleName , /* isExported */ true ,
188
+ AccessLevel::Public, &alreadyAddedModules);
189
+ // It is safe to assume that all dependencies of a Clang module are Clang
190
+ // modules.
191
+ directDependencyIDs.push_back (
192
+ {moduleName.ModuleName , ModuleDependencyKind::Clang});
193
+ }
194
+ bridgedDependencyInfo.setImportedClangDependencies (directDependencyIDs);
195
+ return bridgedDependencyInfo;
203
196
}
204
197
205
198
void ClangImporter::getBridgingHeaderOptions (
0 commit comments