@@ -189,6 +189,79 @@ swiftscan_diagnostic_set_t *mapCollectedDiagnosticsForOutput(
189
189
return diagnosticOutput;
190
190
}
191
191
192
+ // Generate an instance of the `swiftscan_dependency_graph_s` which contains no
193
+ // module dependnecies but captures the diagnostics emitted during the attempted
194
+ // scan query.
195
+ static swiftscan_dependency_graph_t generateHollowDiagnosticOutput (
196
+ const DependencyScanDiagnosticCollector &ScanDiagnosticConsumer) {
197
+ // Create a dependency graph instance
198
+ swiftscan_dependency_graph_t hollowResult = new swiftscan_dependency_graph_s;
199
+
200
+ // Populate the `modules` with a single info for the main module
201
+ // containing no dependencies
202
+ swiftscan_dependency_set_t *dependencySet = new swiftscan_dependency_set_t ;
203
+ dependencySet->count = 1 ;
204
+ dependencySet->modules = new swiftscan_dependency_info_t [1 ];
205
+ swiftscan_dependency_info_s *hollowMainModuleInfo =
206
+ new swiftscan_dependency_info_s;
207
+ dependencySet->modules [0 ] = hollowMainModuleInfo;
208
+ hollowResult->dependencies = dependencySet;
209
+
210
+ // Other main module details empty
211
+ hollowMainModuleInfo->direct_dependencies =
212
+ c_string_utils::create_empty_set ();
213
+ hollowMainModuleInfo->source_files = c_string_utils::create_empty_set ();
214
+ hollowMainModuleInfo->module_path = c_string_utils::create_null ();
215
+ hollowResult->main_module_name = c_string_utils::create_clone (" unknown" );
216
+ hollowMainModuleInfo->module_name =
217
+ c_string_utils::create_clone (" swiftTextual:unknown" );
218
+
219
+ // Hollow info details
220
+ swiftscan_module_details_s *hollowDetails = new swiftscan_module_details_s;
221
+ hollowDetails->kind = SWIFTSCAN_DEPENDENCY_INFO_SWIFT_TEXTUAL;
222
+ hollowDetails->swift_textual_details = {c_string_utils::create_null (),
223
+ c_string_utils::create_empty_set (),
224
+ c_string_utils::create_null (),
225
+ c_string_utils::create_empty_set (),
226
+ c_string_utils::create_empty_set (),
227
+ c_string_utils::create_empty_set (),
228
+ c_string_utils::create_empty_set (),
229
+ c_string_utils::create_empty_set (),
230
+ c_string_utils::create_empty_set (),
231
+ c_string_utils::create_null (),
232
+ false ,
233
+ false ,
234
+ c_string_utils::create_null (),
235
+ c_string_utils::create_null (),
236
+ c_string_utils::create_null ()};
237
+ hollowMainModuleInfo->details = hollowDetails;
238
+
239
+ // Empty Link Library set
240
+ swiftscan_link_library_set_t *hollowLinkLibrarySet =
241
+ new swiftscan_link_library_set_t ;
242
+ hollowLinkLibrarySet->count = 0 ;
243
+ hollowLinkLibrarySet->link_libraries = nullptr ;
244
+ hollowMainModuleInfo->link_libraries = hollowLinkLibrarySet;
245
+
246
+ // Populate the diagnostic info
247
+ hollowResult->diagnostics =
248
+ mapCollectedDiagnosticsForOutput (&ScanDiagnosticConsumer);
249
+ return hollowResult;
250
+ }
251
+
252
+ // Generate an instance of the `swiftscan_import_set_t` which contains no
253
+ // imports but captures the diagnostics emitted during the attempted
254
+ // scan query.
255
+ static swiftscan_import_set_t generateHollowDiagnosticOutputImportSet (
256
+ const DependencyScanDiagnosticCollector &ScanDiagnosticConsumer) {
257
+ // Create an dependency graph instance
258
+ swiftscan_import_set_t hollowResult = new swiftscan_import_set_s;
259
+ hollowResult->imports = c_string_utils::create_empty_set ();
260
+ hollowResult->diagnostics =
261
+ mapCollectedDiagnosticsForOutput (&ScanDiagnosticConsumer);
262
+ return hollowResult;
263
+ }
264
+
192
265
DependencyScanningTool::DependencyScanningTool ()
193
266
: ScanningService(std::make_unique<SwiftDependencyScanningService>()),
194
267
VersionedPCMInstanceCacheCache (
@@ -203,18 +276,13 @@ DependencyScanningTool::getDependencies(
203
276
// There may be errors as early as in instance initialization, so we must ensure
204
277
// we can catch those.
205
278
auto ScanDiagnosticConsumer = std::make_shared<DependencyScanDiagnosticCollector>();
206
- auto produceDiagnosticStateOnFailure = [&ScanDiagnosticConsumer]() {
207
- swiftscan_dependency_graph_t result = new swiftscan_dependency_graph_s;
208
- result->diagnostics = mapCollectedDiagnosticsForOutput (ScanDiagnosticConsumer.get ());
209
- return result;
210
- };
211
279
212
280
// The primary instance used to scan the query Swift source-code
213
281
auto QueryContextOrErr = initCompilerInstanceForScan (Command,
214
282
WorkingDirectory,
215
283
ScanDiagnosticConsumer);
216
284
if (QueryContextOrErr.getError ())
217
- return produceDiagnosticStateOnFailure ( );
285
+ return generateHollowDiagnosticOutput (*ScanDiagnosticConsumer );
218
286
219
287
auto QueryContext = std::move (*QueryContextOrErr);
220
288
@@ -228,9 +296,9 @@ DependencyScanningTool::getDependencies(
228
296
QueryContext.ScanDiagnostics .get (),
229
297
cache);
230
298
if (DependenciesOrErr.getError ())
231
- return produceDiagnosticStateOnFailure ( );
299
+ return generateHollowDiagnosticOutput (*ScanDiagnosticConsumer );
232
300
233
- return std::move (*DependenciesOrErr);;
301
+ return std::move (*DependenciesOrErr);
234
302
}
235
303
236
304
llvm::ErrorOr<swiftscan_import_set_t >
@@ -243,11 +311,9 @@ DependencyScanningTool::getImports(ArrayRef<const char *> Command,
243
311
auto QueryContextOrErr = initCompilerInstanceForScan (Command,
244
312
WorkingDirectory,
245
313
ScanDiagnosticConsumer);
246
- if (QueryContextOrErr.getError ()) {
247
- swiftscan_import_set_t result = new swiftscan_import_set_s;
248
- result->diagnostics = mapCollectedDiagnosticsForOutput (ScanDiagnosticConsumer.get ());
249
- return result;
250
- }
314
+ if (QueryContextOrErr.getError ())
315
+ return generateHollowDiagnosticOutputImportSet (*ScanDiagnosticConsumer);
316
+
251
317
auto QueryContext = std::move (*QueryContextOrErr);
252
318
253
319
// Local scan cache instance, wrapping the shared global cache.
@@ -259,10 +325,9 @@ DependencyScanningTool::getImports(ArrayRef<const char *> Command,
259
325
QueryContext.ScanDiagnostics .get (),
260
326
cache);
261
327
if (DependenciesOrErr.getError ())
262
- return std::make_error_code (std::errc::not_supported);
263
- auto Dependencies = std::move (*DependenciesOrErr);
328
+ return generateHollowDiagnosticOutputImportSet (*ScanDiagnosticConsumer);
264
329
265
- return Dependencies ;
330
+ return std::move (*DependenciesOrErr) ;
266
331
}
267
332
268
333
std::vector<llvm::ErrorOr<swiftscan_dependency_graph_t >>
0 commit comments