@@ -222,10 +222,23 @@ SwiftModuleScanner::scanInterfaceFile(Identifier moduleID,
222222 bool isStrictMemorySafety =
223223 llvm::find (ArgsRefs, " -strict-memory-safety" ) != ArgsRefs.end ();
224224
225+ LibraryLevel libraryLevel = LibraryLevel::Other;
226+ auto libLevelIt = llvm::find (ArgsRefs, " -library-level" );
227+ if (libLevelIt != ArgsRefs.end () &&
228+ (libLevelIt + 1 ) != ArgsRefs.end ()) {
229+ libraryLevel = llvm::StringSwitch<LibraryLevel>(*(libLevelIt + 1 ))
230+ .Case (" api" , LibraryLevel::API)
231+ .Case (" spi" , LibraryLevel::SPI)
232+ .Case (" ipi" , LibraryLevel::IPI)
233+ .Default (LibraryLevel::Other);
234+ }
235+
225236 Result = ModuleDependencyInfo::forSwiftInterfaceModule (
226237 InPath, compiledCandidatesRefs, ArgsRefs, {}, {}, linkLibraries,
227238 isFramework, isStatic, isStrictMemorySafety, {},
228239 /* module-cache-key*/ " " , UserModVer);
240+ if (libraryLevel == LibraryLevel::IPI)
241+ Result->setLibraryLevel (libraryLevel);
229242
230243 // Walk the source file to find the import declarations.
231244 llvm::StringSet<> alreadyAddedModules;
@@ -282,8 +295,8 @@ SwiftModuleScanner::scanInterfaceFile(Identifier moduleID,
282295 if (code) {
283296 return code;
284297 }
285- // Compute library level based on the interface file path .
286- {
298+ // Use path heuristic for API/SPI; IPI was already set from the flags above .
299+ if (Result-> getLibraryLevel () != LibraryLevel::IPI) {
287300 SmallString<256 > modulePathBuf;
288301 StringRef modulePath = moduleInterfacePath.toStringRef (modulePathBuf);
289302 Result->setLibraryLevel (libraryLevelFromPath (
@@ -384,11 +397,17 @@ llvm::ErrorOr<ModuleDependencyInfo> SwiftModuleScanner::scanBinaryModuleFile(
384397 deps->ExecutablePath );
385398 }
386399
387- // Compute library level based on the binary module path.
400+ // Use the stored value only for IPI; path heuristic handles API/SPI as
401+ // before.
388402 {
389- dependencies.setLibraryLevel (libraryLevelFromPath (
390- definingModulePath, Ctx.SearchPathOpts .getSDKPath (),
391- Ctx.LangOpts .Target ));
403+ auto storedLevel = loadedModuleFile->getLibraryLevel ();
404+ if (storedLevel == LibraryLevel::IPI) {
405+ dependencies.setLibraryLevel (storedLevel);
406+ } else {
407+ dependencies.setLibraryLevel (libraryLevelFromPath (
408+ definingModulePath, Ctx.SearchPathOpts .getSDKPath (),
409+ Ctx.LangOpts .Target ));
410+ }
392411 }
393412
394413 return std::move (dependencies);
0 commit comments