[Gradle, K/N] Simplify native cinterop test
This commit is contained in:
+8
-54
@@ -646,68 +646,22 @@ class GeneralNativeIT : BaseGradleIT() {
|
||||
|
||||
@Test
|
||||
fun testCinterop() {
|
||||
val libProject = Project("sample-lib", directoryPrefix = "new-mpp-lib-and-app")
|
||||
libProject.build("publish") {
|
||||
assertSuccessful()
|
||||
}
|
||||
val repo = libProject.projectDir.resolve("repo").absolutePath.replace('\\', '/')
|
||||
|
||||
with(Project("native-cinterop")) {
|
||||
|
||||
setupWorkingDir()
|
||||
listOf(gradleBuildScript(), gradleBuildScript("publishedLibrary")).forEach {
|
||||
it.appendText(
|
||||
"""
|
||||
repositories {
|
||||
maven { url '$repo' }
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
val targetsToBuild = if (HostManager.hostIsMingw) {
|
||||
listOf(nativeHostTargetName, "mingw86")
|
||||
} else {
|
||||
listOf(nativeHostTargetName)
|
||||
}
|
||||
|
||||
val libraryCinteropTasks = targetsToBuild.map { ":projectLibrary:cinteropStdio${it.capitalize()}" }
|
||||
val libraryCompileTasks = targetsToBuild.map { ":projectLibrary:compileKotlin${it.capitalize()}" }
|
||||
|
||||
build(":projectLibrary:build") {
|
||||
assertSuccessful()
|
||||
assertTasksExecuted(libraryCinteropTasks)
|
||||
assertTrue(output.contains("Project test"), "No test output found")
|
||||
targetsToBuild.forEach {
|
||||
assertFileExists("projectLibrary/build/classes/kotlin/$it/main/projectLibrary-cinterop-stdio.klib")
|
||||
}
|
||||
}
|
||||
|
||||
build(":publishedLibrary:build", ":publishedLibrary:publish") {
|
||||
assertSuccessful()
|
||||
assertTasksExecuted(
|
||||
targetsToBuild.map { ":publishedLibrary:cinteropStdio${it.capitalize()}" }
|
||||
)
|
||||
assertTrue(output.contains("Published test"), "No test output found")
|
||||
targetsToBuild.forEach {
|
||||
assertFileExists("publishedLibrary/build/classes/kotlin/$it/main/publishedLibrary-cinterop-stdio.klib")
|
||||
assertFileExists("publishedLibrary/build/classes/kotlin/$it/test/test-cinterop-stdio.klib")
|
||||
assertFileExists("repo/org/example/publishedLibrary-$it/1.0/publishedLibrary-$it-1.0-cinterop-stdio.klib")
|
||||
}
|
||||
}
|
||||
with(transformProjectWithPluginsDsl("native-cinterop")) {
|
||||
configureSingleNativeTarget()
|
||||
|
||||
build(":build") {
|
||||
assertSuccessful()
|
||||
assertTrue(output.contains("Dependent: Project print"), "No test output found")
|
||||
assertTrue(output.contains("Dependent: Published print"), "No test output found")
|
||||
assertFileExists("build/libs/host/main/native-cinterop-cinterop-number.klib")
|
||||
assertFileExists("build/classes/kotlin/host/main/native-cinterop-cinterop-number.klib")
|
||||
assertFileExists("build/classes/kotlin/host/test/native-cinterop_test.klib")
|
||||
}
|
||||
|
||||
// Check that changing the compiler version in properties causes interop reprocessing and source recompilation.
|
||||
val hostLibraryTasks = listOf(
|
||||
":projectLibrary:cinteropStdio${nativeHostTargetName.capitalize()}",
|
||||
":projectLibrary:compileKotlin${nativeHostTargetName.capitalize()}"
|
||||
":cinteropNumberHost",
|
||||
":compileKotlinHost"
|
||||
)
|
||||
build(":projectLibrary:build") {
|
||||
build(":build") {
|
||||
assertSuccessful()
|
||||
assertTasksUpToDate(hostLibraryTasks)
|
||||
}
|
||||
|
||||
+8
-36
@@ -1,48 +1,20 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
plugins {
|
||||
id("org.jetbrains.kotlin.multiplatform").version("<pluginMarkerVersion>")
|
||||
}
|
||||
|
||||
|
||||
apply plugin: 'kotlin-multiplatform'
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
maven { url 'repo' }
|
||||
}
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
allNative {
|
||||
dependencies {
|
||||
implementation project(':projectLibrary')
|
||||
implementation 'org.example:publishedLibrary:1.0'
|
||||
<SingleNativeTarget>("host") {
|
||||
compilations.main.cinterops {
|
||||
number {
|
||||
packageName 'example.cinterop.project'
|
||||
extraOpts '-nodefaultlibs'
|
||||
compilerOpts '-DEVEN_NUMBER'
|
||||
}
|
||||
}
|
||||
nativeTest
|
||||
|
||||
macos64Main { dependsOn sourceSets.allNative }
|
||||
linux64Main { dependsOn sourceSets.allNative }
|
||||
mingw64Main { dependsOn sourceSets.allNative }
|
||||
mingw86Main { dependsOn sourceSets.allNative }
|
||||
|
||||
macos64Test { dependsOn sourceSets.nativeTest }
|
||||
linux64Test { dependsOn sourceSets.nativeTest }
|
||||
mingw64Test { dependsOn sourceSets.nativeTest }
|
||||
mingw86Test { dependsOn sourceSets.nativeTest }
|
||||
}
|
||||
|
||||
targets {
|
||||
fromPreset(presets.macosX64, 'macos64')
|
||||
fromPreset(presets.linuxX64, 'linux64')
|
||||
fromPreset(presets.mingwX64, 'mingw64')
|
||||
// Test building a 32-bit Windows binary.
|
||||
fromPreset(presets.mingwX86, 'mingw86')
|
||||
}
|
||||
}
|
||||
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
apply plugin: 'kotlin-multiplatform'
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
}
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
allNative
|
||||
nativeTest
|
||||
|
||||
macos64Main { dependsOn sourceSets.allNative }
|
||||
linux64Main { dependsOn sourceSets.allNative }
|
||||
mingw64Main { dependsOn sourceSets.allNative }
|
||||
mingw86Main { dependsOn sourceSets.allNative }
|
||||
|
||||
macos64Test { dependsOn sourceSets.nativeTest }
|
||||
linux64Test { dependsOn sourceSets.nativeTest }
|
||||
mingw64Test { dependsOn sourceSets.nativeTest }
|
||||
mingw86Test { dependsOn sourceSets.nativeTest }
|
||||
}
|
||||
|
||||
targets {
|
||||
fromPreset(presets.macosX64, 'macos64')
|
||||
fromPreset(presets.linuxX64, 'linux64')
|
||||
fromPreset(presets.mingwX64, 'mingw64')
|
||||
// Test building a 32-bit Windows binary.
|
||||
fromPreset(presets.mingwX86, 'mingw86')
|
||||
|
||||
configure([macos64, linux64, mingw64, mingw86]) {
|
||||
compilations.main.cinterops {
|
||||
stdio {
|
||||
packageName 'example.cinterop.project.stdio'
|
||||
extraOpts '-nodefaultlibs'
|
||||
compilerOpts '-DEVEN_NUMBER'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-64
@@ -1,64 +0,0 @@
|
||||
apply plugin: 'kotlin-multiplatform'
|
||||
apply plugin: 'maven-publish'
|
||||
|
||||
group = 'org.example'
|
||||
version = '1.0'
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
}
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
allNative {
|
||||
dependencies {
|
||||
implementation 'com.example:sample-lib:1.0'
|
||||
}
|
||||
}
|
||||
nativeTest
|
||||
|
||||
macos64Main { dependsOn sourceSets.allNative }
|
||||
linux64Main { dependsOn sourceSets.allNative }
|
||||
mingw64Main { dependsOn sourceSets.allNative }
|
||||
mingw86Main { dependsOn sourceSets.allNative }
|
||||
|
||||
macos64Test { dependsOn sourceSets.nativeTest }
|
||||
linux64Test { dependsOn sourceSets.nativeTest }
|
||||
mingw64Test { dependsOn sourceSets.nativeTest }
|
||||
mingw86Test { dependsOn sourceSets.nativeTest }
|
||||
}
|
||||
|
||||
targets {
|
||||
fromPreset(presets.macosX64, 'macos64')
|
||||
fromPreset(presets.linuxX64, 'linux64')
|
||||
fromPreset(presets.mingwX64, 'mingw64')
|
||||
// Test building a 32-bit Windows binary.
|
||||
fromPreset(presets.mingwX86, 'mingw86')
|
||||
|
||||
configure([macos64, linux64, mingw64, mingw86]) {
|
||||
compilations.all {
|
||||
// Add interop in the test compilation too as a regression test for KT-30290.
|
||||
cinterops {
|
||||
stdio {
|
||||
packageName 'example.cinterop.published.stdio'
|
||||
extraOpts '-nodefaultlibs'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// We don't create test tasks for Windows x86. But we still want to test
|
||||
// generating interop for it, so we add this dependency.
|
||||
build.dependsOn 'linkDebugTestMingw86'
|
||||
|
||||
publishing {
|
||||
repositories {
|
||||
maven {
|
||||
url = '../repo'
|
||||
}
|
||||
}
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package example.cinterop.published
|
||||
|
||||
import example.cinterop.published.stdio.*
|
||||
import com.example.lib.*
|
||||
|
||||
fun publishedPrint(str: String) {
|
||||
printf(str + '\n')
|
||||
println(id(42))
|
||||
}
|
||||
-2
@@ -1,2 +0,0 @@
|
||||
headers = stdio.h
|
||||
compilerOpts.osx = -D_ANSI_SOURCE
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
package example.cinterop.published
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun publishedTest() {
|
||||
publishedPrint("Published test")
|
||||
}
|
||||
+9
-4
@@ -1,6 +1,11 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
enableFeaturePreview('GRADLE_METADATA')
|
||||
|
||||
rootProject.name = 'native-cinterop'
|
||||
|
||||
include 'projectLibrary'
|
||||
include 'publishedLibrary'
|
||||
rootProject.name = "native-cinterop"
|
||||
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
import example.cinterop.project.*
|
||||
import example.cinterop.published.*
|
||||
|
||||
fun dependentProject() {
|
||||
projectPrint("Dependent: Project print")
|
||||
publishedPrint("Dependent: Published print")
|
||||
}
|
||||
+3
-3
@@ -5,8 +5,8 @@
|
||||
|
||||
package example.cinterop.project
|
||||
|
||||
import example.cinterop.project.stdio.*
|
||||
import example.cinterop.project.*
|
||||
|
||||
fun projectPrint(str: String) {
|
||||
printf(str + '\n')
|
||||
fun answer(): Int {
|
||||
return getNumber() * 2
|
||||
}
|
||||
+2
-8
@@ -1,18 +1,12 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
package example.cinterop.project
|
||||
|
||||
import kotlin.test.*
|
||||
import example.cinterop.project.stdio.*
|
||||
|
||||
@Test
|
||||
fun projectTest() {
|
||||
projectPrint("Project test")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun compilerOptsTest() {
|
||||
assertEquals(2, getNumber())
|
||||
assertEquals(4, answer())
|
||||
}
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
headers = stdio.h
|
||||
compilerOpts.osx = -D_ANSI_SOURCE
|
||||
---
|
||||
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun dependentTest() {
|
||||
dependentProject()
|
||||
}
|
||||
Reference in New Issue
Block a user