Support OptionalExpectation in native

This commit is contained in:
Ilya Matveev
2018-09-17 14:30:14 +03:00
parent 7d5a304cf6
commit a2c5c515de
7 changed files with 58 additions and 26 deletions
@@ -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
}
@@ -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: "))
@@ -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
}
}
}
@@ -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
@@ -146,7 +146,7 @@ internal class KonanInteropRunner(project: Project, additionalJvmArgs: List<Stri
if (HostManager.host == KonanTarget.MINGW_X64) {
//TODO: Oh-ho-ho fix it in more convinient way.
environment.put("PATH", DependencyDirectories.defaultDependenciesRoot.absolutePath +
"\\msys2-mingw-w64-x86_64-gcc-7.2.0-clang-llvm-5.0.0-windows-x86-64" +
"\\msys2-mingw-w64-x86_64-gcc-7.3.0-clang-llvm-lld-6.0.1" +
"\\bin;${environment.get("PATH")}")
}
}
@@ -11,6 +11,8 @@ import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project
import org.gradle.api.attributes.AttributeContainer
import org.gradle.api.file.FileCollection
import org.gradle.api.file.FileTree
import org.gradle.api.file.SourceDirectorySet
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.SourceSetOutput
import org.gradle.util.ConfigureUtil
@@ -272,11 +274,14 @@ class KotlinNativeCompilation(
private val project: Project
get() = target.project
// A FileCollection containing source files from all source sets used by this compilation
// A collection containing all source sets used by this compilation
// (taking into account dependencies between source sets). Used by both compilation
// and linking tasks.
// and linking tasks. Unlike kotlinSourceSets, includes dependency source sets.
// TODO: Move into the compilation task when the linking task does klib linking instead of compilation.
internal var allSources: FileCollection = target.project.files()
internal val allSources: MutableSet<SourceDirectorySet> = mutableSetOf()
// TODO: Move into the compilation task when the linking task does klib linking instead of compilation.
internal val commonSources: MutableSet<SourceDirectorySet> = 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)
}
}
}
@@ -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)