Interop: improve support for multiple source sets in Gradle plugin
This commit is contained in:
@@ -84,7 +84,7 @@ repositories {
|
|||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
genInteropStubs {
|
genCompilerInteropStubs {
|
||||||
environment 'CPATH' : "$llvmInstallPath/include"
|
environment 'CPATH' : "$llvmInstallPath/include"
|
||||||
environment 'LIBRARY_PATH' : "$llvmInstallPath/lib"
|
environment 'LIBRARY_PATH' : "$llvmInstallPath/lib"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ class NativeInteropPlugin implements Plugin<Project> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
void apply(Project prj) {
|
void apply(Project prj) {
|
||||||
def generatedSrcDir = new File(prj.buildDir, "nativeInteropStubs/kotlin")
|
|
||||||
def nativeLibsDir = new File(prj.buildDir, "nativelibs")
|
def nativeLibsDir = new File(prj.buildDir, "nativelibs")
|
||||||
|
|
||||||
prj.configurations {
|
prj.configurations {
|
||||||
@@ -16,52 +15,49 @@ class NativeInteropPlugin implements Plugin<Project> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
prj.dependencies {
|
prj.dependencies {
|
||||||
compile project(path: ':Interop:Runtime')
|
|
||||||
interopStubGenerator project(path: ":Interop:StubGenerator")
|
interopStubGenerator project(path: ":Interop:StubGenerator")
|
||||||
}
|
}
|
||||||
|
|
||||||
def genStubsTaskName = "genInteropStubs"
|
prj.sourceSets.all { sourceSet ->
|
||||||
|
def generatedSrcDir = new File(prj.buildDir, "nativeInteropStubs/${sourceSet.name}/kotlin")
|
||||||
|
|
||||||
prj.task(genStubsTaskName, type: JavaExec) {
|
prj.dependencies {
|
||||||
classpath = prj.configurations.interopStubGenerator
|
add sourceSet.getCompileConfigurationName(), project(path: ':Interop:Runtime')
|
||||||
main = "org.jetbrains.kotlin.native.interop.gen.jvm.MainKt"
|
}
|
||||||
args = [generatedSrcDir, nativeLibsDir]
|
|
||||||
systemProperties "java.library.path" : new File(prj.findProject(":Interop:Indexer").buildDir, "nativelibs")
|
|
||||||
systemProperties "llvmInstallPath" : prj.llvmInstallPath
|
|
||||||
environment "LIBCLANG_DISABLE_CRASH_RECOVERY": "1"
|
|
||||||
environment "DYLD_LIBRARY_PATH": "${prj.llvmInstallPath}/lib"
|
|
||||||
|
|
||||||
outputs.dir generatedSrcDir
|
def genStubsTask = prj.task(sourceSet.getTaskName("gen", "interopStubs"), type: JavaExec) {
|
||||||
outputs.dir nativeLibsDir
|
classpath = prj.configurations.interopStubGenerator
|
||||||
}
|
main = "org.jetbrains.kotlin.native.interop.gen.jvm.MainKt"
|
||||||
|
systemProperties "java.library.path" : new File(prj.findProject(":Interop:Indexer").buildDir, "nativelibs")
|
||||||
|
systemProperties "llvmInstallPath" : prj.llvmInstallPath
|
||||||
|
environment "LIBCLANG_DISABLE_CRASH_RECOVERY": "1"
|
||||||
|
environment "DYLD_LIBRARY_PATH": "${prj.llvmInstallPath}/lib"
|
||||||
|
|
||||||
prj.afterEvaluate {
|
outputs.dir generatedSrcDir
|
||||||
prj.tasks.getByName(genStubsTaskName) {
|
outputs.dir nativeLibsDir
|
||||||
// TODO: handle other source sets
|
|
||||||
prj.sourceSets.each {
|
args = [generatedSrcDir, nativeLibsDir]
|
||||||
it.kotlin.srcDirs.each { srcDir ->
|
|
||||||
inputs.files prj.fileTree(srcDir.path).include('**/*.def')
|
prj.afterEvaluate { // FIXME: it is a hack
|
||||||
args srcDir
|
sourceSet.kotlin.srcDirs.each { srcDir ->
|
||||||
|
if (srcDir != generatedSrcDir) {
|
||||||
|
args srcDir
|
||||||
|
inputs.files prj.fileTree(srcDir.path).include('**/*.def')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
prj.sourceSets {
|
sourceSet.kotlin.srcDirs generatedSrcDir
|
||||||
main {
|
|
||||||
kotlin {
|
prj.tasks.getByName(sourceSet.getTaskName("compile", "Kotlin")) {
|
||||||
srcDirs generatedSrcDir
|
dependsOn genStubsTask
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prj.tasks.getByName("compileKotlin") {
|
|
||||||
dependsOn genStubsTaskName
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: choose tasks more wisely
|
// FIXME: choose tasks more wisely
|
||||||
prj.tasks.withType(JavaExec) {
|
prj.tasks.withType(JavaExec) {
|
||||||
if (name != genStubsTaskName) {
|
if (!name.endsWith("InteropStubs")) {
|
||||||
systemProperties "java.library.path": nativeLibsDir
|
systemProperties "java.library.path": nativeLibsDir
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user