Interop: handle all main.kotlin.srcDirs in Gradle plugin
also fix minor bug with default package
This commit is contained in:
+11
-6
@@ -9,13 +9,20 @@ import kotlin.system.exitProcess
|
|||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
val llvmInstallPath = System.getProperty("llvmInstallPath")!!
|
val llvmInstallPath = System.getProperty("llvmInstallPath")!!
|
||||||
|
|
||||||
val ktSrcRoot = args[0]
|
val ktGenRoot = args[0]
|
||||||
val ktGenRoot = args[1]
|
val nativeLibsDir = args[1]
|
||||||
val nativeLibsDir = args[2]
|
val ktSrcRoots = args.drop(2)
|
||||||
|
|
||||||
|
ktSrcRoots.forEach { ktSrcRoot ->
|
||||||
val defFiles = File(ktSrcRoot).walk().filter { it.name.endsWith(".def") }
|
val defFiles = File(ktSrcRoot).walk().filter { it.name.endsWith(".def") }
|
||||||
|
|
||||||
defFiles.forEach { defFile ->
|
defFiles.forEach { defFile ->
|
||||||
|
processDefFile(ktSrcRoot, defFile, ktGenRoot, nativeLibsDir, llvmInstallPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun processDefFile(ktSrcRoot: String, defFile: File, ktGenRoot: String, nativeLibsDir: String, llvmInstallPath: String) {
|
||||||
val config = Properties()
|
val config = Properties()
|
||||||
defFile.bufferedReader().use { reader ->
|
defFile.bufferedReader().use { reader ->
|
||||||
config.load(reader)
|
config.load(reader)
|
||||||
@@ -32,8 +39,7 @@ fun main(args: Array<String>) {
|
|||||||
|
|
||||||
val defFileRelative = defFile.relativeTo(File(ktSrcRoot))
|
val defFileRelative = defFile.relativeTo(File(ktSrcRoot))
|
||||||
val outKtFile = File(ktGenRoot, defFileRelative.toString().substringBeforeLast(".def") + ".kt")
|
val outKtFile = File(ktGenRoot, defFileRelative.toString().substringBeforeLast(".def") + ".kt")
|
||||||
val outKtPkg = defFileRelative.parentFile.path.replace(File.separatorChar, '.')
|
val outKtPkg = defFileRelative.parentFile?.path?.replace(File.separatorChar, '.') ?: ""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val nativeIndex = buildNativeIndex(headerFiles, compilerOpts)
|
val nativeIndex = buildNativeIndex(headerFiles, compilerOpts)
|
||||||
@@ -96,7 +102,6 @@ fun main(args: Array<String>) {
|
|||||||
|
|
||||||
outCFile.delete()
|
outCFile.delete()
|
||||||
outOFile.delete()
|
outOFile.delete()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildNativeIndex(headerFiles: List<String>, compilerOpts: List<String>): NativeIndex {
|
private fun buildNativeIndex(headerFiles: List<String>, compilerOpts: List<String>): NativeIndex {
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ class NativeInteropPlugin implements Plugin<Project> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
void apply(Project prj) {
|
void apply(Project prj) {
|
||||||
// TODO: handle other source sets
|
|
||||||
def srcDir = prj.file("src/main/kotlin")
|
|
||||||
def generatedSrcDir = new File(prj.buildDir, "nativeInteropStubs/kotlin")
|
def generatedSrcDir = new File(prj.buildDir, "nativeInteropStubs/kotlin")
|
||||||
def nativeLibsDir = new File(prj.buildDir, "nativelibs")
|
def nativeLibsDir = new File(prj.buildDir, "nativelibs")
|
||||||
|
|
||||||
@@ -27,18 +25,26 @@ class NativeInteropPlugin implements Plugin<Project> {
|
|||||||
prj.task(genStubsTaskName, type: JavaExec) {
|
prj.task(genStubsTaskName, type: JavaExec) {
|
||||||
classpath = prj.configurations.interopStubGenerator
|
classpath = prj.configurations.interopStubGenerator
|
||||||
main = "org.jetbrains.kotlin.native.interop.gen.jvm.MainKt"
|
main = "org.jetbrains.kotlin.native.interop.gen.jvm.MainKt"
|
||||||
args = [srcDir, generatedSrcDir, nativeLibsDir]
|
args = [generatedSrcDir, nativeLibsDir]
|
||||||
systemProperties "java.library.path" : new File(prj.findProject(":Interop:Indexer").buildDir, "nativelibs")
|
systemProperties "java.library.path" : new File(prj.findProject(":Interop:Indexer").buildDir, "nativelibs")
|
||||||
systemProperties "llvmInstallPath" : prj.llvmInstallPath
|
systemProperties "llvmInstallPath" : prj.llvmInstallPath
|
||||||
environment "LIBCLANG_DISABLE_CRASH_RECOVERY": "1"
|
environment "LIBCLANG_DISABLE_CRASH_RECOVERY": "1"
|
||||||
environment "DYLD_LIBRARY_PATH": "${prj.llvmInstallPath}/lib"
|
environment "DYLD_LIBRARY_PATH": "${prj.llvmInstallPath}/lib"
|
||||||
|
|
||||||
inputs.files prj.fileTree(srcDir.path).include('**/*.def')
|
|
||||||
|
|
||||||
outputs.dir generatedSrcDir
|
outputs.dir generatedSrcDir
|
||||||
outputs.dir nativeLibsDir
|
outputs.dir nativeLibsDir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prj.afterEvaluate {
|
||||||
|
prj.tasks.getByName(genStubsTaskName) {
|
||||||
|
// TODO: handle other source sets
|
||||||
|
prj.sourceSets.main.kotlin.srcDirs.each { srcDir ->
|
||||||
|
inputs.files prj.fileTree(srcDir.path).include('**/*.def')
|
||||||
|
args srcDir
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
prj.sourceSets {
|
prj.sourceSets {
|
||||||
main {
|
main {
|
||||||
kotlin {
|
kotlin {
|
||||||
|
|||||||
Reference in New Issue
Block a user