@@ -189,6 +189,71 @@ swiftscan_diagnostic_set_t *mapCollectedDiagnosticsForOutput(
189189  return  diagnosticOutput;
190190}
191191
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+ 
192257DependencyScanningTool::DependencyScanningTool ()
193258    : ScanningService(std::make_unique<SwiftDependencyScanningService>()),
194259      VersionedPCMInstanceCacheCache (
@@ -203,18 +268,13 @@ DependencyScanningTool::getDependencies(
203268  //  There may be errors as early as in instance initialization, so we must ensure
204269  //  we can catch those.
205270  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-   };
211271
212272  //  The primary instance used to scan the query Swift source-code
213273  auto  QueryContextOrErr = initCompilerInstanceForScan (Command,
214274                                                       WorkingDirectory,
215275                                                       ScanDiagnosticConsumer);
216276  if  (QueryContextOrErr.getError ())
217-     return  produceDiagnosticStateOnFailure ( );
277+     return  generateHollowDiagnosticOutput (*ScanDiagnosticConsumer );
218278
219279  auto  QueryContext = std::move (*QueryContextOrErr);
220280
@@ -228,9 +288,9 @@ DependencyScanningTool::getDependencies(
228288                                             QueryContext.ScanDiagnostics .get (),
229289                                             cache);
230290  if  (DependenciesOrErr.getError ())
231-     return  produceDiagnosticStateOnFailure ( );
291+     return  generateHollowDiagnosticOutput (*ScanDiagnosticConsumer );
232292
233-   return  std::move (*DependenciesOrErr);; 
293+   return  std::move (*DependenciesOrErr);
234294}
235295
236296llvm::ErrorOr<swiftscan_import_set_t >
@@ -243,11 +303,9 @@ DependencyScanningTool::getImports(ArrayRef<const char *> Command,
243303  auto  QueryContextOrErr = initCompilerInstanceForScan (Command,
244304                                                       WorkingDirectory,
245305                                                       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+ 
251309  auto  QueryContext = std::move (*QueryContextOrErr);
252310
253311  //  Local scan cache instance, wrapping the shared global cache.
@@ -259,10 +317,9 @@ DependencyScanningTool::getImports(ArrayRef<const char *> Command,
259317                                                QueryContext.ScanDiagnostics .get (),
260318                                                cache);
261319  if  (DependenciesOrErr.getError ())
262-     return  std::make_error_code (std::errc::not_supported);
263-   auto  Dependencies = std::move (*DependenciesOrErr);
320+     return  generateHollowDiagnosticOutputImportSet (*ScanDiagnosticConsumer);
264321
265-   return  Dependencies ;
322+   return  std::move (*DependenciesOrErr) ;
266323}
267324
268325std::vector<llvm::ErrorOr<swiftscan_dependency_graph_t >>
0 commit comments