@@ -25,6 +25,12 @@ class DependencyTracker;
25
25
26
26
namespace swift {
27
27
28
+ // / A callback to lookup module outputs for "-fmodule-file=", "-o" etc.
29
+ using LookupModuleOutputCallback = llvm::function_ref<std::string(
30
+ const clang::tooling::dependencies::ModuleDeps &,
31
+ clang::tooling::dependencies::ModuleOutputKind)>;
32
+ using RemapPathCallback = llvm::function_ref<std::string(StringRef)>;
33
+
28
34
// / A dependency scanning worker which performs filesystem lookup
29
35
// / of a named module dependency.
30
36
class ModuleDependencyScanningWorker {
@@ -39,42 +45,60 @@ class ModuleDependencyScanningWorker {
39
45
llvm::PrefixMapper *mapper, DiagnosticEngine &diags);
40
46
41
47
private:
42
- // / Retrieve the module dependencies for the Clang module with the given name.
43
- ClangModuleScannerQueryResult scanFilesystemForClangModuleDependency (
48
+ // / Query dependency information for a named Clang module
49
+ // /
50
+ // / \param moduleName moduel identifier for the query
51
+ // /
52
+ // / \param lookupModuleCallback a callback to compute a client-specific
53
+ // / module-cache-relative output path for discovered Clang module dependencies.
54
+ // /
55
+ // / \param alreadySeenModules a set of module dependencies previously seen
56
+ // / by the scanner, as to avoid processing them all over again
57
+ // /
58
+ // / \returns Clang dependency scanner's \c TranslationUnitDeps result
59
+ std::optional<clang::tooling::dependencies::TranslationUnitDeps>
60
+ scanFilesystemForClangModuleDependency (
44
61
Identifier moduleName,
62
+ LookupModuleOutputCallback lookupModuleCallback,
45
63
const llvm::DenseSet<clang::tooling::dependencies::ModuleID>
46
64
&alreadySeenModules);
47
65
48
- // / Retrieve the module dependencies for the Swift module with the given name.
49
- SwiftModuleScannerQueryResult scanFilesystemForSwiftModuleDependency (
50
- Identifier moduleName, bool isTestableImport = false );
51
-
52
66
// / Query dependency information for header dependencies
53
67
// / of a binary Swift module.
54
68
// /
55
69
// / \param moduleID the name of the Swift module whose dependency
56
70
// / information will be augmented with information about the given
57
71
// / textual header inputs.
58
72
// /
59
- // / \param headerPath the path to the header to be scanned.
73
+ // / \param headerPath optional path to the header to be scanned.
74
+ // /
75
+ // / \param sourceBuffer optional in-memory buffer of a header to be scanned.
60
76
// /
61
- // / \param clangScanningTool The clang dependency scanner.
77
+ // / \param lookupModuleCallback a callback to compute a client-specific
78
+ // / module-cache-relative output path for discovered Clang module dependencies.
62
79
// /
63
- // / \param cache The module dependencies cache to update, with information
64
- // / about new Clang modules discovered along the way.
80
+ // / \param alreadySeenModules a set of module dependencies previously seen
81
+ // / by the scanner, as to avoid processing them all over again
65
82
// /
66
- // / \returns \c true if an error occurred, \c false otherwise
67
- bool scanHeaderDependenciesOfSwiftModule (
68
- const ASTContext &ctx,
83
+ // / \returns Clang dependency scanner's \c TranslationUnitDeps result
84
+ std::optional<clang::tooling::dependencies::TranslationUnitDeps>
85
+ scanHeaderDependenciesOfSwiftModule (
69
86
ModuleDependencyID moduleID, std::optional<StringRef> headerPath,
70
87
std::optional<llvm::MemoryBufferRef> sourceBuffer,
71
- ModuleDependenciesCache &cache,
72
- ModuleDependencyIDSetVector &headerClangModuleDependencies,
73
- std::vector<std::string> &headerFileInputs,
74
- std::vector<std::string> &bridgingHeaderCommandLine,
75
- std::vector<std::string> &visibleClangModules,
76
- std::optional<std::string> &includeTreeID);
88
+ LookupModuleOutputCallback lookupModuleCallback,
89
+ const llvm::DenseSet<clang::tooling::dependencies::ModuleID>
90
+ &alreadySeenModules);
77
91
92
+ // / Query dependency information for a named Swift module
93
+ // /
94
+ // / \param moduleName moduel identifier for the query
95
+ // /
96
+ // / \param isTestableImport a boolean flag which indicates whether
97
+ // / this is an @testable dependency
98
+ // /
99
+ // / \returns a struct containing query results
100
+ SwiftModuleScannerQueryResult scanFilesystemForSwiftModuleDependency (
101
+ Identifier moduleName, bool isTestableImport = false );
78
102
79
103
// / Store cache entry for include tree.
80
104
llvm::Error
@@ -92,16 +116,9 @@ class ModuleDependencyScanningWorker {
92
116
// Swift and Clang module loaders acting as scanners.
93
117
std::unique_ptr<SwiftModuleScanner> swiftModuleScannerLoader;
94
118
95
- // / The location of where the explicitly-built modules will be output to
96
- std::string moduleOutputPath;
97
- // / The location of where the explicitly-built SDK modules will be output to
98
- std::string sdkModuleOutputPath;
99
-
100
119
// CAS instance.
101
120
std::shared_ptr<llvm::cas::ObjectStore> CAS;
102
121
std::shared_ptr<llvm::cas::ActionCache> ActionCache;
103
- // / File prefix mapper.
104
- llvm::PrefixMapper *PrefixMapper;
105
122
106
123
// Base command line invocation for clang scanner queries (both module and header)
107
124
std::vector<std::string> clangScanningBaseCommandLineArgs;
@@ -222,11 +239,7 @@ class ModuleDependencyScanner {
222
239
return PrefixMapper && !PrefixMapper->getMappings ().empty ();
223
240
}
224
241
llvm::PrefixMapper *getPrefixMapper () const { return PrefixMapper.get (); }
225
- std::string remapPath (StringRef Path) const {
226
- if (!PrefixMapper)
227
- return Path.str ();
228
- return PrefixMapper->mapToString (Path);
229
- }
242
+ std::string remapPath (StringRef Path) const ;
230
243
231
244
// / CAS options.
232
245
llvm::cas::ObjectStore &getCAS () const {
@@ -293,11 +306,22 @@ class ModuleDependencyScanner {
293
306
ModuleDependenciesCache &cache,
294
307
ModuleDependencyIDSetVector &allModules);
295
308
309
+ // / Bridge Clang dependency scanner's dependency node
310
+ // / to the Swift scanner's `ModuleDependencyInfo`.
311
+ ModuleDependencyInfo
312
+ bridgeClangModuleDependency (
313
+ const clang::tooling::dependencies::ModuleDeps &clangDependency);
314
+
296
315
// / Perform an operation utilizing one of the Scanning workers
297
316
// / available to this scanner.
298
317
template <typename Function, typename ... Args>
299
318
auto withDependencyScanningWorker (Function &&F, Args &&...ArgList);
300
319
320
+ // / Determine cache-relative output path for a given Clang module
321
+ std::string clangModuleOutputPathLookup (
322
+ const clang::tooling::dependencies::ModuleDeps &clangDep,
323
+ clang::tooling::dependencies::ModuleOutputKind moduleOutputKind) const ;
324
+
301
325
// / Use the scanner's ASTContext to construct an `Identifier`
302
326
// / for a given module name.
303
327
Identifier getModuleImportIdentifier (StringRef moduleName);
@@ -317,6 +341,11 @@ class ModuleDependencyScanner {
317
341
ASTContext &ScanASTContext;
318
342
ModuleDependencyIssueReporter IssueReporter;
319
343
344
+ // / The location of where the explicitly-built modules will be output to
345
+ std::string ModuleOutputPath;
346
+ // / The location of where the explicitly-built SDK modules will be output to
347
+ std::string SDKModuleOutputPath;
348
+
320
349
// / The available pool of workers for filesystem module search
321
350
unsigned NumThreads;
322
351
std::list<std::unique_ptr<ModuleDependencyScanningWorker>> Workers;
0 commit comments