From 7b1552f3d66c7efdd09c0cce35b34072db898f6e Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Sun, 16 Dec 2018 19:11:02 +0700 Subject: [PATCH] Add tests for new binaries DSL --- .../kotlin/gradle/NewMultiplatformIT.kt | 173 +++++++++++++++++- .../build.gradle.kts | 13 +- .../sample-app/build.gradle | 9 + .../groovy-dsl/build.gradle | 85 +++++++++ .../groovy-dsl/exported/build.gradle | 19 ++ .../src/commonMain/kotlin/exported.kt | 1 + .../groovy-dsl/settings.gradle | 5 + .../src/commonMain/kotlin/PackageMain.kt | 5 + .../src/commonMain/kotlin/RootMain.kt | 3 + .../groovy-dsl/src/commonTest/kotlin/test.kt | 11 ++ .../kotlin-dsl/build.gradle.kts | 96 ++++++++++ .../kotlin-dsl/exported/build.gradle.kts | 19 ++ .../src/commonMain/kotlin/exported.kt | 1 + .../kotlin-dsl/settings.gradle | 13 ++ .../src/commonMain/kotlin/PackageMain.kt | 5 + .../src/commonMain/kotlin/RootMain.kt | 3 + .../kotlin-dsl/src/commonTest/kotlin/test.kt | 6 + .../gradle/plugin/mpp/NativeBinaries.kt | 8 +- 18 files changed, 465 insertions(+), 10 deletions(-) create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/build.gradle create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/exported/build.gradle create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/exported/src/commonMain/kotlin/exported.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/settings.gradle create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/src/commonMain/kotlin/PackageMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/src/commonMain/kotlin/RootMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/src/commonTest/kotlin/test.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/build.gradle.kts create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/exported/build.gradle.kts create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/exported/src/commonMain/kotlin/exported.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/settings.gradle create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/src/commonMain/kotlin/PackageMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/src/commonMain/kotlin/RootMain.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/src/commonTest/kotlin/test.kt 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 bdc885d3e67..ba03d359d7c 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 @@ -6,13 +6,11 @@ package org.jetbrains.kotlin.gradle import org.jetbrains.kotlin.gradle.plugin.ProjectLocalConfigurations import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin +import org.jetbrains.kotlin.gradle.plugin.mpp.NativeOutputKind import org.jetbrains.kotlin.gradle.plugin.mpp.UnusedSourceSetsChecker import org.jetbrains.kotlin.gradle.plugin.sources.METADATA_CONFIGURATION_NAME_SUFFIX import org.jetbrains.kotlin.gradle.plugin.sources.SourceSetConsistencyChecks -import org.jetbrains.kotlin.gradle.util.checkBytecodeContains -import org.jetbrains.kotlin.gradle.util.isWindows -import org.jetbrains.kotlin.gradle.util.modify -import org.jetbrains.kotlin.gradle.util.testResolveAllConfigurations +import org.jetbrains.kotlin.gradle.util.* import org.jetbrains.kotlin.konan.target.CompilerOutputKind import org.jetbrains.kotlin.konan.target.HostManager import org.junit.Assert @@ -152,6 +150,15 @@ class NewMultiplatformIT : BaseGradleIT() { val nativeExeName = if (isWindows) "main.exe" else "main.kexe" assertFileExists("build/bin/$nativeHostTargetName/mainReleaseExecutable/$nativeExeName") assertFileExists("build/bin/$nativeHostTargetName/mainDebugExecutable/$nativeExeName") + + // Check that linker options was correctly passed to the K/N compiler. + output.lineSequence().filter { + it.contains("Run tool: konanc") && it.contains("-p program") + }.toList().also { + assertTrue(it.isNotEmpty()) + }.forEach { + assertTrue(it.contains("-linker-options -L.")) + } } build("assemble", "resolveRuntimeDependencies") { @@ -171,6 +178,12 @@ class NewMultiplatformIT : BaseGradleIT() { build("clean", "assemble", "--rerun-tasks") { checkAppBuild() } + + // Check that binary getters initially introduced in 1.3 work. + build("checkBinaryGetters") { + assertTrue(output.contains("Wasm binary file: main.wasm")) + assertTrue(output.contains("Wasm link task: linkMainReleaseExecutableWasm32")) + } } with(oldStyleAppProject) { @@ -835,6 +848,158 @@ class NewMultiplatformIT : BaseGradleIT() { } } + @Test + fun testNativeBinaryKotlinDSL() = doTestNativeBinaryDSL("kotlin-dsl") + + @Test + fun testNativeBinaryGroovyDSL() = doTestNativeBinaryDSL("groovy-dsl") + + private fun doTestNativeBinaryDSL( + projectName: String, + gradleVersionRequired: GradleVersionRequired = gradleVersion + ) = with(transformProjectWithPluginsDsl(projectName, gradleVersionRequired, "new-mpp-native-binaries")) { + val hostSuffix = nativeHostTargetName.capitalize() + val binaries = mutableListOf( + "debugExecutable" to "native-binary", + "releaseExecutable" to "native-binary", + "fooDebugExecutable" to "foo", + "fooReleaseExecutable" to "foo", + "barReleaseExecutable" to "bar", + "bazReleaseExecutable" to "my-baz", + "testDebugExecutable" to "test", + "test2ReleaseExecutable" to "test2", + "releaseStatic" to "native_binary", + "releaseShared" to "native_binary" + ) + + val linkTasks = binaries.map { (name, _) -> "link${name.capitalize()}$hostSuffix" } + val outputFiles = binaries.map { (name, fileBaseName) -> + val outputKind = NativeOutputKind.values().single { name.endsWith(it.taskNameClassifier, true) }.compilerOutputKind + val prefix = outputKind.prefix(HostManager.host) + val suffix = outputKind.suffix(HostManager.host) + val fileName = "$prefix$fileBaseName$suffix" + "build/bin/$nativeHostTargetName/$name/$fileName" + } + + val runTasks = listOf( + "runDebugExecutable", + "runReleaseExecutable", + "runFooDebugExecutable", + "runFooReleaseExecutable", + "runBarReleaseExecutable", + "runBazReleaseExecutable", + "runTest2ReleaseExecutable" + ).map { "$it$hostSuffix" }.toMutableList() + + val binariesTasks = arrayOf("${nativeHostTargetName}MainBinaries", "${nativeHostTargetName}TestBinaries") + + // Check that all link and run tasks are generated. + build(*binariesTasks) { + assertSuccessful() + assertTasksExecuted(linkTasks.map { ":$it" }) + outputFiles.forEach { + assertFileExists(it) + } + // Check that getters work fine. + assertTrue(output.contains("Check link task: linkReleaseShared$hostSuffix")) + assertTrue(output.contains("Check run task: runFooReleaseExecutable$hostSuffix")) + } + + build("tasks") { + assertSuccessful() + runTasks.forEach { + assertTrue(output.contains(it), "The 'tasks' output doesn't contain a task ${it}") + } + } + + // Clean the build to check that run tasks build corresponding binaries. + build("clean") { + assertSuccessful() + } + + // Check that run tasks work find and an entry point can be specified. + build("runDebugExecutable$hostSuffix") { + assertSuccessful() + assertTrue(output.contains(".main")) + } + + build("runBazReleaseExecutable$hostSuffix") { + assertSuccessful() + assertTrue(output.contains("foo.main")) + } + + build("runTest2ReleaseExecutable$hostSuffix") { + assertSuccessful() + assertTrue(output.contains("tests.foo")) + } + + // Check that we still have a default test task and it can be executed properly. + build("${nativeHostTargetName}Test") { + assertSuccessful() + assertTrue(output.contains("tests.foo")) + } + + fun CompiledProject.checkFrameworkCompilationCommandLine(check: (String) -> Unit) { + output.lineSequence().filter { + it.contains("Run tool: konanc") && it.contains("-p framework") + }.toList().also { + assertTrue(it.isNotEmpty()) + }.forEach(check) + } + if (HostManager.hostIsMac) { + + // Check dependency exporting and bitcode embedding in frameworks. + // For release builds + build("linkReleaseFrameworkIos") { + assertSuccessful() + assertFileExists("build/bin/ios/releaseFramework/native_binary.framework") + fileInWorkingDir("build/bin/ios/releaseFramework/native_binary.framework/Headers/native_binary.h") + .readText().contains("+ (int32_t)exported") + // Check that by default release frameworks have bitcode embedded. + checkFrameworkCompilationCommandLine { + assertTrue(it.contains("-Xembed-bitcode")) + assertTrue(it.contains("-opt")) + } + } + + // For debug builds + build("linkDebugFrameworkIos") { + assertSuccessful() + assertFileExists("build/bin/ios/debugFramework/native_binary.framework") + fileInWorkingDir("build/bin/ios/debugFramework/native_binary.framework/Headers/native_binary.h") + .readText().contains("+ (int32_t)exported") + // Check that by default debug frameworks have bitcode marker embedded. + checkFrameworkCompilationCommandLine { + assertTrue(it.contains("-Xembed-bitcode-marker")) + assertTrue(it.contains("-g")) + } + } + + // Check manual disabling bitcode embedding and custom command line args. + build("linkCustomReleaseFrameworkIos") { + assertSuccessful() + checkFrameworkCompilationCommandLine { + assertTrue(it.contains("-linker-options -L.")) + assertTrue(it.contains("-Xtime")) + assertFalse(it.contains("-Xembed-bitcode-marker")) + assertFalse(it.contains("-Xembed-bitcode")) + } + } + + // Check that plugin doesn't allow exporting dependencies not added in the API configuration. + val buildFile = listOf("build.gradle", "build.gradle.kts").map { projectDir.resolve(it) }.single { it.exists() } + buildFile.modify { + it.replace("api(project(\":exported\"))", "") + } + build("linkReleaseFrameworkIos") { + assertFailed() + val failureMsg = "Following dependencies exported in the releaseFramework binary " + + "are not specified as API-dependencies of a corresponding source set" + assertTrue(output.contains(failureMsg)) + } + } + } + @Test fun testSourceJars() = with(Project("sample-lib", gradleVersion, "new-mpp-lib-and-app")) { setupWorkingDir() diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-and-app/sample-app-gradle-kotlin-dsl/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-and-app/sample-app-gradle-kotlin-dsl/build.gradle.kts index 18283ca6aa1..7c784fb99df 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-and-app/sample-app-gradle-kotlin-dsl/build.gradle.kts +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-and-app/sample-app-gradle-kotlin-dsl/build.gradle.kts @@ -1,5 +1,3 @@ -import org.jetbrains.kotlin.gradle.plugin.mpp.NativeOutputKind.EXECUTABLE - plugins { id("org.jetbrains.kotlin.multiplatform").version("") id("maven-publish") @@ -29,6 +27,8 @@ kotlin { compilations.getByName("main") { outputKinds.add(EXECUTABLE) entryPoint = "com.example.app.native.main" + // Check that linker options are correctly passed to the compiler. + linkerOpts = mutableListOf("-L.") } } @@ -59,6 +59,13 @@ kotlin { } } } + + tasks.create("checkBinaryGetters") { + doLast { + println("Wasm binary file: ${wasm32.compilations.getByName("main").getBinary("EXECUTABLE", "RELEASE").name}") + println("Wasm link task: ${wasm32.compilations.getByName("main").getLinkTask("EXECUTABLE", "RELEASE").name}") + } + } } tasks.create("resolveRuntimeDependencies", DefaultTask::class.java) { @@ -67,4 +74,4 @@ tasks.create("resolveRuntimeDependencies", DefaultTask::class.java) { val configName = kotlin.jvm("jvm6").compilations["main"].runtimeDependencyConfigurationName configurations[configName].resolve() } -} \ No newline at end of file +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-and-app/sample-app/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-and-app/sample-app/build.gradle index ceccb5bab3d..a9c8674d3ec 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-and-app/sample-app/build.gradle +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-and-app/sample-app/build.gradle @@ -66,6 +66,8 @@ kotlin { configure([wasm32, linux64, mingw64, macos64]) { compilations.main.outputKinds += org.jetbrains.kotlin.gradle.plugin.mpp.NativeOutputKind.EXECUTABLE compilations.main.entryPoint = "com.example.app.native.main" + // Check that linker options are correctly passed to the compiler. + compilations.main.linkerOpts = ['-L.'] } } } @@ -76,4 +78,11 @@ task resolveRuntimeDependencies(type: DefaultTask) { def configName = kotlin.targets.jvm6.compilations.main.runtimeDependencyConfigurationName configurations[configName].resolve() } +} + +task checkBinaryGetters { + doLast { + println("Wasm binary file: ${kotlin.targets.wasm32.compilations.main.getBinary("EXECUTABLE", "RELEASE").name}") + println("Wasm link task: ${kotlin.targets.wasm32.compilations.main.getLinkTask("EXECUTABLE", "RELEASE").name}") + } } \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/build.gradle new file mode 100644 index 00000000000..4c90a8a47ff --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/build.gradle @@ -0,0 +1,85 @@ +buildscript { + repositories { + mavenLocal() + jcenter() + } + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +apply plugin: 'kotlin-multiplatform' + +repositories { + mavenLocal() + jcenter() +} + +kotlin { + sourceSets { + commonMain { + dependencies { + api "org.jetbrains.kotlin:kotlin-stdlib-common" + } + } + + iosMain { + dependencies { + api(project(":exported")) + } + } + + commonTest { + dependencies { + api "org.jetbrains.kotlin:kotlin-test-annotations-common" + } + } + } + + targets { + macosX64("macos64") + linuxX64("linux64") + mingwX64("windows64") + + configure([macos64, linux64, windows64]) { + binaries { + + executable() // Executable with default name. + executable("foo") // Custom binary name. + executable("bar", [RELEASE]) // Custom build types. + + // Configure a binary. + executable("baz", [RELEASE]) { + // Rename an output binary: baz.kexe -> my-baz.kexe. + baseName = "my-baz" + // Use a custom entry point. + entryPoint = "foo.main" + } + + executable("test2", [RELEASE]) { + compilation = compilations["test"] + } + + sharedLib([RELEASE]) + staticLib([RELEASE]) + } + // Check that we can access binaries/tasks: + // Just by name: + println("Check link task: ${binaries.releaseShared.linkTask.name}") + // Using a typed getter: + println("Check run task: ${binaries.getExecutable("foo", RELEASE).runTask.name}") + } + iosArm64("ios") { + binaries { + framework { + export project(':exported') + } + framework('custom', [RELEASE]) { + embedBitcode = 'DISABLE' + linkerOpts = ['-L.'] + freeCompilerArgs = ["-Xtime"] + } + } + } + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/exported/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/exported/build.gradle new file mode 100644 index 00000000000..8f685abccc3 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/exported/build.gradle @@ -0,0 +1,19 @@ +plugins { + id("org.jetbrains.kotlin.multiplatform") +} + +repositories { + mavenLocal() + jcenter() + maven { setUrl("http://dl.bintray.com/kotlin/kotlinx.html/") } +} + +kotlin { + sourceSets.commonMain { + dependencies { + api("org.jetbrains.kotlin:kotlin-stdlib-common") + } + } + + iosArm64("ios") +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/exported/src/commonMain/kotlin/exported.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/exported/src/commonMain/kotlin/exported.kt new file mode 100644 index 00000000000..6905fb96702 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/exported/src/commonMain/kotlin/exported.kt @@ -0,0 +1 @@ +fun exported() = 42 \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/settings.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/settings.gradle new file mode 100644 index 00000000000..0bb55ac1af4 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/settings.gradle @@ -0,0 +1,5 @@ +enableFeaturePreview('GRADLE_METADATA') + +rootProject.name = "native-binary" + +include ':exported' \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/src/commonMain/kotlin/PackageMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/src/commonMain/kotlin/PackageMain.kt new file mode 100644 index 00000000000..0077bb41f7b --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/src/commonMain/kotlin/PackageMain.kt @@ -0,0 +1,5 @@ +package foo + +fun main() { + println("foo.main") +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/src/commonMain/kotlin/RootMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/src/commonMain/kotlin/RootMain.kt new file mode 100644 index 00000000000..6910c0e3d0a --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/src/commonMain/kotlin/RootMain.kt @@ -0,0 +1,3 @@ +fun main() { + println(".main") +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/src/commonTest/kotlin/test.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/src/commonTest/kotlin/test.kt new file mode 100644 index 00000000000..749c82e2487 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/groovy-dsl/src/commonTest/kotlin/test.kt @@ -0,0 +1,11 @@ +/* + * 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. + */ + +import kotlin.test.* + +@Test +fun foo() { + println("tests.foo") +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/build.gradle.kts new file mode 100644 index 00000000000..b6cded2ecaf --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/build.gradle.kts @@ -0,0 +1,96 @@ +plugins { + id("org.jetbrains.kotlin.multiplatform").version("") +} + +repositories { + mavenLocal() + jcenter() + maven { setUrl("http://dl.bintray.com/kotlin/kotlinx.html/") } +} + +kotlin { + sourceSets["commonMain"].apply { + dependencies { + api("org.jetbrains.kotlin:kotlin-stdlib-common") + } + } + + sourceSets.create("iosMain").apply { + dependencies { + api(project(":exported")) + } + } + + sourceSets["commonTest"].apply { + dependencies { + api("org.jetbrains.kotlin:kotlin-test-annotations-common") + } + } + + val macos = macosX64("macos64") + val linux = linuxX64("linux64") + val windows = mingwX64("windows64") + + configure(listOf(macos, linux, windows)) { + + binaries { + + executable() // Executable with default name. + executable("foo") // Custom binary name. + executable("bar", listOf(RELEASE)) // Custom build types. + + // Configure a binary. + executable("baz") { + // Rename an output binary: baz.kexe -> my-baz.kexe. + baseName = "my-baz" + // Use a custom entry point. + entryPoint = "foo.main" + } + + executable("test2") { + compilation = compilations["test"] + } + + sharedLib(listOf(RELEASE)) + staticLib(listOf(RELEASE)) + } + // Check that we can access binaries/tasks: + // Just by name: + println("Check link task: ${binaries["releaseShared"].linkTask.name}") + // Using a typed getter: + println("Check run task: ${binaries.getExecutable("foo", RELEASE).runTask?.name}") + } + + iosArm64("ios") { + binaries { + framework { + export(project(":exported")) + } + framework("custom", listOf(RELEASE)) { + embedBitcode("disable") + linkerOpts = mutableListOf("-L.") + freeCompilerArgs = mutableListOf("-Xtime") + } + } + } +} + + + + + + + + + + + + + + + + + + + + diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/exported/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/exported/build.gradle.kts new file mode 100644 index 00000000000..26e80c4a28e --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/exported/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + id("org.jetbrains.kotlin.multiplatform") +} + +repositories { + mavenLocal() + jcenter() + maven { setUrl("http://dl.bintray.com/kotlin/kotlinx.html/") } +} + +kotlin { + sourceSets["commonMain"].apply { + dependencies { + api("org.jetbrains.kotlin:kotlin-stdlib-common") + } + } + + iosArm64("ios") +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/exported/src/commonMain/kotlin/exported.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/exported/src/commonMain/kotlin/exported.kt new file mode 100644 index 00000000000..6905fb96702 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/exported/src/commonMain/kotlin/exported.kt @@ -0,0 +1 @@ +fun exported() = 42 \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/settings.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/settings.gradle new file mode 100644 index 00000000000..fe707a1169f --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/settings.gradle @@ -0,0 +1,13 @@ +pluginManagement { + repositories { + mavenLocal() + jcenter() + gradlePluginPortal() + } +} + +enableFeaturePreview('GRADLE_METADATA') + +rootProject.name = "native-binary" + +include ':exported' \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/src/commonMain/kotlin/PackageMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/src/commonMain/kotlin/PackageMain.kt new file mode 100644 index 00000000000..0077bb41f7b --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/src/commonMain/kotlin/PackageMain.kt @@ -0,0 +1,5 @@ +package foo + +fun main() { + println("foo.main") +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/src/commonMain/kotlin/RootMain.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/src/commonMain/kotlin/RootMain.kt new file mode 100644 index 00000000000..6910c0e3d0a --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/src/commonMain/kotlin/RootMain.kt @@ -0,0 +1,3 @@ +fun main() { + println(".main") +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/src/commonTest/kotlin/test.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/src/commonTest/kotlin/test.kt new file mode 100644 index 00000000000..50a6ea99ab2 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-native-binaries/kotlin-dsl/src/commonTest/kotlin/test.kt @@ -0,0 +1,6 @@ +import kotlin.test.* + +@Test +fun foo() { + println("tests.foo") +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/NativeBinaries.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/NativeBinaries.kt index 5075ba7eaf9..58153524f87 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/NativeBinaries.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/NativeBinaries.kt @@ -199,11 +199,13 @@ class Framework( /** * Enable or disable embedding bitcode for the framework. + * The parameter [mode] is one of the following string constants: * - * @param mode - one of the following string constants: * disable - Don't embed LLVM IR bitcode. - * bitcode - Embed LLVM IR bitcode as data. Has the same effect as the -Xembed-bitcode command line option. - * marker - Embed placeholder LLVM IR data as a marker. Has the same effect as the -Xembed-bitcode-marker command line option. + * bitcode - Embed LLVM IR bitcode as data. + * Has the same effect as the -Xembed-bitcode command line option. + * marker - Embed placeholder LLVM IR data as a marker. + * Has the same effect as the -Xembed-bitcode-marker command line option. */ fun embedBitcode(mode: String) = embedBitcode(BitcodeEmbeddingMode.valueOf(mode.toUpperCase()))