@@ -2246,6 +2246,49 @@ SPIGroupsRequest::evaluate(Evaluator &evaluator, const Decl *decl) const {
2246
2246
return ctx.AllocateCopy (spiGroups.getArrayRef ());
2247
2247
}
2248
2248
2249
+ LibraryLevel ModuleDecl::getLibraryLevel () const {
2250
+ return evaluateOrDefault (getASTContext ().evaluator ,
2251
+ ModuleLibraryLevelRequest{this },
2252
+ LibraryLevel::Other);
2253
+ }
2254
+
2255
+ LibraryLevel
2256
+ ModuleLibraryLevelRequest::evaluate (Evaluator &evaluator,
2257
+ const ModuleDecl *module) const {
2258
+ auto &ctx = module->getASTContext ();
2259
+
2260
+ // / Is \p path from System/Library/PrivateFrameworks/?
2261
+ auto fromPrivateFrameworks = [&](StringRef path) -> bool {
2262
+ auto sep = llvm::sys::path::get_separator ();
2263
+ auto privateFrameworksPath = llvm::Twine (ctx.SearchPathOpts .SDKPath ) +
2264
+ sep + " System" + sep + " Library" + sep + " PrivateFrameworks" + sep;
2265
+ return hasPrefix (path, privateFrameworksPath.str ());
2266
+ };
2267
+
2268
+ if (module->isNonSwiftModule ()) {
2269
+ if (auto *underlying = module->findUnderlyingClangModule ()) {
2270
+ // Imported clangmodules are SPI if they are defined by a private
2271
+ // modulemap or from the PrivateFrameworks folder in the SDK.
2272
+ bool moduleIsSPI = underlying->ModuleMapIsPrivate ||
2273
+ (underlying->isPartOfFramework () &&
2274
+ fromPrivateFrameworks (underlying->PresumedModuleMapFile ));
2275
+ return moduleIsSPI ? LibraryLevel::SPI : LibraryLevel::API;
2276
+ }
2277
+ return LibraryLevel::Other;
2278
+
2279
+ } else if (module->isMainModule ()) {
2280
+ // The current compilation target.
2281
+ return ctx.LangOpts .LibraryLevel ;
2282
+
2283
+ } else {
2284
+ // Other Swift modules are SPI if they are from the PrivateFrameworks
2285
+ // folder in the SDK.
2286
+ auto modulePath = module->getModuleFilename ();
2287
+ return fromPrivateFrameworks (modulePath) ?
2288
+ LibraryLevel::SPI : LibraryLevel::API;
2289
+ }
2290
+ }
2291
+
2249
2292
bool SourceFile::shouldCrossImport () const {
2250
2293
return Kind != SourceFileKind::SIL && Kind != SourceFileKind::Interface &&
2251
2294
getASTContext ().LangOpts .EnableCrossImportOverlays ;
0 commit comments