From 33bfb2d06372cd62f790cab1a8a9292e75c9ae20 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Tue, 4 Oct 2016 16:25:18 +0300 Subject: [PATCH] Interop: improve support for multiple source sets in Gradle plugin --- backend.native/build.gradle | 2 +- .../kotlin/NativeInteropPlugin.groovy | 60 +++++++++---------- 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/backend.native/build.gradle b/backend.native/build.gradle index 70b815605c6..8579e55e5f0 100644 --- a/backend.native/build.gradle +++ b/backend.native/build.gradle @@ -84,7 +84,7 @@ repositories { mavenCentral() } -genInteropStubs { +genCompilerInteropStubs { environment 'CPATH' : "$llvmInstallPath/include" environment 'LIBRARY_PATH' : "$llvmInstallPath/lib" } diff --git a/buildSrc/src/main/groovy/org/jetbrains/kotlin/NativeInteropPlugin.groovy b/buildSrc/src/main/groovy/org/jetbrains/kotlin/NativeInteropPlugin.groovy index 6066f13e798..d021f5f4de0 100644 --- a/buildSrc/src/main/groovy/org/jetbrains/kotlin/NativeInteropPlugin.groovy +++ b/buildSrc/src/main/groovy/org/jetbrains/kotlin/NativeInteropPlugin.groovy @@ -8,7 +8,6 @@ class NativeInteropPlugin implements Plugin { @Override void apply(Project prj) { - def generatedSrcDir = new File(prj.buildDir, "nativeInteropStubs/kotlin") def nativeLibsDir = new File(prj.buildDir, "nativelibs") prj.configurations { @@ -16,52 +15,49 @@ class NativeInteropPlugin implements Plugin { } prj.dependencies { - compile project(path: ':Interop:Runtime') 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) { - classpath = prj.configurations.interopStubGenerator - 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" + prj.dependencies { + add sourceSet.getCompileConfigurationName(), project(path: ':Interop:Runtime') + } - outputs.dir generatedSrcDir - outputs.dir nativeLibsDir - } + def genStubsTask = prj.task(sourceSet.getTaskName("gen", "interopStubs"), type: JavaExec) { + 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 { - prj.tasks.getByName(genStubsTaskName) { - // TODO: handle other source sets - prj.sourceSets.each { - it.kotlin.srcDirs.each { srcDir -> - inputs.files prj.fileTree(srcDir.path).include('**/*.def') - args srcDir + outputs.dir generatedSrcDir + outputs.dir nativeLibsDir + + args = [generatedSrcDir, nativeLibsDir] + + prj.afterEvaluate { // FIXME: it is a hack + sourceSet.kotlin.srcDirs.each { srcDir -> + if (srcDir != generatedSrcDir) { + args srcDir + inputs.files prj.fileTree(srcDir.path).include('**/*.def') + } } } } - } - prj.sourceSets { - main { - kotlin { - srcDirs generatedSrcDir - } + sourceSet.kotlin.srcDirs generatedSrcDir + + prj.tasks.getByName(sourceSet.getTaskName("compile", "Kotlin")) { + dependsOn genStubsTask } } - prj.tasks.getByName("compileKotlin") { - dependsOn genStubsTaskName - } - // FIXME: choose tasks more wisely prj.tasks.withType(JavaExec) { - if (name != genStubsTaskName) { + if (!name.endsWith("InteropStubs")) { systemProperties "java.library.path": nativeLibsDir } }