mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[CAS] swift dependency scanning using CAS for compiler caching (#66366)
Teach swift dependency scanner to use CAS to capture the full dependencies for a build and construct build commands with immutable inputs from CAS. This allows swift compilation caching using CAS.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "swift/AST/ASTContext.h"
|
||||
#include "swift/AST/ModuleDependencies.h"
|
||||
#include "swift/Frontend/ModuleInterfaceLoader.h"
|
||||
#include "swift/Serialization/SerializedModuleLoader.h"
|
||||
|
||||
@@ -41,18 +42,22 @@ namespace swift {
|
||||
|
||||
/// Location where pre-built moduels are to be built into.
|
||||
std::string moduleCachePath;
|
||||
|
||||
Optional<SwiftDependencyTracker> dependencyTracker;
|
||||
public:
|
||||
Optional<ModuleDependencyInfo> dependencies;
|
||||
|
||||
ModuleDependencyScanner(ASTContext &ctx, ModuleLoadingMode LoadMode,
|
||||
Identifier moduleName,
|
||||
InterfaceSubContextDelegate &astDelegate,
|
||||
ScannerKind kind = MDS_plain)
|
||||
ScannerKind kind = MDS_plain,
|
||||
Optional<SwiftDependencyTracker> tracker = None)
|
||||
: SerializedModuleLoaderBase(ctx, nullptr, LoadMode,
|
||||
/*IgnoreSwiftSourceInfoFile=*/true),
|
||||
kind(kind), moduleName(moduleName), astDelegate(astDelegate),
|
||||
moduleCachePath(getModuleCachePathFromClang(
|
||||
ctx.getClangModuleLoader()->getClangInstance())) {}
|
||||
ctx.getClangModuleLoader()->getClangInstance())),
|
||||
dependencyTracker(tracker) {}
|
||||
|
||||
std::error_code findModuleFilesInDirectory(
|
||||
ImportPath::Element ModuleID,
|
||||
@@ -87,9 +92,16 @@ namespace swift {
|
||||
void parsePlaceholderModuleMap(StringRef fileName) {
|
||||
ExplicitModuleMapParser parser(Allocator);
|
||||
llvm::StringMap<ExplicitClangModuleInputInfo> ClangDependencyModuleMap;
|
||||
auto result =
|
||||
parser.parseSwiftExplicitModuleMap(fileName, PlaceholderDependencyModuleMap,
|
||||
ClangDependencyModuleMap);
|
||||
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileBufOrErr =
|
||||
llvm::MemoryBuffer::getFile(fileName);
|
||||
if (!fileBufOrErr) {
|
||||
Ctx.Diags.diagnose(SourceLoc(),
|
||||
diag::explicit_swift_module_map_missing, fileName);
|
||||
return;
|
||||
}
|
||||
auto result = parser.parseSwiftExplicitModuleMap(
|
||||
(*fileBufOrErr)->getMemBufferRef(), PlaceholderDependencyModuleMap,
|
||||
ClangDependencyModuleMap);
|
||||
if (result == std::errc::invalid_argument) {
|
||||
Ctx.Diags.diagnose(SourceLoc(),
|
||||
diag::placeholder_dependency_module_map_corrupted,
|
||||
@@ -109,9 +121,10 @@ namespace swift {
|
||||
PlaceholderSwiftModuleScanner(ASTContext &ctx, ModuleLoadingMode LoadMode,
|
||||
Identifier moduleName,
|
||||
StringRef PlaceholderDependencyModuleMap,
|
||||
InterfaceSubContextDelegate &astDelegate)
|
||||
InterfaceSubContextDelegate &astDelegate,
|
||||
Optional<SwiftDependencyTracker> tracker = None)
|
||||
: ModuleDependencyScanner(ctx, LoadMode, moduleName, astDelegate,
|
||||
MDS_placeholder) {
|
||||
MDS_placeholder, tracker) {
|
||||
|
||||
// FIXME: Find a better place for this map to live, to avoid
|
||||
// doing the parsing on every module.
|
||||
|
||||
Reference in New Issue
Block a user