Skip to content

Commit d5449bf

Browse files
committed
[Dependency Scanner] Add import-prescan handling to batch scanning
1 parent e0dbba5 commit d5449bf

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

lib/FrontendTool/ScanDependencies.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,8 @@ static bool scanModuleDependencies(CompilerInstance &instance,
659659
FEOpts.PrebuiltModuleCachePath,
660660
FEOpts.SerializeModuleInterfaceDependencyHashes,
661661
FEOpts.shouldTrackSystemDependencies());
662+
std::error_code EC;
663+
llvm::raw_fd_ostream out(outputPath, EC, llvm::sys::fs::F_None);
662664
Optional<ModuleDependencies> rootDeps;
663665
if (isClang) {
664666
// Loading the clang module using Clang importer.
@@ -677,6 +679,12 @@ static bool scanModuleDependencies(CompilerInstance &instance,
677679
allModules.insert({moduleName.str(), isClang ? ModuleDependenciesKind::Clang:
678680
ModuleDependenciesKind::Swift});
679681

682+
// Output module prescan.
683+
if (FEOpts.ImportPrescan) {
684+
writePrescanJSON(out, rootDeps.getValue());
685+
return false;
686+
}
687+
680688
// Explore the dependencies of every module.
681689
for (unsigned currentModuleIdx = 0;
682690
currentModuleIdx < allModules.size();
@@ -687,8 +695,6 @@ static bool scanModuleDependencies(CompilerInstance &instance,
687695
allModules.insert(discoveredModules.begin(), discoveredModules.end());
688696
}
689697
// Write out the JSON description.
690-
std::error_code EC;
691-
llvm::raw_fd_ostream out(outputPath, EC, llvm::sys::fs::F_None);
692698
writeJSON(out, instance, cache, ASTDelegate, allModules.getArrayRef());
693699
return false;
694700
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t/inputs)
3+
// RUN: %empty-directory(%t/outputs)
4+
// RUN: mkdir -p %t/clang-module-cache
5+
6+
// RUN: echo "[{" > %/t/inputs/input.json
7+
// RUN: echo "\"swiftModuleName\": \"F\"," >> %/t/inputs/input.json
8+
// RUN: echo "\"arguments\": \"-target x86_64-apple-macosx10.9\"," >> %/t/inputs/input.json
9+
// RUN: echo "\"output\": \"%/t/outputs/F.swiftmodule.json\"" >> %/t/inputs/input.json
10+
// RUN: echo "}]" >> %/t/inputs/input.json
11+
12+
// RUN: %target-swift-frontend -scan-dependencies -import-prescan -module-cache-path %t/clang-module-cache %s -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -emit-dependencies -emit-dependencies-path %t/deps.d -import-objc-header %S/Inputs/CHeaders/Bridging.h -swift-version 4 -batch-scan-input-file %/t/inputs/input.json
13+
14+
// Check the contents of the JSON output
15+
// RUN: %FileCheck %s -check-prefix=CHECK-SWIFT < %t/outputs/F.swiftmodule.json
16+
17+
// CHECK-SWIFT: {
18+
// CHECK-SWIFT-NEXT:"imports": [
19+
// CHECK-SWIFT-NEXT: "Swift",
20+
// CHECK-SWIFT-NEXT: "F",
21+
// CHECK-SWIFT-NEXT: "SwiftOnoneSupport"
22+
// CHECK-SWIFT-NEXT:]

0 commit comments

Comments
 (0)