From 74ab1503c3d999995c9307996216462ad505473d Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Mon, 31 Oct 2016 12:57:45 +0700 Subject: [PATCH 1/5] Interop: make gradle plugin more friendly to complex dependency management when representing dependencies as file collection some meta information gets lost --- InteropExample/build.gradle | 2 +- backend.native/build.gradle | 4 ++-- .../kotlin/NativeInteropPlugin.groovy | 23 ++++++------------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/InteropExample/build.gradle b/InteropExample/build.gradle index 4b06b429071..86dbc1c0d11 100644 --- a/InteropExample/build.gradle +++ b/InteropExample/build.gradle @@ -27,7 +27,7 @@ kotlinNativeInterop { dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - compile kotlinNativeInterop['llvm'] + compile kotlinNativeInterop['llvm'].configuration } mainClassName = 'MainKt' diff --git a/backend.native/build.gradle b/backend.native/build.gradle index c42c9adb3cc..b5a9728561f 100644 --- a/backend.native/build.gradle +++ b/backend.native/build.gradle @@ -105,8 +105,8 @@ kotlinNativeInterop { dependencies { compilerCompile deps - compilerCompile kotlinNativeInterop['llvm'] - compilerCompile kotlinNativeInterop['hash'] + compilerCompile kotlinNativeInterop['llvm'].configuration + compilerCompile kotlinNativeInterop['hash'].configuration cli_bcCompile deps cli_bcCompile sourceSets.compiler.output diff --git a/buildSrc/src/main/groovy/org/jetbrains/kotlin/NativeInteropPlugin.groovy b/buildSrc/src/main/groovy/org/jetbrains/kotlin/NativeInteropPlugin.groovy index 4d9a0b70307..38688fcc90c 100644 --- a/buildSrc/src/main/groovy/org/jetbrains/kotlin/NativeInteropPlugin.groovy +++ b/buildSrc/src/main/groovy/org/jetbrains/kotlin/NativeInteropPlugin.groovy @@ -4,6 +4,7 @@ import org.gradle.api.Named import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.Task +import org.gradle.api.artifacts.Configuration import org.gradle.api.file.FileCollection import org.gradle.api.internal.AbstractNamedDomainObjectContainer import org.gradle.api.internal.file.AbstractFileCollection @@ -12,7 +13,7 @@ import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.TaskDependency import org.gradle.internal.reflect.Instantiator -class NamedNativeInteropConfig extends AbstractFileCollection implements Named { +class NamedNativeInteropConfig implements Named { private final Project project final String name @@ -31,6 +32,8 @@ class NamedNativeInteropConfig extends AbstractFileCollection implements Named { private FileCollection linkFiles; private List linkTasks = [] + Configuration configuration + void defFile(String value) { defFile = value genTask.inputs.file(project.file(defFile)) @@ -117,6 +120,7 @@ class NamedNativeInteropConfig extends AbstractFileCollection implements Named { interopStubs = project.sourceSets.create(name + "InteropStubs") genTask = project.task(interopStubs.getTaskName("gen", ""), type: JavaExec) + configuration = project.configurations.create(interopStubs.name) this.configure() } @@ -178,22 +182,9 @@ class NamedNativeInteropConfig extends AbstractFileCollection implements Named { } } } - } - @Override - String getDisplayName() { - return "Native interop config $name" - } - - @Override - Set getFiles() { - return interopStubs.output.getFiles() + - interopStubs.compileClasspath.files // TODO: workaround to add Interop:Runtime - } - - @Override - TaskDependency getBuildDependencies() { - return interopStubs.output.getBuildDependencies() + this.configuration.extendsFrom project.configurations[interopStubs.runtimeConfigurationName] + project.dependencies.add(this.configuration.name, interopStubs.output) } } From 394b4ce6ecf17ced92a67d88567e8fd830b7661b Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Mon, 31 Oct 2016 13:13:46 +0700 Subject: [PATCH 2/5] backend/build: depend on kotlin-compiler.jar from repo instead of the jars from backend.native/kotlin-ir --- backend.native/build.gradle | 58 +++++++++++++++++++++---------- backend.native/tests/build.gradle | 14 ++++---- 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/backend.native/build.gradle b/backend.native/build.gradle index b5a9728561f..4dd9aa793f3 100644 --- a/backend.native/build.gradle +++ b/backend.native/build.gradle @@ -1,5 +1,4 @@ buildscript { - ext.kotlin_ir_path = "$projectDir/kotlin-ir/dist" repositories { mavenCentral() } @@ -14,11 +13,29 @@ apply plugin: 'java' apply plugin: 'kotlin' apply plugin: org.jetbrains.kotlin.NativeInteropPlugin -def deps = files("$kotlin_ir_path/kotlinc/lib/kotlin-compiler.jar", - "$kotlin_ir_path/kotlinc/lib/kotlin-runtime.jar", - "$kotlin_ir_path/kotlinc/lib/kotlin-reflect.jar") -//export dependencies jars -ext['deps'] = deps +String kotlinCompilerModule = 'org.jetbrains.kotlin:kotlin-compiler:1.1.0-dev-4137' + +// (gets applied to this project and all its subprojects) +allprojects { + repositories { + mavenCentral() + maven { + url "http://dl.bintray.com/kotlin/kotlin-dev" + } + } + + configurations.all { + // kotlin-compiler module includes Kotlin runtime bundled; + // make Gradle aware of this to avoid multiple Kotlin runtimes in classpath: + resolutionStrategy.dependencySubstitution { + substitute module('org.jetbrains.kotlin:kotlin-runtime') with module(kotlinCompilerModule) + substitute module('org.jetbrains.kotlin:kotlin-stdlib') with module(kotlinCompilerModule) + substitute module('org.jetbrains.kotlin:kotlin-reflect') with module(kotlinCompilerModule) + } + // TODO: probably we should use kotlin-compiler without bundled runtime + } + +} sourceSets { compiler { @@ -103,27 +120,35 @@ kotlinNativeInterop { } } + +configurations { + cli_bcRuntime.extendsFrom compilerRuntime + + cli_bc { + extendsFrom cli_bcRuntime + } +} + dependencies { - compilerCompile deps + compilerCompile kotlinCompilerModule compilerCompile kotlinNativeInterop['llvm'].configuration compilerCompile kotlinNativeInterop['hash'].configuration - cli_bcCompile deps + cli_bcCompile "org.jetbrains.kotlin:kotlin-runtime:$kotlin_version" cli_bcCompile sourceSets.compiler.output - bc_frontendCompile deps + bc_frontendCompile kotlinCompilerModule + + cli_bc sourceSets.cli_bc.output } -configurations { - cli_bcRuntime.extendsFrom compilerRuntime -} build.dependsOn 'compilerClasses','cli_bcClasses','bc_frontendClasses' task run(type: JavaExec) { main 'org.jetbrains.kotlin.cli.bc.K2NativeKt' - classpath sourceSets.cli_bc.runtimeClasspath + classpath configurations.cli_bc args 'tests/codegen/function/sum.kt' @@ -144,13 +169,10 @@ task run(type: JavaExec) { task jars { - println "kotlin-ir: $kotlin_ir_path" + doFirst { project.buildscript.configurations.classpath.each { String jarName = it.getName(); print jarName + ":" } -} - -repositories { - mavenCentral() + } } diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index b03465588cc..86d234546ec 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -1,6 +1,10 @@ -import org.gradle.api.internal.file.DefaultCompositeFileTree -import org.gradle.api.internal.file.FileTreeInternal +configurations { + cli_bc +} +dependencies { + cli_bc project(path: ':backend.native', configuration: 'cli_bc') +} public class KonanTest extends DefaultTask { protected String source @@ -16,17 +20,13 @@ public class KonanTest extends DefaultTask { @TaskAction public void compileBc() { - def classpathSs = new DefaultCompositeFileTree(new ArrayList()) - project.sourceSets.each{classpathSs += it.output} - project.project(":Interop:Runtime").sourceSets.each{ classpathSs += it.output } - classpathSs += backendNative.ext.deps def sourceKt = project.file(source) def sourceBc = new File("${sourceKt.absolutePath}.bc") def runtimeBc = new File("${runtimeProject.buildDir.canonicalPath}/runtime.bc") println "${runtimeBc}" project.javaexec { main='org.jetbrains.kotlin.cli.bc.K2NativeKt' - classpath = classpathSs + classpath = project.configurations.cli_bc args "-output", "${sourceBc.absolutePath}", "-runtime", "${runtimeBc.absolutePath}", "${sourceKt.absolutePath}", From 1b624ac88f59833852d12f325e6fc5de4798056a Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Mon, 31 Oct 2016 16:01:11 +0700 Subject: [PATCH 3/5] backend: fix building against latest kotlin-compiler.jar --- .../src/org/jetbrains/kotlin/backend/native/ModuleIndex.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/ModuleIndex.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/ModuleIndex.kt index f6d4dd7c1e8..687986d76a4 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/ModuleIndex.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/native/ModuleIndex.kt @@ -27,7 +27,10 @@ class ModuleIndex(val module: IrModuleFragment) { override fun visitClass(declaration: IrClass) { super.visitClass(declaration) - map[declaration.descriptor.classId] = declaration + val classId = declaration.descriptor.classId + if (classId != null) { + map[classId] = declaration + } } }) From 18ae8b231126c39bc3374b70aac4935bb11f0299 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Mon, 31 Oct 2016 15:55:23 +0700 Subject: [PATCH 4/5] build: switch to Sonatype snapshots repo for kotlin-compiler it is updated automatically by every successful build --- backend.native/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend.native/build.gradle b/backend.native/build.gradle index 4dd9aa793f3..af76e5a4948 100644 --- a/backend.native/build.gradle +++ b/backend.native/build.gradle @@ -13,14 +13,14 @@ apply plugin: 'java' apply plugin: 'kotlin' apply plugin: org.jetbrains.kotlin.NativeInteropPlugin -String kotlinCompilerModule = 'org.jetbrains.kotlin:kotlin-compiler:1.1.0-dev-4137' +String kotlinCompilerModule = 'org.jetbrains.kotlin:kotlin-compiler:1.1-20161025.164748-245' // (gets applied to this project and all its subprojects) allprojects { repositories { mavenCentral() maven { - url "http://dl.bintray.com/kotlin/kotlin-dev" + url 'http://oss.sonatype.org/content/repositories/snapshots' } } From 941f3b9bc533d9b2e920dd396c748fbc7e3e3e82 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Mon, 31 Oct 2016 19:51:08 +0700 Subject: [PATCH 5/5] remove backend.native/kotlin-ir submodule --- .gitmodules | 4 ---- backend.native/kotlin-ir | 1 - 2 files changed, 5 deletions(-) delete mode 160000 backend.native/kotlin-ir diff --git a/.gitmodules b/.gitmodules index 432e7cc8d8c..7c9fe241d99 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +1,3 @@ -[submodule "experiments/kotlin-ir"] - path = backend.native/kotlin-ir - url = https://github.com/JetBrains/kotlin.git - branch = master [submodule "third-party/ios/libffi"] path = third-party/ios/libffi url = https://github.com/ksjogo/libffi diff --git a/backend.native/kotlin-ir b/backend.native/kotlin-ir deleted file mode 160000 index 82364ad3e53..00000000000 --- a/backend.native/kotlin-ir +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 82364ad3e537493d4d498bf17044da3df6fdb79f