diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt index 3c0b110a1f7..d3c44b22440 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt @@ -312,9 +312,9 @@ abstract class BaseGradleIT { return this } - fun CompiledProject.assertContains(vararg expected: String): CompiledProject { + fun CompiledProject.assertContains(vararg expected: String, ignoreCase: Boolean = false): CompiledProject { for (str in expected) { - assertTrue(output.contains(str.normalize()), "Output should contain '$str'") + assertTrue(output.contains(str.normalize(), ignoreCase), "Output should contain '$str'") } return this } diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt index 7958dd60088..c22cf69a0fe 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt @@ -477,21 +477,31 @@ class NewMultiplatformIT : BaseGradleIT() { """.trimIndent() ) - build("compileKotlinJvmWithoutJava") { + build("compileKotlinJvmWithoutJava", "compileKotlin${nativeHostTargetName.capitalize()}") { assertSuccessful() assertFileExists(targetClassesDir("jvmWithoutJava") + "OptionalCommonUsage.class") } - projectDir.resolve("src/jvmWithoutJavaMain/kotlin/OptionalImpl.kt").writeText( - "\n" + """ + val optionalImplText = "\n" + """ @Optional("should fail, see KT-25196") class OptionalPlatformUsage - """.trimIndent() - ) + """.trimIndent() + + projectDir.resolve("src/jvmWithoutJavaMain/kotlin/OptionalImpl.kt").writeText(optionalImplText) build("compileKotlinJvmWithoutJava") { assertFailed() - assertContains("Declaration annotated with '@OptionalExpectation' can only be used in common module sources") + assertContains("Declaration annotated with '@OptionalExpectation' can only be used in common module sources", ignoreCase = true) + } + + projectDir.resolve("src/${nativeHostTargetName}Main/kotlin/").also { + it.mkdirs() + it.resolve("OptionalImpl.kt").writeText(optionalImplText) + } + + build("compileKotlin${nativeHostTargetName.capitalize()}") { + assertFailed() + assertContains("Declaration annotated with '@OptionalExpectation' can only be used in common module sources", ignoreCase = true) } } @@ -620,7 +630,7 @@ class NewMultiplatformIT : BaseGradleIT() { @Test fun testNativeCompilerDownloading() { // The plugin shouldn't download the K/N compiler if there is no corresponding targets in the project. - with(Project("new-mpp-lib-with-tests", gradleVersion)) { + with(Project("sample-old-style-app", gradleVersion, "new-mpp-lib-and-app")) { build("tasks") { assertSuccessful() assertFalse(output.contains("Kotlin/Native distribution: ")) diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/build.gradle index 6eeb0b048cb..8658a0705cd 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/build.gradle +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/build.gradle @@ -22,8 +22,11 @@ repositories { kotlin { targets { fromPreset(presets.jvm, 'jvmWithoutJava') - fromPreset(presets.jvmWithJava, 'jvmWithJava') + fromPreset(presets.jvmWithJava, 'jvmWithJava') fromPreset(presets.js, 'js') + fromPreset(presets.macosX64, 'macos64') + fromPreset(presets.linuxX64, 'linux64') + fromPreset(presets.mingwX64, 'mingw64') } sourceSets { commonTest { @@ -48,5 +51,9 @@ kotlin { implementation 'org.jetbrains.kotlin:kotlin-test-js' } } + nativeMain + configure([macos64Main, linux64Main, mingw64Main]) { + dependsOn nativeMain + } } } \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/src/nativeMain/kotlin/main.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/src/nativeMain/kotlin/main.kt new file mode 100644 index 00000000000..03f197bff01 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/src/nativeMain/kotlin/main.kt @@ -0,0 +1,8 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package com.example.lib + +actual fun expectedFun() = Unit \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/KotlinNativeToolRunner.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/KotlinNativeToolRunner.kt index 64163ee527c..7ad4c367a94 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/KotlinNativeToolRunner.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/KotlinNativeToolRunner.kt @@ -146,7 +146,7 @@ internal class KonanInteropRunner(project: Project, additionalJvmArgs: List = mutableSetOf() + + // TODO: Move into the compilation task when the linking task does klib linking instead of compilation. + internal val commonSources: MutableSet = mutableSetOf() var isTestCompilation = false @@ -399,8 +404,10 @@ class KotlinNativeCompilation( ) override fun addSourcesToCompileTask(sourceSet: KotlinSourceSet, addAsCommonSources: Boolean) { - // TODO: support optional expectations - allSources += sourceSet.kotlin + allSources.add(sourceSet.kotlin) + if (addAsCommonSources) { + commonSources.add(sourceSet.kotlin) + } } } diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinNativeTasks.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinNativeTasks.kt index c778eed386a..c36e28183ee 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinNativeTasks.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinNativeTasks.kt @@ -96,13 +96,13 @@ open class KotlinNativeCompile : AbstractCompile() { lateinit var outputKind: CompilerOutputKind // Inputs and outputs + @InputFiles + @SkipWhenEmpty + override fun getSource(): FileTree = project.files(compilation.allSources).asFileTree - override fun getSource(): FileTree = sources.asFileTree - - val sources: FileCollection - @InputFiles - @SkipWhenEmpty - get() = compilation.allSources + private val commonSources: FileCollection + // Already taken into account in getSources method. + get() = project.files(compilation.commonSources).asFileTree val libraries: FileCollection @InputFiles get() = compilation.compileDependencyFiles @@ -190,7 +190,7 @@ open class KotlinNativeCompile : AbstractCompile() { // Language features. addArgIfNotNull("-language-version", languageVersion) addArgIfNotNull("-api-version", apiVersion) - addKey("-Xprogressive", progressiveMode) + addKey("-progressive", progressiveMode) enabledLanguageFeatures.forEach { featureName -> add("-XXLanguage:+$featureName") } @@ -221,11 +221,11 @@ open class KotlinNativeCompile : AbstractCompile() { addArg("-friend-modules", friends.map { it.absolutePath }.joinToString(File.pathSeparator)) } - addListArg("-linkerOpts", linkerOpts) + addListArg("-linker-options", linkerOpts) // Sources. - // TODO: Filter only kt files? - addAll(sources.files.map { it.absolutePath }) + addAll(getSource().map { it.absolutePath }) + add("-Xcommon-sources=${commonSources.map { it.absolutePath }.joinToString(separator = ",")}") } KonanCompilerRunner(project).run(args)