Skip to content

Commit dad1435

Browse files
committed
[Dependency Scanning] Factor out import prescan into separate utility
1 parent aabcb22 commit dad1435

File tree

4 files changed

+336
-305
lines changed

4 files changed

+336
-305
lines changed

include/swift/DependencyScan/ScanDependencies.h

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,41 +28,46 @@ class ModuleDependenciesCache;
2828
namespace dependencies {
2929

3030
struct BatchScanInput {
31-
StringRef moduleName;
32-
StringRef arguments;
33-
StringRef outputPath;
31+
llvm::StringRef moduleName;
32+
llvm::StringRef arguments;
33+
llvm::StringRef outputPath;
3434
bool isSwift;
3535
};
3636

37+
// MARK: swift-frontend -scan-dependencies entry points
3738
/// Scans the dependencies of the main module of \c instance and writes out
3839
/// the resulting JSON according to the instance's output parameters.
3940
/// This method is used for swift-frontend invocations in dependency scanning mode
4041
/// (-scan-dependencies), where the module dependency cache is not shared.
41-
bool scanAndOutputDependencies(CompilerInstance &instance);
42-
43-
/// Scans the dependencies of the main module of \c instance.
44-
bool scanDependencies(CompilerInstance &instance,
45-
ModuleDependenciesCache &cache,
46-
llvm::raw_ostream &out);
42+
bool scanDependencies(CompilerInstance &instance);
4743

4844
/// Batch scan the dependencies for modules specified in \c batchInputFile.
4945
bool batchScanDependencies(CompilerInstance &instance,
50-
llvm::StringRef batchInputFile);
46+
llvm::StringRef batchInputFile);
47+
48+
/// Identify all imports in the translation unit's module.
49+
bool prescanMainModuleDependencies(CompilerInstance &instance);
5150

5251

52+
// MARK: dependency scanning execution
53+
/// Scans the dependencies of the main module of \c instance.
54+
bool performModuleScan(CompilerInstance &instance,
55+
ModuleDependenciesCache &cache,
56+
llvm::raw_ostream &out);
57+
5358
/// Batch scan the dependencies for modules specified in \c batchInputFile.
54-
bool executeBatchModuleScan(CompilerInstance &instance,
59+
bool performBatchModuleScan(CompilerInstance &instance,
5560
ModuleDependenciesCache &cache,
5661
llvm::StringSaver &saver,
5762
const std::vector<BatchScanInput> &BatchInput);
5863

5964
/// Scan for dependencies of a module with a specified name, producing the resulting output
6065
/// at the specified output path.
61-
bool executeSingleModuleScan(CompilerInstance &instance,
62-
ModuleDependenciesCache &cache,
63-
StringRef moduleName,
64-
bool isClang,
65-
StringRef outputPath);
66+
bool scanBatchModuleEntry(CompilerInstance &instance,
67+
ModuleDependenciesCache &cache,
68+
llvm::StringRef moduleName,
69+
bool isClang,
70+
llvm::StringRef outputPath);
6671

6772
} // end namespace dependencies
6873
} // end namespace swift

lib/DependencyScan/DependencyScanningTool.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "swift/DependencyScan/DependencyScanningTool.h"
14+
#include "swift/DependencyScan/ModuleInfo.h"
1415
#include "swift/AST/DiagnosticEngine.h"
1516
#include "swift/AST/DiagnosticsFrontend.h"
1617
#include "swift/Basic/LLVMInitialize.h"
@@ -38,7 +39,7 @@ llvm::ErrorOr<std::string> DependencyScanningTool::getDependencies(
3839

3940
std::string JSONOutput;
4041
llvm::raw_string_ostream OSS(JSONOutput);
41-
scanDependencies(*Instance.get(), *SharedCache, OSS);
42+
performModuleScan(*Instance.get(), *SharedCache, OSS);
4243
OSS.flush();
4344

4445
// TODO: swiftch to an in-memory representation
@@ -55,7 +56,7 @@ std::error_code DependencyScanningTool::getDependencies(
5556
return EC;
5657
auto Instance = std::move(*InstanceOrErr);
5758

58-
executeBatchModuleScan(*Instance.get(), *SharedCache, Saver, BatchInput);
59+
performBatchModuleScan(*Instance.get(), *SharedCache, Saver, BatchInput);
5960
return std::error_code();
6061
}
6162

0 commit comments

Comments
 (0)