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/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..af76e5a4948 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-20161025.164748-245' + +// (gets applied to this project and all its subprojects) +allprojects { + repositories { + mavenCentral() + maven { + url 'http://oss.sonatype.org/content/repositories/snapshots' + } + } + + 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 { } } -dependencies { - compilerCompile deps - compilerCompile kotlinNativeInterop['llvm'] - compilerCompile kotlinNativeInterop['hash'] - - cli_bcCompile deps - cli_bcCompile sourceSets.compiler.output - - bc_frontendCompile deps -} configurations { - cli_bcRuntime.extendsFrom compilerRuntime + cli_bcRuntime.extendsFrom compilerRuntime + + cli_bc { + extendsFrom cli_bcRuntime + } } +dependencies { + compilerCompile kotlinCompilerModule + compilerCompile kotlinNativeInterop['llvm'].configuration + compilerCompile kotlinNativeInterop['hash'].configuration + + cli_bcCompile "org.jetbrains.kotlin:kotlin-runtime:$kotlin_version" + cli_bcCompile sourceSets.compiler.output + + bc_frontendCompile kotlinCompilerModule + + cli_bc sourceSets.cli_bc.output +} + + 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/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 + } } }) 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 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}", 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) } }