Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gradle, native: Add a DSL shortcut for iOS, watchsOS and tvOS
This patch adds a group of shortcut DSL methods allowing a user to create simulator and device targets for Apple platforms along with corresponding common source set(s) in one command. iOS, tvOS and watchOS targets are supported. Issue #KT-33856 fixed
- Loading branch information
Showing
39 changed files
with
506 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...le-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/CommonNativeIT.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright 2010-2019 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 org.jetbrains.kotlin.gradle | ||
|
||
import org.jetbrains.kotlin.konan.target.HostManager | ||
import org.junit.Assume | ||
import org.junit.Test | ||
|
||
class CommonNativeIT : BaseGradleIT() { | ||
|
||
private fun doCommonNativeTest( | ||
projectName: String, | ||
libTargets: List<String>, | ||
appTargets: List<String> | ||
) = with(transformProjectWithPluginsDsl(projectName, directoryPrefix = "new-mpp-common-native")) { | ||
val libCompileTasks = libTargets.map { ":lib:compileKotlin${it.capitalize()}" } | ||
val appCompileTasks = appTargets.map { ":app:compileKotlin${it.capitalize()}" } | ||
val appLinkFrameworkTasks = appTargets.map { ":app:linkDebugFramework${it.capitalize()}" } | ||
val appLinkTestTasks = appTargets.map { ":app:linkDebugTest${it.capitalize()}" } | ||
|
||
build(":lib:publish") { | ||
assertSuccessful() | ||
assertTasksExecuted(libCompileTasks) | ||
libTargets.forEach { | ||
assertContains("Configuring $it") | ||
assertFileExists("lib/build/classes/kotlin/$it/main/lib.klib") | ||
} | ||
} | ||
|
||
build(":app:build", *appLinkTestTasks.toTypedArray()) { | ||
assertSuccessful() | ||
assertTasksExecuted(appCompileTasks) | ||
assertTasksExecuted(appLinkFrameworkTasks) | ||
assertTasksExecuted(appLinkTestTasks) | ||
|
||
appTargets.forEach { | ||
assertFileExists("app/build/classes/kotlin/$it/main/app.klib") | ||
assertFileExists("app/build/bin/$it/debugFramework") | ||
assertFileExists("app/build/bin/$it/debugTest") | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun testCommonIos() { | ||
Assume.assumeTrue(HostManager.hostIsMac) | ||
doCommonNativeTest( | ||
"common-ios", | ||
libTargets = listOf("iosLibArm64", "iosLibX64"), | ||
appTargets = listOf("iosArm64", "iosX64") | ||
) | ||
} | ||
|
||
@Test | ||
fun testCommonWatchos() { | ||
Assume.assumeTrue(HostManager.hostIsMac) | ||
doCommonNativeTest( | ||
"common-watchos", | ||
libTargets = listOf("watchosLibArm32", "watchosLibArm64", "watchosLibX86"), | ||
appTargets = listOf("watchosArm32", "watchosArm64", "watchosX86") | ||
) | ||
} | ||
|
||
@Test | ||
fun testCommonTvos() { | ||
Assume.assumeTrue(HostManager.hostIsMac) | ||
doCommonNativeTest( | ||
"common-tvos", | ||
libTargets = listOf("tvosLibArm64", "tvosLibX64"), | ||
appTargets = listOf("tvosArm64", "tvosX64") | ||
) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...ests/src/test/resources/testProject/new-mpp-common-native/common-ios/app/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
plugins { | ||
id("org.jetbrains.kotlin.multiplatform").version("<pluginMarkerVersion>") | ||
} | ||
|
||
repositories { | ||
mavenLocal() | ||
jcenter() | ||
maven { setUrl(rootProject.projectDir.resolve("repo")) } | ||
} | ||
|
||
kotlin { | ||
ios() | ||
|
||
// Check that we can reenter the configuration method. | ||
ios { | ||
binaries.framework(listOf(DEBUG)) | ||
} | ||
|
||
sourceSets["iosMain"].dependencies { | ||
implementation("common.ios:lib:1.0") | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...ources/testProject/new-mpp-common-native/common-ios/app/src/iosArm64Main/kotlin/device.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package common.ios.app | ||
|
||
actual fun platform(): String = "Device" |
10 changes: 10 additions & 0 deletions
10
...est/resources/testProject/new-mpp-common-native/common-ios/app/src/iosMain/kotlin/main.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package common.ios.app | ||
|
||
import common.ios.lib.* | ||
|
||
expect fun platform(): String | ||
|
||
fun appFunction() { | ||
libFunction() | ||
println(platform()) | ||
} |
7 changes: 7 additions & 0 deletions
7
...est/resources/testProject/new-mpp-common-native/common-ios/app/src/iosTest/kotlin/test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import common.ios.app.* | ||
import kotlin.test.* | ||
|
||
@Test | ||
fun test() { | ||
appFunction() | ||
} |
3 changes: 3 additions & 0 deletions
3
...urces/testProject/new-mpp-common-native/common-ios/app/src/iosX64Main/kotlin/simulator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package common.ios.app | ||
|
||
actual fun platform(): String = "Simulator" |
25 changes: 25 additions & 0 deletions
25
...ests/src/test/resources/testProject/new-mpp-common-native/common-ios/lib/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
plugins { | ||
id("org.jetbrains.kotlin.multiplatform").version("<pluginMarkerVersion>") | ||
id("maven-publish") | ||
} | ||
|
||
group = "common.ios" | ||
version = "1.0" | ||
|
||
repositories { | ||
mavenLocal() | ||
jcenter() | ||
} | ||
|
||
kotlin { | ||
ios("iosLib") | ||
ios("iosLib") { | ||
println("Configuring ${this.name}") | ||
} | ||
} | ||
|
||
publishing { | ||
repositories { | ||
maven { setUrl(rootProject.projectDir.resolve("repo")) } | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...ces/testProject/new-mpp-common-native/common-ios/lib/src/iosLibArm64Main/kotlin/device.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package common.ios.lib | ||
|
||
actual fun platform(): String = "Device" |
7 changes: 7 additions & 0 deletions
7
.../resources/testProject/new-mpp-common-native/common-ios/lib/src/iosLibMain/kotlin/main.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package common.ios.lib | ||
|
||
expect fun platform(): String | ||
|
||
fun libFunction() { | ||
println(platform()) | ||
} |
3 changes: 3 additions & 0 deletions
3
...es/testProject/new-mpp-common-native/common-ios/lib/src/iosLibX64Main/kotlin/simulator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package common.ios.lib | ||
|
||
actual fun platform(): String = "Simulator" |
12 changes: 12 additions & 0 deletions
12
...tests/src/test/resources/testProject/new-mpp-common-native/common-ios/settings.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
pluginManagement { | ||
repositories { | ||
mavenLocal() | ||
jcenter() | ||
gradlePluginPortal() | ||
} | ||
} | ||
|
||
enableFeaturePreview("GRADLE_METADATA") | ||
|
||
include(":app") | ||
include(":lib") |
22 changes: 22 additions & 0 deletions
22
...sts/src/test/resources/testProject/new-mpp-common-native/common-tvos/app/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
plugins { | ||
id("org.jetbrains.kotlin.multiplatform").version("<pluginMarkerVersion>") | ||
} | ||
|
||
repositories { | ||
mavenLocal() | ||
jcenter() | ||
maven { setUrl(rootProject.projectDir.resolve("repo")) } | ||
} | ||
|
||
kotlin { | ||
tvos() | ||
|
||
// Check that we can reenter the configuration method. | ||
tvos { | ||
binaries.framework(listOf(DEBUG)) | ||
} | ||
|
||
sourceSets["tvosMain"].dependencies { | ||
implementation("common.tvos:lib:1.0") | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...rces/testProject/new-mpp-common-native/common-tvos/app/src/tvosArm64Main/kotlin/device.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package common.tvos.app | ||
|
||
actual fun platform(): String = "Device" |
12 changes: 12 additions & 0 deletions
12
...t/resources/testProject/new-mpp-common-native/common-tvos/app/src/tvosMain/kotlin/main.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
|
||
package common.tvos.app | ||
|
||
import common.tvos.lib.* | ||
|
||
expect fun platform(): String | ||
|
||
fun appFunction() { | ||
libFunction() | ||
println(platform()) | ||
} |
7 changes: 7 additions & 0 deletions
7
...t/resources/testProject/new-mpp-common-native/common-tvos/app/src/tvosTest/kotlin/test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import common.tvos.app.* | ||
import kotlin.test.* | ||
|
||
@Test | ||
fun test() { | ||
appFunction() | ||
} |
3 changes: 3 additions & 0 deletions
3
...ces/testProject/new-mpp-common-native/common-tvos/app/src/tvosX64Main/kotlin/simulator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package common.tvos.app | ||
|
||
actual fun platform(): String = "Simulator" |
25 changes: 25 additions & 0 deletions
25
...sts/src/test/resources/testProject/new-mpp-common-native/common-tvos/lib/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
plugins { | ||
id("org.jetbrains.kotlin.multiplatform").version("<pluginMarkerVersion>") | ||
id("maven-publish") | ||
} | ||
|
||
group = "common.tvos" | ||
version = "1.0" | ||
|
||
repositories { | ||
mavenLocal() | ||
jcenter() | ||
} | ||
|
||
kotlin { | ||
tvos("tvosLib") | ||
tvos("tvosLib") { | ||
println("Configuring ${this.name}") | ||
} | ||
} | ||
|
||
publishing { | ||
repositories { | ||
maven { setUrl(rootProject.projectDir.resolve("repo")) } | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...s/testProject/new-mpp-common-native/common-tvos/lib/src/tvosLibArm64Main/kotlin/device.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package common.tvos.lib | ||
|
||
actual fun platform(): String = "Device" |
7 changes: 7 additions & 0 deletions
7
...esources/testProject/new-mpp-common-native/common-tvos/lib/src/tvosLibMain/kotlin/main.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package common.tvos.lib | ||
|
||
expect fun platform(): String | ||
|
||
fun libFunction() { | ||
println(platform()) | ||
} |
3 changes: 3 additions & 0 deletions
3
.../testProject/new-mpp-common-native/common-tvos/lib/src/tvosLibX64Main/kotlin/simulator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package common.tvos.lib | ||
|
||
actual fun platform(): String = "Simulator" |
12 changes: 12 additions & 0 deletions
12
...ests/src/test/resources/testProject/new-mpp-common-native/common-tvos/settings.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
pluginManagement { | ||
repositories { | ||
mavenLocal() | ||
jcenter() | ||
gradlePluginPortal() | ||
} | ||
} | ||
|
||
enableFeaturePreview("GRADLE_METADATA") | ||
|
||
include(":app") | ||
include(":lib") |
22 changes: 22 additions & 0 deletions
22
.../src/test/resources/testProject/new-mpp-common-native/common-watchos/app/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
plugins { | ||
id("org.jetbrains.kotlin.multiplatform").version("<pluginMarkerVersion>") | ||
} | ||
|
||
repositories { | ||
mavenLocal() | ||
jcenter() | ||
maven { setUrl(rootProject.projectDir.resolve("repo")) } | ||
} | ||
|
||
kotlin { | ||
watchos() | ||
|
||
// Check that we can reenter the configuration method. | ||
watchos { | ||
binaries.framework(listOf(DEBUG)) | ||
} | ||
|
||
sourceSets["watchosMain"].dependencies { | ||
implementation("common.watchos:lib:1.0") | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...tProject/new-mpp-common-native/common-watchos/app/src/watchosArm32Main/kotlin/device32.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package common.watchos.app | ||
|
||
actual val bitness: Int = 32 |
3 changes: 3 additions & 0 deletions
3
...tProject/new-mpp-common-native/common-watchos/app/src/watchosArm64Main/kotlin/device64.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package common.watchos.app | ||
|
||
actual val bitness: Int = 64 |
5 changes: 5 additions & 0 deletions
5
...stProject/new-mpp-common-native/common-watchos/app/src/watchosDeviceMain/kotlin/device.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package common.watchos.app | ||
|
||
expect val bitness: Int | ||
|
||
actual fun platform(): String = "Device$bitness" |
10 changes: 10 additions & 0 deletions
10
...urces/testProject/new-mpp-common-native/common-watchos/app/src/watchosMain/kotlin/main.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package common.watchos.app | ||
|
||
import common.watchos.lib.* | ||
|
||
expect fun platform(): String | ||
|
||
fun appFunction() { | ||
libFunction() | ||
println(platform()) | ||
} |
7 changes: 7 additions & 0 deletions
7
...urces/testProject/new-mpp-common-native/common-watchos/app/src/watchosTest/kotlin/test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import common.watchos.app.* | ||
import kotlin.test.* | ||
|
||
@Test | ||
fun test() { | ||
appFunction() | ||
} |
Oops, something went wrong.