Merge pull request #76321 from artemcm/PackageOnlyAdjacentScanFix

[Dependency Scanning] Query package-only dependencies from adjacent binary modules when necessary
This commit is contained in:
Artem Chikin
2024-09-09 09:53:01 -07:00
committed by GitHub
4 changed files with 120 additions and 1 deletions

View File

@@ -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,