@@ -189,6 +189,83 @@ 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+ swiftscan_macro_dependency_set_t *hollowMacroSet = new swiftscan_macro_dependency_set_t ;
223+ hollowMacroSet->count = 0 ;
224+ hollowMacroSet->macro_dependencies = nullptr ;
225+ hollowDetails->swift_textual_details = {c_string_utils::create_null (),
226+ c_string_utils::create_empty_set (),
227+ c_string_utils::create_null (),
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_empty_set (),
232+ c_string_utils::create_empty_set (),
233+ c_string_utils::create_empty_set (),
234+ c_string_utils::create_null (),
235+ false ,
236+ false ,
237+ c_string_utils::create_null (),
238+ c_string_utils::create_null (),
239+ c_string_utils::create_null (),
240+ hollowMacroSet};
241+ hollowMainModuleInfo->details = hollowDetails;
242+
243+ // Empty Link Library set
244+ swiftscan_link_library_set_t *hollowLinkLibrarySet =
245+ new swiftscan_link_library_set_t ;
246+ hollowLinkLibrarySet->count = 0 ;
247+ hollowLinkLibrarySet->link_libraries = nullptr ;
248+ hollowMainModuleInfo->link_libraries = hollowLinkLibrarySet;
249+
250+ // Populate the diagnostic info
251+ hollowResult->diagnostics =
252+ mapCollectedDiagnosticsForOutput (&ScanDiagnosticConsumer);
253+ return hollowResult;
254+ }
255+
256+ // Generate an instance of the `swiftscan_import_set_t` which contains no
257+ // imports but captures the diagnostics emitted during the attempted
258+ // scan query.
259+ static swiftscan_import_set_t generateHollowDiagnosticOutputImportSet (
260+ const DependencyScanDiagnosticCollector &ScanDiagnosticConsumer) {
261+ // Create an dependency graph instance
262+ swiftscan_import_set_t hollowResult = new swiftscan_import_set_s;
263+ hollowResult->imports = c_string_utils::create_empty_set ();
264+ hollowResult->diagnostics =
265+ mapCollectedDiagnosticsForOutput (&ScanDiagnosticConsumer);
266+ return hollowResult;
267+ }
268+
192269DependencyScanningTool::DependencyScanningTool ()
193270 : ScanningService(std::make_unique<SwiftDependencyScanningService>()),
194271 VersionedPCMInstanceCacheCache (
@@ -203,18 +280,13 @@ DependencyScanningTool::getDependencies(
203280 // There may be errors as early as in instance initialization, so we must ensure
204281 // we can catch those.
205282 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- };
211283
212284 // The primary instance used to scan the query Swift source-code
213285 auto QueryContextOrErr = initCompilerInstanceForScan (Command,
214286 WorkingDirectory,
215287 ScanDiagnosticConsumer);
216288 if (QueryContextOrErr.getError ())
217- return produceDiagnosticStateOnFailure ( );
289+ return generateHollowDiagnosticOutput (*ScanDiagnosticConsumer );
218290
219291 auto QueryContext = std::move (*QueryContextOrErr);
220292
@@ -228,9 +300,9 @@ DependencyScanningTool::getDependencies(
228300 QueryContext.ScanDiagnostics .get (),
229301 cache);
230302 if (DependenciesOrErr.getError ())
231- return produceDiagnosticStateOnFailure ( );
303+ return generateHollowDiagnosticOutput (*ScanDiagnosticConsumer );
232304
233- return std::move (*DependenciesOrErr);;
305+ return std::move (*DependenciesOrErr);
234306}
235307
236308llvm::ErrorOr<swiftscan_import_set_t >
@@ -243,11 +315,9 @@ DependencyScanningTool::getImports(ArrayRef<const char *> Command,
243315 auto QueryContextOrErr = initCompilerInstanceForScan (Command,
244316 WorkingDirectory,
245317 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- }
318+ if (QueryContextOrErr.getError ())
319+ return generateHollowDiagnosticOutputImportSet (*ScanDiagnosticConsumer);
320+
251321 auto QueryContext = std::move (*QueryContextOrErr);
252322
253323 // Local scan cache instance, wrapping the shared global cache.
@@ -259,10 +329,9 @@ DependencyScanningTool::getImports(ArrayRef<const char *> Command,
259329 QueryContext.ScanDiagnostics .get (),
260330 cache);
261331 if (DependenciesOrErr.getError ())
262- return std::make_error_code (std::errc::not_supported);
263- auto Dependencies = std::move (*DependenciesOrErr);
332+ return generateHollowDiagnosticOutputImportSet (*ScanDiagnosticConsumer);
264333
265- return Dependencies ;
334+ return std::move (*DependenciesOrErr) ;
266335}
267336
268337std::vector<llvm::ErrorOr<swiftscan_dependency_graph_t >>
0 commit comments