Interop: improve support for multiple source sets in Gradle plugin

This commit is contained in:
Svyatoslav Scherbina
2016-10-04 16:25:18 +03:00
parent df6b4388a0
commit 33bfb2d063
2 changed files with 29 additions and 33 deletions
+1 -1
View File
@@ -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,16 +15,19 @@ 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 {
add sourceSet.getCompileConfigurationName(), project(path: ':Interop:Runtime')
}
def genStubsTask = prj.task(sourceSet.getTaskName("gen", "interopStubs"), 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 = [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"
@@ -33,35 +35,29 @@ class NativeInteropPlugin implements Plugin<Project> {
outputs.dir generatedSrcDir outputs.dir generatedSrcDir
outputs.dir nativeLibsDir outputs.dir nativeLibsDir
}
prj.afterEvaluate { args = [generatedSrcDir, nativeLibsDir]
prj.tasks.getByName(genStubsTaskName) {
// TODO: handle other source sets prj.afterEvaluate { // FIXME: it is a hack
prj.sourceSets.each { sourceSet.kotlin.srcDirs.each { srcDir ->
it.kotlin.srcDirs.each { srcDir -> if (srcDir != generatedSrcDir) {
inputs.files prj.fileTree(srcDir.path).include('**/*.def')
args srcDir args srcDir
inputs.files prj.fileTree(srcDir.path).include('**/*.def')
} }
} }
} }
} }
prj.sourceSets { sourceSet.kotlin.srcDirs generatedSrcDir
main {
kotlin {
srcDirs generatedSrcDir
}
}
}
prj.tasks.getByName("compileKotlin") { prj.tasks.getByName(sourceSet.getTaskName("compile", "Kotlin")) {
dependsOn genStubsTaskName dependsOn genStubsTask
}
} }
// 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
} }
} }