mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[ScanDependency][canImport] Improve canImport handling in explicit build
Teach dependency scanner to report all the module canImport check result to swift-frontend, so swift-frontend doesn't need to parse swiftmodule or parse TBD file to determine the versions. This ensures dependency scanner and swift-frontend will have the same resolution for all canImport checks. This also fixes two related issues: * Previously, in order to get consistant results between scanner and frontend, scanner will request building the module in canImport check even it is not imported later. This slightly alters the definition of the canImport to only succeed when the module can be found AND be built. This also can affect the auto-link in such cases. * For caching build, the location of the clang module is abstracted away so swift-frontend cannot locate the TBD file to resolve underlyingVersion. rdar://128067152
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
#include "llvm/CAS/CachingOnDiskFileSystem.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/Threading.h"
|
||||
#include "llvm/Support/VersionTuple.h"
|
||||
#include "llvm/Support/VirtualFileSystem.h"
|
||||
#include <algorithm>
|
||||
|
||||
@@ -464,15 +465,26 @@ ModuleDependencyScanner::getMainModuleDependencyInfo(ModuleDecl *mainModule) {
|
||||
&ScanASTContext.SourceMgr);
|
||||
}
|
||||
|
||||
// Add all the successful canImport checks from the ASTContext as part of
|
||||
// the dependency since only mainModule can have `canImport` check. This
|
||||
// needs to happen after visiting all the top-level decls from all
|
||||
// Pass all the successful canImport checks from the ASTContext as part of
|
||||
// build command to main module to ensure frontend gets the same result.
|
||||
// This needs to happen after visiting all the top-level decls from all
|
||||
// SourceFiles.
|
||||
for (auto &Module :
|
||||
mainModule->getASTContext().getSuccessfulCanImportCheckNames())
|
||||
mainDependencies.addModuleImport(Module.first(),
|
||||
&alreadyAddedModules);
|
||||
}
|
||||
auto buildArgs = mainDependencies.getCommandline();
|
||||
mainModule->getASTContext().forEachCanImportVersionCheck(
|
||||
[&](StringRef moduleName, const llvm::VersionTuple &Version,
|
||||
const llvm::VersionTuple &UnderlyingVersion) {
|
||||
if (Version.empty() && UnderlyingVersion.empty()) {
|
||||
buildArgs.push_back("-module-can-import");
|
||||
buildArgs.push_back(moduleName.str());
|
||||
} else {
|
||||
buildArgs.push_back("-module-can-import-version");
|
||||
buildArgs.push_back(moduleName.str());
|
||||
buildArgs.push_back(Version.getAsString());
|
||||
buildArgs.push_back(UnderlyingVersion.getAsString());
|
||||
}
|
||||
});
|
||||
mainDependencies.updateCommandLine(buildArgs);
|
||||
}
|
||||
|
||||
return mainDependencies;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user