mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Dependency Scanning] Query package-only dependencies from adjacent binary modules when necessary
When '.package.swiftinterface' loading ('-experimental-package-interface-load') is disabled and when '-scanner-module-validation' is disabled, the scanner defaults to locating the non-package textual interface and may specify its adjacent binary module as a valid candidate binary module to use. If said candidate is up-to-date and ends up getting used, and belongs to the same package as the loading Swift source, then the source compilation may attempt to load its package-only dependencies. Since the scanner only parsed the non-package textual interface, those dependencies are not located and specified as inputs to compilation. This change causes the scanner, in such cases, to also lookup package-only dependencies in adjacent binary Swift modules of textual Swift module dependencies, if such dependency belongs to the same package as the source target being scanned.
Resolves rdar://135215789
This commit is contained in:
@@ -301,6 +301,45 @@ SerializedModuleLoaderBase::getModuleName(ASTContext &Ctx, StringRef modulePath,
|
||||
return ModuleFile::getModuleName(Ctx, modulePath, Name);
|
||||
}
|
||||
|
||||
llvm::ErrorOr<llvm::StringSet<>>
|
||||
SerializedModuleLoaderBase::getMatchingPackageOnlyImportsOfModule(
|
||||
Twine modulePath, bool isFramework, bool isRequiredOSSAModules,
|
||||
StringRef SDKName, StringRef packageName, llvm::vfs::FileSystem *fileSystem,
|
||||
PathObfuscator &recoverer) {
|
||||
auto moduleBuf = fileSystem->getBufferForFile(modulePath);
|
||||
if (!moduleBuf)
|
||||
return moduleBuf.getError();
|
||||
|
||||
llvm::StringSet<> importedModuleNames;
|
||||
// Load the module file without validation.
|
||||
std::shared_ptr<const ModuleFileSharedCore> loadedModuleFile;
|
||||
serialization::ValidationInfo loadInfo = ModuleFileSharedCore::load(
|
||||
"", "", std::move(moduleBuf.get()), nullptr, nullptr, isFramework,
|
||||
isRequiredOSSAModules, SDKName, recoverer, loadedModuleFile);
|
||||
|
||||
if (loadedModuleFile->getModulePackageName() != packageName)
|
||||
return importedModuleNames;
|
||||
|
||||
for (const auto &dependency : loadedModuleFile->getDependencies()) {
|
||||
if (dependency.isHeader())
|
||||
continue;
|
||||
if (!dependency.isPackageOnly())
|
||||
continue;
|
||||
|
||||
// Find the top-level module name.
|
||||
auto modulePathStr = dependency.getPrettyPrintedPath();
|
||||
StringRef moduleName = modulePathStr;
|
||||
auto dotPos = moduleName.find('.');
|
||||
if (dotPos != std::string::npos)
|
||||
moduleName = moduleName.slice(0, dotPos);
|
||||
|
||||
importedModuleNames.insert(moduleName);
|
||||
}
|
||||
|
||||
return importedModuleNames;
|
||||
}
|
||||
|
||||
|
||||
std::error_code
|
||||
SerializedModuleLoaderBase::openModuleSourceInfoFileIfPresent(
|
||||
ImportPath::Element ModuleID,
|
||||
|
||||
Reference in New Issue
Block a user