@@ -189,6 +189,71 @@ 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
+ c_string_utils::create_null (),
234
+ c_string_utils::create_null (),
235
+ c_string_utils::create_null ()};
236
+ hollowMainModuleInfo->details = hollowDetails;
237
+
238
+ // Populate the diagnostic info
239
+ hollowResult->diagnostics =
240
+ mapCollectedDiagnosticsForOutput (&ScanDiagnosticConsumer);
241
+ return hollowResult;
242
+ }
243
+
244
+ // Generate an instance of the `swiftscan_import_set_t` which contains no
245
+ // imports but captures the diagnostics emitted during the attempted
246
+ // scan query.
247
+ static swiftscan_import_set_t generateHollowDiagnosticOutputImportSet (
248
+ const DependencyScanDiagnosticCollector &ScanDiagnosticConsumer) {
249
+ // Create an dependency graph instance
250
+ swiftscan_import_set_t hollowResult = new swiftscan_import_set_s;
251
+ hollowResult->imports = c_string_utils::create_empty_set ();
252
+ hollowResult->diagnostics =
253
+ mapCollectedDiagnosticsForOutput (&ScanDiagnosticConsumer);
254
+ return hollowResult;
255
+ }
256
+
192
257
DependencyScanningTool::DependencyScanningTool ()
193
258
: ScanningService(std::make_unique<SwiftDependencyScanningService>()),
194
259
VersionedPCMInstanceCacheCache (
@@ -203,18 +268,13 @@ DependencyScanningTool::getDependencies(
203
268
// There may be errors as early as in instance initialization, so we must ensure
204
269
// we can catch those.
205
270
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
271
212
272
// The primary instance used to scan the query Swift source-code
213
273
auto QueryContextOrErr = initCompilerInstanceForScan (Command,
214
274
WorkingDirectory,
215
275
ScanDiagnosticConsumer);
216
276
if (QueryContextOrErr.getError ())
217
- return produceDiagnosticStateOnFailure ( );
277
+ return generateHollowDiagnosticOutput (*ScanDiagnosticConsumer );
218
278
219
279
auto QueryContext = std::move (*QueryContextOrErr);
220
280
@@ -228,9 +288,9 @@ DependencyScanningTool::getDependencies(
228
288
QueryContext.ScanDiagnostics .get (),
229
289
cache);
230
290
if (DependenciesOrErr.getError ())
231
- return produceDiagnosticStateOnFailure ( );
291
+ return generateHollowDiagnosticOutput (*ScanDiagnosticConsumer );
232
292
233
- return std::move (*DependenciesOrErr);;
293
+ return std::move (*DependenciesOrErr);
234
294
}
235
295
236
296
llvm::ErrorOr<swiftscan_import_set_t >
@@ -243,11 +303,9 @@ DependencyScanningTool::getImports(ArrayRef<const char *> Command,
243
303
auto QueryContextOrErr = initCompilerInstanceForScan (Command,
244
304
WorkingDirectory,
245
305
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
- }
306
+ if (QueryContextOrErr.getError ())
307
+ return generateHollowDiagnosticOutputImportSet (*ScanDiagnosticConsumer);
308
+
251
309
auto QueryContext = std::move (*QueryContextOrErr);
252
310
253
311
// Local scan cache instance, wrapping the shared global cache.
@@ -259,10 +317,9 @@ DependencyScanningTool::getImports(ArrayRef<const char *> Command,
259
317
QueryContext.ScanDiagnostics .get (),
260
318
cache);
261
319
if (DependenciesOrErr.getError ())
262
- return std::make_error_code (std::errc::not_supported);
263
- auto Dependencies = std::move (*DependenciesOrErr);
320
+ return generateHollowDiagnosticOutputImportSet (*ScanDiagnosticConsumer);
264
321
265
- return Dependencies ;
322
+ return std::move (*DependenciesOrErr) ;
266
323
}
267
324
268
325
std::vector<llvm::ErrorOr<swiftscan_dependency_graph_t >>
0 commit comments