mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Serialization|NFC] Extract logic loading dependencies out of associateWithFileContext
This commit is contained in:
@@ -123,53 +123,13 @@ bool ModuleFile::allowCompilerErrors() const {
|
||||
return getContext().LangOpts.AllowModuleWithCompilerErrors;
|
||||
}
|
||||
|
||||
Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
|
||||
bool recoverFromIncompatibility) {
|
||||
PrettyStackTraceModuleFile stackEntry(*this);
|
||||
|
||||
assert(!hasError() && "error already detected; should not call this");
|
||||
assert(!FileContext && "already associated with an AST module");
|
||||
FileContext = file;
|
||||
Status status = Status::Valid;
|
||||
|
||||
ModuleDecl *M = file->getParentModule();
|
||||
// The real (on-disk) name of the module should be checked here as that's the
|
||||
// actually loaded module. In case module aliasing is used when building the main
|
||||
// module, e.g. -module-name MyModule -module-alias Foo=Bar, the loaded module
|
||||
// that maps to 'Foo' is actually Bar.swiftmodule|.swiftinterface (applies to swift
|
||||
// modules only), which is retrieved via M->getRealName(). If no module aliasing is
|
||||
// used, M->getRealName() will return the same value as M->getName(), which is 'Foo'.
|
||||
if (M->getRealName().str() != Core->Name) {
|
||||
return error(Status::NameMismatch);
|
||||
}
|
||||
|
||||
Status
|
||||
ModuleFile::loadDependenciesForFileContext(const FileUnit *file,
|
||||
SourceLoc diagLoc,
|
||||
bool forTestable) {
|
||||
ASTContext &ctx = getContext();
|
||||
|
||||
llvm::Triple moduleTarget(llvm::Triple::normalize(Core->TargetTriple));
|
||||
if (!areCompatibleArchitectures(moduleTarget, ctx.LangOpts.Target) ||
|
||||
!areCompatibleOSs(moduleTarget, ctx.LangOpts.Target)) {
|
||||
status = Status::TargetIncompatible;
|
||||
if (!recoverFromIncompatibility)
|
||||
return error(status);
|
||||
} else if (ctx.LangOpts.EnableTargetOSChecking && !M->isResilient() &&
|
||||
isTargetTooNew(moduleTarget, ctx.LangOpts.Target)) {
|
||||
status = Status::TargetTooNew;
|
||||
if (!recoverFromIncompatibility)
|
||||
return error(status);
|
||||
}
|
||||
|
||||
StringRef SDKPath = ctx.SearchPathOpts.getSDKPath();
|
||||
if (SDKPath.empty() ||
|
||||
!Core->ModuleInputBuffer->getBufferIdentifier().startswith(SDKPath)) {
|
||||
for (const auto &searchPath : Core->SearchPaths) {
|
||||
ctx.addSearchPath(
|
||||
ctx.SearchPathOpts.SearchPathRemapper.remapPath(searchPath.Path),
|
||||
searchPath.IsFramework,
|
||||
searchPath.IsSystem);
|
||||
}
|
||||
}
|
||||
|
||||
auto clangImporter = static_cast<ClangImporter *>(ctx.getClangModuleLoader());
|
||||
ModuleDecl *M = file->getParentModule();
|
||||
|
||||
bool missingDependency = false;
|
||||
for (auto &dependency : Dependencies) {
|
||||
@@ -259,6 +219,59 @@ Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
|
||||
return error(Status::MissingDependency);
|
||||
}
|
||||
|
||||
return Status::Valid;
|
||||
}
|
||||
|
||||
Status ModuleFile::associateWithFileContext(FileUnit *file, SourceLoc diagLoc,
|
||||
bool recoverFromIncompatibility) {
|
||||
PrettyStackTraceModuleFile stackEntry(*this);
|
||||
|
||||
assert(!hasError() && "error already detected; should not call this");
|
||||
assert(!FileContext && "already associated with an AST module");
|
||||
FileContext = file;
|
||||
Status status = Status::Valid;
|
||||
|
||||
ModuleDecl *M = file->getParentModule();
|
||||
// The real (on-disk) name of the module should be checked here as that's the
|
||||
// actually loaded module. In case module aliasing is used when building the main
|
||||
// module, e.g. -module-name MyModule -module-alias Foo=Bar, the loaded module
|
||||
// that maps to 'Foo' is actually Bar.swiftmodule|.swiftinterface (applies to swift
|
||||
// modules only), which is retrieved via M->getRealName(). If no module aliasing is
|
||||
// used, M->getRealName() will return the same value as M->getName(), which is 'Foo'.
|
||||
if (M->getRealName().str() != Core->Name) {
|
||||
return error(Status::NameMismatch);
|
||||
}
|
||||
|
||||
ASTContext &ctx = getContext();
|
||||
|
||||
llvm::Triple moduleTarget(llvm::Triple::normalize(Core->TargetTriple));
|
||||
if (!areCompatibleArchitectures(moduleTarget, ctx.LangOpts.Target) ||
|
||||
!areCompatibleOSs(moduleTarget, ctx.LangOpts.Target)) {
|
||||
status = Status::TargetIncompatible;
|
||||
if (!recoverFromIncompatibility)
|
||||
return error(status);
|
||||
} else if (ctx.LangOpts.EnableTargetOSChecking && !M->isResilient() &&
|
||||
isTargetTooNew(moduleTarget, ctx.LangOpts.Target)) {
|
||||
status = Status::TargetTooNew;
|
||||
if (!recoverFromIncompatibility)
|
||||
return error(status);
|
||||
}
|
||||
|
||||
StringRef SDKPath = ctx.SearchPathOpts.getSDKPath();
|
||||
if (SDKPath.empty() ||
|
||||
!Core->ModuleInputBuffer->getBufferIdentifier().startswith(SDKPath)) {
|
||||
for (const auto &searchPath : Core->SearchPaths) {
|
||||
ctx.addSearchPath(
|
||||
ctx.SearchPathOpts.SearchPathRemapper.remapPath(searchPath.Path),
|
||||
searchPath.IsFramework,
|
||||
searchPath.IsSystem);
|
||||
}
|
||||
}
|
||||
|
||||
Status res = loadDependenciesForFileContext(file, diagLoc,
|
||||
/*forTestable=*/false);
|
||||
if (res != Status::Valid) return res;
|
||||
|
||||
if (Core->Bits.HasEntryPoint) {
|
||||
FileContext->getParentModule()->registerEntryPointFile(FileContext,
|
||||
SourceLoc(),
|
||||
|
||||
Reference in New Issue
Block a user