26
26
#include " llvm/ADT/IntrusiveRefCntPtr.h"
27
27
#include " llvm/ADT/Optional.h"
28
28
#include " llvm/ADT/StringSet.h"
29
+ #include " llvm/CAS/CASProvidingFileSystem.h"
29
30
#include " llvm/CAS/CASReference.h"
30
31
#include " llvm/CAS/CachingOnDiskFileSystem.h"
32
+ #include " llvm/CAS/ObjectStore.h"
31
33
#include " llvm/Support/Mutex.h"
32
34
#include " llvm/Support/Error.h"
33
35
#include " llvm/Support/VirtualFileSystem.h"
@@ -128,9 +130,12 @@ class ModuleDependencyInfoStorageBase {
128
130
struct CommonSwiftTextualModuleDependencyDetails {
129
131
CommonSwiftTextualModuleDependencyDetails (
130
132
ArrayRef<StringRef> extraPCMArgs, ArrayRef<StringRef> buildCommandLine,
133
+ ArrayRef<StringRef> bridgingHeaderBuildCommandLine,
131
134
const std::string &CASFileSystemRootID)
132
135
: extraPCMArgs(extraPCMArgs.begin(), extraPCMArgs.end()),
133
136
buildCommandLine (buildCommandLine.begin(), buildCommandLine.end()),
137
+ bridgingHeaderBuildCommandLine(bridgingHeaderBuildCommandLine.begin(),
138
+ bridgingHeaderBuildCommandLine.end()),
134
139
CASFileSystemRootID(CASFileSystemRootID) {}
135
140
136
141
// / To build a PCM to be used by this Swift module, we need to append these
@@ -155,8 +160,14 @@ struct CommonSwiftTextualModuleDependencyDetails {
155
160
// / interface.
156
161
std::vector<std::string> buildCommandLine;
157
162
163
+ // / The Swift frontend invocation arguments to build bridging header.
164
+ std::vector<std::string> bridgingHeaderBuildCommandLine;
165
+
158
166
// / CASID for the Root of CASFS. Empty if CAS is not used.
159
167
std::string CASFileSystemRootID;
168
+
169
+ // / CASID for the Root of bridgingHeaderClangIncludeTree. Empty if not used.
170
+ std::string bridgingHeaderIncludeTreeRoot;
160
171
};
161
172
162
173
// / Describes the dependencies of a Swift module described by an Swift interface file.
@@ -202,7 +213,7 @@ class SwiftInterfaceModuleDependenciesStorage :
202
213
compiledModuleCandidates(compiledModuleCandidates.begin(),
203
214
compiledModuleCandidates.end()),
204
215
contextHash(contextHash), isFramework(isFramework),
205
- textualModuleDetails(extraPCMArgs, buildCommandLine, RootID),
216
+ textualModuleDetails(extraPCMArgs, buildCommandLine, {}, RootID),
206
217
moduleCacheKey(ModuleCacheKey)
207
218
{}
208
219
@@ -218,10 +229,6 @@ class SwiftInterfaceModuleDependenciesStorage :
218
229
textualModuleDetails.buildCommandLine = newCommandLine;
219
230
}
220
231
221
- void updateCASFileSystemID (const std::string &ID) {
222
- textualModuleDetails.CASFileSystemRootID = ID;
223
- }
224
-
225
232
void updateModuleCacheKey (const std::string &Key) {
226
233
moduleCacheKey = Key;
227
234
}
@@ -243,11 +250,13 @@ class SwiftSourceModuleDependenciesStorage :
243
250
// / Collection of module imports that were detected to be `@Testable`
244
251
llvm::StringSet<> testableImports;
245
252
246
- SwiftSourceModuleDependenciesStorage (const std::string &RootID,
247
- ArrayRef<StringRef> buildCommandLine,
248
- ArrayRef<StringRef> extraPCMArgs)
253
+ SwiftSourceModuleDependenciesStorage (
254
+ const std::string &RootID, ArrayRef<StringRef> buildCommandLine,
255
+ ArrayRef<StringRef> bridgingHeaderBuildCommandLine,
256
+ ArrayRef<StringRef> extraPCMArgs)
249
257
: ModuleDependencyInfoStorageBase(ModuleDependencyKind::SwiftSource),
250
- textualModuleDetails (extraPCMArgs, buildCommandLine, RootID),
258
+ textualModuleDetails (extraPCMArgs, buildCommandLine,
259
+ bridgingHeaderBuildCommandLine, RootID),
251
260
testableImports(llvm::StringSet<>()) {}
252
261
253
262
ModuleDependencyInfoStorageBase *clone () const override {
@@ -262,8 +271,9 @@ class SwiftSourceModuleDependenciesStorage :
262
271
textualModuleDetails.buildCommandLine = newCommandLine;
263
272
}
264
273
265
- void updateCASFileSystemID (const std::string &ID) {
266
- textualModuleDetails.CASFileSystemRootID = ID;
274
+ void updateBridgingHeaderCommandLine (
275
+ const std::vector<std::string> &newCommandLine) {
276
+ textualModuleDetails.bridgingHeaderBuildCommandLine = newCommandLine;
267
277
}
268
278
269
279
void addTestableImport (ImportPath::Module module ) {
@@ -341,6 +351,9 @@ class ClangModuleDependencyStorage : public ModuleDependencyInfoStorageBase {
341
351
// / CASID for the Root of CASFS. Empty if CAS is not used.
342
352
std::string CASFileSystemRootID;
343
353
354
+ // / CASID for the Root of ClangIncludeTree. Empty if not used.
355
+ std::string clangIncludeTreeRoot;
356
+
344
357
// / The cache key for the produced module.
345
358
std::string moduleCacheKey;
346
359
@@ -352,6 +365,7 @@ class ClangModuleDependencyStorage : public ModuleDependencyInfoStorageBase {
352
365
const std::vector<std::string> &fileDependencies,
353
366
const std::vector<std::string> &capturedPCMArgs,
354
367
const std::string &CASFileSystemRootID,
368
+ const std::string &clangIncludeTreeRoot,
355
369
const std::string &ModuleCacheKey
356
370
) : ModuleDependencyInfoStorageBase(ModuleDependencyKind::Clang),
357
371
pcmOutputPath (pcmOutputPath),
@@ -361,6 +375,7 @@ class ClangModuleDependencyStorage : public ModuleDependencyInfoStorageBase {
361
375
fileDependencies(fileDependencies),
362
376
capturedPCMArgs(capturedPCMArgs),
363
377
CASFileSystemRootID(CASFileSystemRootID),
378
+ clangIncludeTreeRoot(clangIncludeTreeRoot),
364
379
moduleCacheKey(ModuleCacheKey) {}
365
380
366
381
ModuleDependencyInfoStorageBase *clone () const override {
@@ -473,10 +488,12 @@ class ModuleDependencyInfo {
473
488
static ModuleDependencyInfo
474
489
forSwiftSourceModule (const std::string &CASFileSystemRootID,
475
490
ArrayRef<StringRef> buildCommands,
491
+ ArrayRef<StringRef> bridgingHeaderBuildCommands,
476
492
ArrayRef<StringRef> extraPCMArgs) {
477
493
return ModuleDependencyInfo (
478
494
std::make_unique<SwiftSourceModuleDependenciesStorage>(
479
- CASFileSystemRootID, buildCommands, extraPCMArgs));
495
+ CASFileSystemRootID, buildCommands, bridgingHeaderBuildCommands,
496
+ extraPCMArgs));
480
497
}
481
498
482
499
// / Describe the module dependencies for a Clang module that can be
@@ -489,12 +506,13 @@ class ModuleDependencyInfo {
489
506
const std::vector<std::string> &fileDependencies,
490
507
const std::vector<std::string> &capturedPCMArgs,
491
508
const std::string &CASFileSystemRootID,
509
+ const std::string &clangIncludeTreeRoot,
492
510
const std::string &moduleCacheKey) {
493
511
return ModuleDependencyInfo (
494
512
std::make_unique<ClangModuleDependencyStorage>(
495
513
pcmOutputPath, moduleMapFile, contextHash,
496
514
nonPathCommandLine, fileDependencies, capturedPCMArgs,
497
- CASFileSystemRootID, moduleCacheKey));
515
+ CASFileSystemRootID, clangIncludeTreeRoot, moduleCacheKey));
498
516
}
499
517
500
518
// / Describe a placeholder dependency swift module.
@@ -593,13 +611,17 @@ class ModuleDependencyInfo {
593
611
llvm_unreachable (" Unexpected type" );
594
612
}
595
613
596
- void updateCASFileSystemID (const std::string &ID) {
597
- if (isSwiftInterfaceModule ())
598
- return cast<SwiftInterfaceModuleDependenciesStorage>(storage.get ())
599
- ->updateCASFileSystemID (ID);
600
- else if (isSwiftSourceModule ())
614
+ std::vector<std::string> getBridgingHeaderCommandline () const {
615
+ if (auto *detail = getAsSwiftSourceModule ())
616
+ return detail->textualModuleDetails .bridgingHeaderBuildCommandLine ;
617
+ return {};
618
+ }
619
+
620
+ void updateBridgingHeaderCommandLine (
621
+ const std::vector<std::string> &newCommandLine) {
622
+ if (isSwiftSourceModule ())
601
623
return cast<SwiftSourceModuleDependenciesStorage>(storage.get ())
602
- ->updateCASFileSystemID (ID );
624
+ ->updateBridgingHeaderCommandLine (newCommandLine );
603
625
llvm_unreachable (" Unexpected type" );
604
626
}
605
627
@@ -695,6 +717,12 @@ class ModuleDependencyInfo {
695
717
// / Get CAS Filesystem RootID.
696
718
Optional<std::string> getCASFSRootID () const ;
697
719
720
+ // / Get Clang Include Tree ID.
721
+ Optional<std::string> getClangIncludeTree () const ;
722
+
723
+ // / Get bridging header Include Tree ID.
724
+ Optional<std::string> getBridgingHeaderIncludeTree () const ;
725
+
698
726
// / Get module output path.
699
727
std::string getModuleOutputPath () const ;
700
728
@@ -711,6 +739,9 @@ class ModuleDependencyInfo {
711
739
void addBridgingModuleDependency (StringRef module ,
712
740
llvm::StringSet<> &alreadyAddedModules);
713
741
742
+ // / Add bridging header include tree.
743
+ void addBridgingHeaderIncludeTree (StringRef ID);
744
+
714
745
// / Collect a map from a secondary module name to a list of cross-import
715
746
// / overlays, when this current module serves as the primary module.
716
747
llvm::StringMap<llvm::SmallSetVector<Identifier, 4 >>
@@ -773,6 +804,12 @@ class SwiftDependencyScanningService {
773
804
// / CachingOnDiskFileSystem for dependency tracking.
774
805
llvm::IntrusiveRefCntPtr<llvm::cas::CachingOnDiskFileSystem> CacheFS;
775
806
807
+ // / If use clang include tree.
808
+ bool UseClangIncludeTree = false ;
809
+
810
+ // / CAS ObjectStore Instance.
811
+ std::shared_ptr<llvm::cas::ObjectStore> CAS;
812
+
776
813
// / The common dependencies that is needed for every swift compiler instance.
777
814
std::vector<std::string> CommonDependencyFiles;
778
815
@@ -826,7 +863,7 @@ class SwiftDependencyScanningService {
826
863
return getCacheForScanningContextHash (scanningContextHash)->alreadySeenClangModules ;
827
864
}
828
865
829
- bool usingCachingFS () const { return (bool )CacheFS; }
866
+ bool usingCachingFS () const { return !UseClangIncludeTree && (bool )CacheFS; }
830
867
831
868
llvm::cas::CachingOnDiskFileSystem &getSharedCachingFS () const {
832
869
assert (CacheFS && " Expect CachingOnDiskFileSystem" );
@@ -841,9 +878,13 @@ class SwiftDependencyScanningService {
841
878
}
842
879
843
880
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> getClangScanningFS () const {
844
- if (CacheFS )
881
+ if (usingCachingFS () )
845
882
return CacheFS->createProxyFS ();
846
883
884
+ if (UseClangIncludeTree)
885
+ return llvm::cas::createCASProvidingFileSystem (
886
+ CAS, llvm::vfs::createPhysicalFileSystem ());
887
+
847
888
return llvm::vfs::createPhysicalFileSystem ();
848
889
}
849
890
0 commit comments