From 3dda02459df53b82dcd10445aea5636232e0df00 Mon Sep 17 00:00:00 2001 From: "Alexander.Likhachev" Date: Wed, 14 Oct 2020 00:20:17 +0300 Subject: [PATCH] [Gradle, K/N] Add more cases for cinterop test --- .../kotlin/gradle/native/GeneralNativeIT.kt | 37 ++++++++++--------- .../testProject/native-cinterop/build.gradle | 14 ++++++- .../projectLibrary/build.gradle | 21 +++++++++++ .../src/hostMain/kotlin/main.kt | 10 +++++ .../src/hostTest/kotlin/test.kt | 12 ++++++ .../nativeInterop/cinterop/anotherNumber.def | 11 ++++++ .../publishedLibrary/build.gradle | 32 ++++++++++++++++ .../src/hostMain/kotlin/main.kt | 10 +++++ .../src/hostTest/kotlin/test.kt | 12 ++++++ .../src/nativeInterop/cinterop/number.def | 0 .../native-cinterop/settings.gradle | 3 ++ .../src/hostMain/kotlin/main.kt | 10 +++-- .../src/hostTest/kotlin/test.kt | 6 ++- .../src/nativeInterop/cinterop/testNumber.def | 7 ++++ 14 files changed, 161 insertions(+), 24 deletions(-) create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/projectLibrary/build.gradle create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/projectLibrary/src/hostMain/kotlin/main.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/projectLibrary/src/hostTest/kotlin/test.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/projectLibrary/src/nativeInterop/cinterop/anotherNumber.def create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/publishedLibrary/build.gradle create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/publishedLibrary/src/hostMain/kotlin/main.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/publishedLibrary/src/hostTest/kotlin/test.kt rename libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/{ => publishedLibrary}/src/nativeInterop/cinterop/number.def (100%) create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/src/nativeInterop/cinterop/testNumber.def diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/GeneralNativeIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/GeneralNativeIT.kt index 66873073464..5b1fad29f70 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/GeneralNativeIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/GeneralNativeIT.kt @@ -687,24 +687,27 @@ class GeneralNativeIT : BaseGradleIT() { } @Test - fun testCinterop() { - with(transformNativeTestProjectWithPluginDsl("native-cinterop")) { - build(":build") { - assertSuccessful() - 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") - } + fun testCinterop() = with(transformNativeTestProjectWithPluginDsl("native-cinterop")) { + fun libraryFiles(projectName: String, cinteropName: String) = listOf( + "$projectName/build/classes/kotlin/host/main/${projectName}-cinterop-$cinteropName.klib", + "$projectName/build/classes/kotlin/host/main/${projectName}.klib", + "$projectName/build/classes/kotlin/host/test/${projectName}_test.klib", + ) - // Check that changing the compiler version in properties causes interop reprocessing and source recompilation. - val hostLibraryTasks = listOf( - ":cinteropNumberHost", - ":compileKotlinHost" - ) - build(":build") { - assertSuccessful() - assertTasksUpToDate(hostLibraryTasks) - } + build(":projectLibrary:build") { + assertSuccessful() + assertTasksExecuted(":projectLibrary:cinteropAnotherNumberHost") + libraryFiles("projectLibrary", "anotherNumber").forEach { assertFileExists(it) } + } + + build(":publishedLibrary:build", ":publishedLibrary:publish") { + assertSuccessful() + assertTasksExecuted(":publishedLibrary:cinteropNumberHost") + libraryFiles("publishedLibrary", "number").forEach { assertFileExists(it) } + } + + build(":build") { + assertSuccessful() } } diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/build.gradle index 688d5227ebd..e271e0722f0 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/build.gradle +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/build.gradle @@ -5,12 +5,22 @@ plugins { repositories { mavenLocal() jcenter() + maven { url 'repo' } } kotlin { + sourceSets { + hostMain { + dependencies { + implementation project(':projectLibrary') + implementation 'org.example:publishedLibrary:1.0' + } + } + } + ("host") { - compilations.main.cinterops { - number { + compilations.test.cinterops { + testNumber { packageName 'example.cinterop.project' extraOpts '-nodefaultlibs' compilerOpts '-DEVEN_NUMBER' diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/projectLibrary/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/projectLibrary/build.gradle new file mode 100644 index 00000000000..3d550f5ccf6 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/projectLibrary/build.gradle @@ -0,0 +1,21 @@ +plugins { + id("org.jetbrains.kotlin.multiplatform") + id("maven-publish") +} + +repositories { + mavenLocal() + jcenter() +} + +kotlin { + ("host") { + compilations.main.cinterops { + anotherNumber { + packageName 'library.cinterop.project' + extraOpts '-nodefaultlibs' + compilerOpts '-DEVEN_NUMBER' + } + } + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/projectLibrary/src/hostMain/kotlin/main.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/projectLibrary/src/hostMain/kotlin/main.kt new file mode 100644 index 00000000000..0336aafc164 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/projectLibrary/src/hostMain/kotlin/main.kt @@ -0,0 +1,10 @@ +/* + * 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 library.cinterop.project + +fun projectAnswer(): Int { + return getAnotherNumber() * 2 +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/projectLibrary/src/hostTest/kotlin/test.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/projectLibrary/src/hostTest/kotlin/test.kt new file mode 100644 index 00000000000..97f197000a5 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/projectLibrary/src/hostTest/kotlin/test.kt @@ -0,0 +1,12 @@ +/* + * 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 library.cinterop.project + +import kotlin.test.* + +@Test +fun testAnswer() { + assertEquals(8, projectAnswer()) +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/projectLibrary/src/nativeInterop/cinterop/anotherNumber.def b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/projectLibrary/src/nativeInterop/cinterop/anotherNumber.def new file mode 100644 index 00000000000..f73bad1c966 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/projectLibrary/src/nativeInterop/cinterop/anotherNumber.def @@ -0,0 +1,11 @@ +compilerOpts.osx = -D_ANSI_SOURCE +--- + +int getAnotherNumber() +{ + #ifdef EVEN_NUMBER + return 4; + #else + return 3; + #endif +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/publishedLibrary/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/publishedLibrary/build.gradle new file mode 100644 index 00000000000..9de450b08c8 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/publishedLibrary/build.gradle @@ -0,0 +1,32 @@ +plugins { + id("org.jetbrains.kotlin.multiplatform") + id("maven-publish") +} + +group = 'org.example' +version = '1.0' + +repositories { + mavenLocal() + jcenter() +} + +kotlin { + ("host") { + compilations.main.cinterops { + number { + packageName 'library.cinterop.project' + extraOpts '-nodefaultlibs' + compilerOpts '-DEVEN_NUMBER' + } + } + } +} + +publishing { + repositories { + maven { + url = '../repo' + } + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/publishedLibrary/src/hostMain/kotlin/main.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/publishedLibrary/src/hostMain/kotlin/main.kt new file mode 100644 index 00000000000..2dc523e07a1 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/publishedLibrary/src/hostMain/kotlin/main.kt @@ -0,0 +1,10 @@ +/* + * 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 library.cinterop.project + +fun publishedAnswer(): Int { + return getNumber() * 2 +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/publishedLibrary/src/hostTest/kotlin/test.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/publishedLibrary/src/hostTest/kotlin/test.kt new file mode 100644 index 00000000000..3d2eaa6ee43 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/publishedLibrary/src/hostTest/kotlin/test.kt @@ -0,0 +1,12 @@ +/* + * 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 library.cinterop.project + +import kotlin.test.* + +@Test +fun testAnswer() { + assertEquals(4, publishedAnswer()) +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/src/nativeInterop/cinterop/number.def b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/publishedLibrary/src/nativeInterop/cinterop/number.def similarity index 100% rename from libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/src/nativeInterop/cinterop/number.def rename to libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/publishedLibrary/src/nativeInterop/cinterop/number.def diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/settings.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/settings.gradle index 0bd00ea71d9..4a595d2ce1b 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/settings.gradle +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/settings.gradle @@ -9,3 +9,6 @@ pluginManagement { enableFeaturePreview('GRADLE_METADATA') rootProject.name = "native-cinterop" + +include 'projectLibrary' +include 'publishedLibrary' \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/src/hostMain/kotlin/main.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/src/hostMain/kotlin/main.kt index ba8c53799bb..c7226eb9275 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/src/hostMain/kotlin/main.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/src/hostMain/kotlin/main.kt @@ -5,8 +5,12 @@ package example.cinterop.project -import example.cinterop.project.* +import library.cinterop.project.* -fun answer(): Int { - return getNumber() * 2 +fun libraryAnswer(): Int { + return publishedAnswer() + projectAnswer() +} + +fun selfCalculatedAnswer(): Int { + return getNumber() * 2 + getAnotherNumber() * 2 } diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/src/hostTest/kotlin/test.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/src/hostTest/kotlin/test.kt index a11af7afd41..0780d842432 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/src/hostTest/kotlin/test.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/src/hostTest/kotlin/test.kt @@ -7,6 +7,8 @@ package example.cinterop.project import kotlin.test.* @Test -fun compilerOptsTest() { - assertEquals(4, answer()) +fun testAnswer() { + assertEquals(12, libraryAnswer()) + assertEquals(12, selfCalculatedAnswer()) + assertEquals(5, getTestNumber()) } diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/src/nativeInterop/cinterop/testNumber.def b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/src/nativeInterop/cinterop/testNumber.def new file mode 100644 index 00000000000..3d90e611dd9 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-cinterop/src/nativeInterop/cinterop/testNumber.def @@ -0,0 +1,7 @@ +compilerOpts.osx = -D_ANSI_SOURCE +--- + +int getTestNumber() +{ + return 5; +} \ No newline at end of file