mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #76321 from artemcm/PackageOnlyAdjacentScanFix
[Dependency Scanning] Query package-only dependencies from adjacent binary modules when necessary
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