|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 |
|
13 | 13 | #include "swift/DependencyScan/ScanDependencies.h"
|
14 |
| -#include "swift/DependencyScan/DSString.h" |
15 | 14 | #include "swift/AST/ASTContext.h"
|
16 | 15 | #include "swift/AST/Decl.h"
|
17 | 16 | #include "swift/AST/DiagnosticEngine.h"
|
|
24 | 23 | #include "swift/Basic/LLVM.h"
|
25 | 24 | #include "swift/Basic/STLExtras.h"
|
26 | 25 | #include "swift/ClangImporter/ClangImporter.h"
|
| 26 | +#include "swift/DependencyScan/DSString.h" |
27 | 27 | #include "swift/Frontend/Frontend.h"
|
28 | 28 | #include "swift/Frontend/FrontendOptions.h"
|
29 | 29 | #include "swift/Frontend/ModuleInterfaceLoader.h"
|
@@ -472,14 +472,13 @@ getAsClangDependencyModule(const depscan_module_details_t *details) {
|
472 | 472 | return nullptr;
|
473 | 473 | }
|
474 | 474 |
|
475 |
| -static void |
476 |
| -writePrescanJSON(llvm::raw_ostream &out, |
477 |
| - const std::vector<std::string> &moduleDependencies) { |
| 475 | +static void writePrescanJSON(llvm::raw_ostream &out, |
| 476 | + const depscan_prescan_result_t *importSet) { |
478 | 477 | // Write out a JSON containing all main module imports.
|
479 | 478 | out << "{\n";
|
480 | 479 | SWIFT_DEFER { out << "}\n"; };
|
481 | 480 |
|
482 |
| - writeJSONSingleField(out, "imports", moduleDependencies, 0, false); |
| 481 | + writeJSONSingleField(out, "imports", importSet, 0, false); |
483 | 482 | }
|
484 | 483 |
|
485 | 484 | static void writeJSON(llvm::raw_ostream &out,
|
@@ -984,8 +983,7 @@ forEachBatchEntry(CompilerInstance &instance, ModuleDependenciesCache &cache,
|
984 | 983 | }
|
985 | 984 |
|
986 | 985 | static ModuleDependencies
|
987 |
| -identifyMainModuleDependencies(CompilerInstance &instance, |
988 |
| - ModuleDependenciesCache &cache) { |
| 986 | +identifyMainModuleDependencies(CompilerInstance &instance) { |
989 | 987 | ModuleDecl *mainModule = instance.getMainModule();
|
990 | 988 | // Main module file name.
|
991 | 989 | auto newExt = file_types::getExtension(file_types::TY_SwiftModuleFile);
|
@@ -1105,10 +1103,13 @@ bool swift::dependencies::prescanDependencies(CompilerInstance &instance) {
|
1105 | 1103 | }
|
1106 | 1104 |
|
1107 | 1105 | // Execute import prescan, and write JSON output to the output stream
|
1108 |
| - auto mainDependencies = identifyMainModuleDependencies(instance, cache); |
| 1106 | + auto importSetOrErr = performModulePrescan(instance); |
| 1107 | + if (importSetOrErr.getError()) |
| 1108 | + return true; |
| 1109 | + auto importSet = std::move(*importSetOrErr); |
1109 | 1110 |
|
1110 | 1111 | // Serialize and output main module dependencies only and exit.
|
1111 |
| - writePrescanJSON(out, mainDependencies.getModuleDependencies()); |
| 1112 | + writePrescanJSON(out, importSet); |
1112 | 1113 | // This process succeeds regardless of whether any errors occurred.
|
1113 | 1114 | // FIXME: We shouldn't need this, but it's masking bugs in our scanning
|
1114 | 1115 | // logic where we don't create a fresh context when scanning Swift interfaces
|
@@ -1186,7 +1187,7 @@ swift::dependencies::performModuleScan(CompilerInstance &instance,
|
1186 | 1187 | ModuleDecl *mainModule = instance.getMainModule();
|
1187 | 1188 |
|
1188 | 1189 | // First, identify the dependencies of the main module
|
1189 |
| - auto mainDependencies = identifyMainModuleDependencies(instance, cache); |
| 1190 | + auto mainDependencies = identifyMainModuleDependencies(instance); |
1190 | 1191 |
|
1191 | 1192 | // Add the main module.
|
1192 | 1193 | StringRef mainModuleName = mainModule->getNameStr();
|
@@ -1261,6 +1262,15 @@ swift::dependencies::performModuleScan(CompilerInstance &instance,
|
1261 | 1262 | return dependencyGraph;
|
1262 | 1263 | }
|
1263 | 1264 |
|
| 1265 | +llvm::ErrorOr<depscan_prescan_result_t *> |
| 1266 | +swift::dependencies::performModulePrescan(CompilerInstance &instance) { |
| 1267 | + // Execute import prescan, and write JSON output to the output stream |
| 1268 | + auto mainDependencies = identifyMainModuleDependencies(instance); |
| 1269 | + depscan_prescan_result_t *importSet = new depscan_prescan_result_t; |
| 1270 | + importSet->import_set = create_set(mainDependencies.getModuleDependencies()); |
| 1271 | + return importSet; |
| 1272 | +} |
| 1273 | + |
1264 | 1274 | std::vector<llvm::ErrorOr<depscan_dependency_result_t *>>
|
1265 | 1275 | swift::dependencies::performBatchModuleScan(
|
1266 | 1276 | CompilerInstance &instance, ModuleDependenciesCache &cache,
|
@@ -1330,11 +1340,11 @@ swift::dependencies::performBatchModuleScan(
|
1330 | 1340 | return batchScanResult;
|
1331 | 1341 | }
|
1332 | 1342 |
|
1333 |
| -std::vector<llvm::ErrorOr<std::vector<std::string>>> |
| 1343 | +std::vector<llvm::ErrorOr<depscan_prescan_result_t *>> |
1334 | 1344 | swift::dependencies::performBatchModulePrescan(
|
1335 | 1345 | CompilerInstance &instance, ModuleDependenciesCache &cache,
|
1336 | 1346 | llvm::StringSaver &saver, const std::vector<BatchScanInput> &batchInput) {
|
1337 |
| - std::vector<llvm::ErrorOr<std::vector<std::string>>> batchPrescanResult; |
| 1347 | + std::vector<llvm::ErrorOr<depscan_prescan_result_t *>> batchPrescanResult; |
1338 | 1348 |
|
1339 | 1349 | // Perform a full dependency scan for each batch entry module
|
1340 | 1350 | forEachBatchEntry(
|
@@ -1377,7 +1387,9 @@ swift::dependencies::performBatchModulePrescan(
|
1377 | 1387 | return;
|
1378 | 1388 | }
|
1379 | 1389 |
|
1380 |
| - batchPrescanResult.push_back(rootDeps->getModuleDependencies()); |
| 1390 | + depscan_prescan_result_t *importSet = new depscan_prescan_result_t; |
| 1391 | + importSet->import_set = create_set(rootDeps->getModuleDependencies()); |
| 1392 | + batchPrescanResult.push_back(importSet); |
1381 | 1393 | });
|
1382 | 1394 |
|
1383 | 1395 | return batchPrescanResult;
|
|
0 commit comments