[Sema] Consider modules imported from more paths as private

Consider both frameworks and free floating modules imported from more
private path as SPI. This will make the compiler raise errors on public
imports of more private modules.

rdar://91904154
This commit is contained in:
Alexis Laferrière
2022-04-18 14:24:12 -07:00
parent 6cc2399ddb
commit 91001f0257
4 changed files with 12 additions and 3 deletions

View File

@@ -2646,7 +2646,10 @@ ModuleLibraryLevelRequest::evaluate(Evaluator &evaluator,
auto fromPrivateFrameworks = [&](StringRef modulePath) -> bool {
if (!ctx.LangOpts.Target.isOSDarwin()) return false;
return hasSDKPrefix(modulePath, "System", "Library", "PrivateFrameworks");
return hasSDKPrefix(modulePath, "AppleInternal", "Library", "Frameworks") ||
hasSDKPrefix(modulePath, "System", "Library", "PrivateFrameworks") ||
hasSDKPrefix(modulePath, "System", "iOSSupport", "System", "Library", "PrivateFrameworks") ||
hasSDKPrefix(modulePath, "usr", "local", "include");
};
if (module->isNonSwiftModule()) {
@@ -2654,8 +2657,7 @@ ModuleLibraryLevelRequest::evaluate(Evaluator &evaluator,
// Imported clangmodules are SPI if they are defined by a private
// modulemap or from the PrivateFrameworks folder in the SDK.
bool moduleIsSPI = underlying->ModuleMapIsPrivate ||
(underlying->isPartOfFramework() &&
fromPrivateFrameworks(underlying->PresumedModuleMapFile));
fromPrivateFrameworks(underlying->PresumedModuleMapFile);
return moduleIsSPI ? LibraryLevel::SPI : LibraryLevel::API;
}
return LibraryLevel::Other;