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 bbf0dea1eba..a3a0697038e 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 @@ -205,6 +205,89 @@ class GeneralNativeIT : BaseGradleIT() { } } + @Test + fun testCanProvideNativeFrameworkArtifact() = with( + transformNativeTestProjectWithPluginDsl("frameworks", directoryPrefix = "native-binaries") + ) { + Assume.assumeTrue(HostManager.hostIsMac) + + gradleBuildScript().appendText( + """ + val frameworkTargets = Attribute.of( + "org.jetbrains.kotlin.native.framework.targets", + Set::class.java + ) + val kotlinNativeBuildTypeAttribute = Attribute.of( + "org.jetbrains.kotlin.native.build.type", + String::class.java + ) + + fun validateConfiguration(conf: Configuration, targets: Set, expectedBuildType: String) { + if (conf.artifacts.files.count() != 1 || conf.artifacts.files.singleFile.name != "main.framework") { + throw IllegalStateException("No single artifact with proper name \"main.framework\"") + } + val confTargets = conf.attributes.getAttribute(frameworkTargets)!! + val buildType = conf.attributes.getAttribute(kotlinNativeBuildTypeAttribute)!! + if (confTargets.size != targets.size || !confTargets.containsAll(targets)) { + throw IllegalStateException("Framework has incorrect attributes. Expected targets: \"${'$'}targets\", actual: \"${'$'}confTargets\"") + } + if (buildType != expectedBuildType) { + throw IllegalStateException("Framework has incorrect attributes. Expected build type: \"${'$'}expectedBuildType\", actual: \"${'$'}buildType\"") + } + } + + tasks.register("validateThinArtifacts") { + doLast { + val targets = listOf("ios" to "ios_arm64", "iosSim" to "ios_x64") + val buildTypes = listOf("release", "debug") + targets.forEach { (name, target) -> + buildTypes.forEach { buildType -> + val conf = project.configurations.getByName("main${'$'}{buildType.capitalize()}Framework${'$'}{name.capitalize()}") + validateConfiguration(conf, setOf(target), buildType.toUpperCase()) + } + } + } + } + + tasks.register("validateFatArtifacts") { + doLast { + val buildTypes = listOf("release", "debug") + buildTypes.forEach { buildType -> + val conf = project.configurations.getByName("main${'$'}{buildType.capitalize()}FrameworkIosFat") + validateConfiguration(conf, setOf("ios_x64", "ios_arm64"), buildType.toUpperCase()) + } + } + } + + tasks.register("validateCustomAttributesSetting") { + doLast { + val conf = project.configurations.getByName("customReleaseFrameworkIos") + val attr1Value = conf.attributes.getAttribute(disambiguation1Attribute) + if (attr1Value != "someValue") { + throw IllegalStateException("myDisambiguation1Attribute has incorrect value. Expected: \"someValue\", actual: \"${'$'}attr1Value\"") + } + val attr2Value = conf.attributes.getAttribute(disambiguation2Attribute) + if (attr2Value != "someValue2") { + throw IllegalStateException("myDisambiguation2Attribute has incorrect value. Expected: \"someValue2\", actual: \"${'$'}attr2Value\"") + } + } + } + """.trimIndent() + ) + + build(":validateThinArtifacts") { + assertSuccessful() + } + + build(":validateFatArtifacts") { + assertSuccessful() + } + + build(":validateCustomAttributesSetting") { + assertSuccessful() + } + } + @Test fun testCanProduceNativeFrameworks() = with( transformNativeTestProjectWithPluginDsl("frameworks", directoryPrefix = "native-binaries") diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-binaries/frameworks/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-binaries/frameworks/build.gradle.kts index 207f06cd23b..22657626b9f 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-binaries/frameworks/build.gradle.kts +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-binaries/frameworks/build.gradle.kts @@ -7,6 +7,9 @@ repositories { jcenter() } +val disambiguation1Attribute = Attribute.of("myDisambiguation1Attribute", String::class.java) +val disambiguation2Attribute = Attribute.of("myDisambiguation2Attribute", String::class.java) + kotlin { sourceSets["commonMain"].apply { dependencies { @@ -16,6 +19,7 @@ kotlin { } iosArm64("ios") { + attributes.attribute(disambiguation1Attribute, "someValue") binaries { framework("main") { export(project(":exported")) @@ -25,6 +29,7 @@ kotlin { linkerOpts = mutableListOf("-L.") freeCompilerArgs = mutableListOf("-Xtime") isStatic = true + attributes.attribute(disambiguation2Attribute, "someValue2") } } }