[ObjCExport] AA: AnalysisApiHeaderGenerator: Implement support for klib dependencies
KT-65670
This commit is contained in:
committed by
Space Team
parent
e377a98815
commit
64503d9217
+5
-1
@@ -29,7 +29,11 @@ class AnalysisApiHeaderGeneratorExtension : ParameterResolver {
|
|||||||
|
|
||||||
object AnalysisApiHeaderGenerator : HeaderGenerator {
|
object AnalysisApiHeaderGenerator : HeaderGenerator {
|
||||||
override fun generateHeaders(root: File, configuration: HeaderGenerator.Configuration): ObjCHeader {
|
override fun generateHeaders(root: File, configuration: HeaderGenerator.Configuration): ObjCHeader {
|
||||||
val session = createStandaloneAnalysisApiSession(root.listFiles().orEmpty().filter { it.extension == "kt" })
|
val session = createStandaloneAnalysisApiSession(
|
||||||
|
kotlinFiles = root.listFiles().orEmpty().filter { it.extension == "kt" },
|
||||||
|
dependencyKlibs = configuration.dependencies
|
||||||
|
)
|
||||||
|
|
||||||
val (module, files) = session.modulesWithFiles.entries.single()
|
val (module, files) = session.modulesWithFiles.entries.single()
|
||||||
return analyze(module) {
|
return analyze(module) {
|
||||||
KtObjCExportSession(
|
KtObjCExportSession(
|
||||||
|
|||||||
+21
-5
@@ -16,7 +16,9 @@ import org.jetbrains.kotlin.backend.konan.testUtils.kotlinNativeStdlibPath
|
|||||||
import org.jetbrains.kotlin.konan.target.HostManager
|
import org.jetbrains.kotlin.konan.target.HostManager
|
||||||
import org.jetbrains.kotlin.platform.konan.NativePlatforms
|
import org.jetbrains.kotlin.platform.konan.NativePlatforms
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.nio.file.Path
|
||||||
import kotlin.io.path.Path
|
import kotlin.io.path.Path
|
||||||
|
import kotlin.io.path.nameWithoutExtension
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a standalone analysis session from Kotlin source code passed as [kotlinSources]
|
* Creates a standalone analysis session from Kotlin source code passed as [kotlinSources]
|
||||||
@@ -24,6 +26,7 @@ import kotlin.io.path.Path
|
|||||||
fun createStandaloneAnalysisApiSession(
|
fun createStandaloneAnalysisApiSession(
|
||||||
tempDir: File,
|
tempDir: File,
|
||||||
kotlinSources: Map</* File Name */ String, /* Source Code */ String>,
|
kotlinSources: Map</* File Name */ String, /* Source Code */ String>,
|
||||||
|
dependencyKlibs: List<Path> = emptyList(),
|
||||||
): StandaloneAnalysisAPISession {
|
): StandaloneAnalysisAPISession {
|
||||||
val testModuleRoot = tempDir.resolve("testModule")
|
val testModuleRoot = tempDir.resolve("testModule")
|
||||||
testModuleRoot.mkdirs()
|
testModuleRoot.mkdirs()
|
||||||
@@ -33,14 +36,14 @@ fun createStandaloneAnalysisApiSession(
|
|||||||
writeText(sourceCode)
|
writeText(sourceCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return createStandaloneAnalysisApiSession(listOf(testModuleRoot))
|
return createStandaloneAnalysisApiSession(listOf(testModuleRoot), dependencyKlibs)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a standalone analysis session from [kotlinFiles] on disk.
|
* Creates a standalone analysis session from [kotlinFiles] on disk.
|
||||||
* The Kotlin/Native stdlib will be provided as dependency
|
* The Kotlin/Native stdlib will be provided as dependency
|
||||||
*/
|
*/
|
||||||
fun createStandaloneAnalysisApiSession(kotlinFiles: List<File>): StandaloneAnalysisAPISession {
|
fun createStandaloneAnalysisApiSession(kotlinFiles: List<File>, dependencyKlibs: List<Path> = emptyList()): StandaloneAnalysisAPISession {
|
||||||
val currentArchitectureTarget = HostManager.host
|
val currentArchitectureTarget = HostManager.host
|
||||||
val nativePlatform = NativePlatforms.nativePlatformByTargets(listOf(currentArchitectureTarget))
|
val nativePlatform = NativePlatforms.nativePlatformByTargets(listOf(currentArchitectureTarget))
|
||||||
return buildStandaloneAnalysisAPISession {
|
return buildStandaloneAnalysisAPISession {
|
||||||
@@ -49,17 +52,30 @@ fun createStandaloneAnalysisApiSession(kotlinFiles: List<File>): StandaloneAnaly
|
|||||||
|
|
||||||
buildKtModuleProvider {
|
buildKtModuleProvider {
|
||||||
platform = nativePlatform
|
platform = nativePlatform
|
||||||
val kLib = addModule(
|
val stdlibModule = addModule(
|
||||||
buildKtLibraryModule {
|
buildKtLibraryModule {
|
||||||
addBinaryRoot(Path(kotlinNativeStdlibPath))
|
addBinaryRoot(Path(kotlinNativeStdlibPath))
|
||||||
platform = nativePlatform
|
platform = nativePlatform
|
||||||
libraryName = "klib"
|
libraryName = "stdlib"
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val dependencyKlibModules = dependencyKlibs.map { klib ->
|
||||||
|
buildKtLibraryModule {
|
||||||
|
addBinaryRoot(klib)
|
||||||
|
platform = nativePlatform
|
||||||
|
libraryName = klib.nameWithoutExtension
|
||||||
|
addRegularDependency(stdlibModule)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
addModule(
|
addModule(
|
||||||
buildKtSourceModule {
|
buildKtSourceModule {
|
||||||
addSourceRoots(kotlinFiles.map { it.toPath() })
|
addSourceRoots(kotlinFiles.map { it.toPath() })
|
||||||
addRegularDependency(kLib)
|
addRegularDependency(stdlibModule)
|
||||||
|
dependencyKlibModules.forEach { dependencyKlibModule ->
|
||||||
|
addRegularDependency(dependencyKlibModule)
|
||||||
|
}
|
||||||
platform = nativePlatform
|
platform = nativePlatform
|
||||||
moduleName = "source"
|
moduleName = "source"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user