[K/N][cinterop] Improve Imports interface

Extracting `isImported(headerId: HeaderId): Boolean` method allows
mocking this interface in tests
This commit is contained in:
Sergey Bogolepov
2023-01-12 12:49:57 +02:00
committed by Space Team
parent 2f0bdfc5e2
commit fe8e18cb33
2 changed files with 8 additions and 3 deletions
@@ -21,6 +21,8 @@ import org.jetbrains.kotlin.native.interop.indexer.*
interface Imports {
fun getPackage(location: Location): String?
fun isImported(headerId: HeaderId): Boolean
}
@@ -35,6 +37,9 @@ class ImportsImpl(internal val headerIdToPackage: Map<HeaderId, PackageInfo>) :
return packageInfo.name
}
override fun isImported(headerId: HeaderId) =
headerId in headerIdToPackage
private val accessedLibraries = mutableSetOf<KonanLibrary>()
val requiredLibraries: Set<KonanLibrary>
@@ -63,11 +68,11 @@ class HeaderInclusionPolicyImpl(
}
class HeaderExclusionPolicyImpl(
private val importsImpl: ImportsImpl
private val imports: Imports
) : HeaderExclusionPolicy {
override fun excludeAll(headerId: HeaderId): Boolean {
return headerId in importsImpl.headerIdToPackage
return imports.isImported(headerId)
}
}
@@ -508,7 +508,7 @@ internal fun buildNativeLibrary(
tool: ToolConfig,
def: DefFile,
arguments: CInteropArguments,
imports: ImportsImpl
imports: Imports
): NativeLibrary {
val additionalHeaders = (arguments.header).toTypedArray()
val additionalCompilerOpts = (arguments.compilerOpts +