Browse Source

Support compose resources for ios tests (#4185)

pull/4190/head
Konstantin 10 months ago committed by GitHub
parent
commit
2e354eba3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 39
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/ios/configureSyncIosResources.kt
  2. 19
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt
  3. 2
      gradle-plugins/gradle.properties

39
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/ios/configureSyncIosResources.kt

@ -8,6 +8,7 @@ package org.jetbrains.compose.resources.ios
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.file.Directory import org.gradle.api.file.Directory
import org.gradle.api.provider.Provider import org.gradle.api.provider.Provider
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.Input import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskContainer import org.gradle.api.tasks.TaskContainer
import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.TaskAction
@ -21,8 +22,7 @@ import org.jetbrains.compose.internal.utils.new
import org.jetbrains.compose.internal.utils.registerOrConfigure import org.jetbrains.compose.internal.utils.registerOrConfigure
import org.jetbrains.compose.internal.utils.uppercaseFirstChar import org.jetbrains.compose.internal.utils.uppercaseFirstChar
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.Framework import org.jetbrains.kotlin.gradle.plugin.mpp.*
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
import java.io.File import java.io.File
private val incompatiblePlugins = listOf( private val incompatiblePlugins = listOf(
@ -30,6 +30,8 @@ private val incompatiblePlugins = listOf(
"io.github.skeptick.libres", "io.github.skeptick.libres",
) )
private const val IOS_COMPOSE_RESOURCES_ROOT_DIR = "compose-resources"
internal fun Project.configureSyncTask(mppExt: KotlinMultiplatformExtension) { internal fun Project.configureSyncTask(mppExt: KotlinMultiplatformExtension) {
fun reportSyncIsDisabled(reason: String) { fun reportSyncIsDisabled(reason: String) {
logger.info("Compose Multiplatform resource management for iOS is disabled: $reason") logger.info("Compose Multiplatform resource management for iOS is disabled: $reason")
@ -60,13 +62,13 @@ private class SyncIosResourcesContext(
fun syncDirFor(framework: Framework): Provider<Directory> { fun syncDirFor(framework: Framework): Provider<Directory> {
val providers = framework.project.providers val providers = framework.project.providers
return if (framework.isCocoapodsFramework) { return if (framework.isCocoapodsFramework) {
project.layout.buildDirectory.dir("compose/ios/${framework.baseName}/compose-resources/") project.layout.buildDirectory.dir("compose/ios/${framework.baseName}/$IOS_COMPOSE_RESOURCES_ROOT_DIR/")
} else { } else {
providers.environmentVariable("BUILT_PRODUCTS_DIR") providers.environmentVariable("BUILT_PRODUCTS_DIR")
.zip(providers.environmentVariable("CONTENTS_FOLDER_PATH")) { builtProductsDir, contentsFolderPath -> .zip(providers.environmentVariable("CONTENTS_FOLDER_PATH")) { builtProductsDir, contentsFolderPath ->
File(builtProductsDir) File(builtProductsDir)
.resolve(contentsFolderPath) .resolve(contentsFolderPath)
.resolve("compose-resources") .resolve(IOS_COMPOSE_RESOURCES_ROOT_DIR)
.canonicalPath .canonicalPath
}.flatMap { }.flatMap {
framework.project.objects.directoryProperty().apply { set(File(it)) } framework.project.objects.directoryProperty().apply { set(File(it)) }
@ -74,6 +76,15 @@ private class SyncIosResourcesContext(
} }
} }
fun configureEachIosTestExecutable(fn: (TestExecutable) -> Unit) {
mppExt.targets.all { target ->
target.asIosNativeTargetOrNull()?.let { iosTarget ->
iosTarget.binaries.withType(TestExecutable::class.java).configureEach { bin ->
fn(bin)
}
}
}
}
fun configureEachIosFramework(fn: (Framework) -> Unit) { fun configureEachIosFramework(fn: (Framework) -> Unit) {
mppExt.targets.all { target -> mppExt.targets.all { target ->
@ -166,6 +177,18 @@ private fun SyncIosResourcesContext.configureSyncResourcesTasks() {
} }
} }
} }
configureEachIosTestExecutable { bin ->
val copyTestResourcesTask = "copyTestComposeResourcesFor${bin.target.targetName.uppercaseFirstChar()}"
val task = project.tasks.registerOrConfigure<Copy>(copyTestResourcesTask) {
from({
(bin.compilation.associateWith + bin.compilation).flatMap { compilation ->
compilation.allKotlinSourceSets.map { it.resources }
}
})
into(bin.outputDirectory.resolve(IOS_COMPOSE_RESOURCES_ROOT_DIR))
}
bin.linkTask.dependsOn(task)
}
} }
private val Framework.isCocoapodsFramework: Boolean private val Framework.isCocoapodsFramework: Boolean
@ -186,11 +209,11 @@ private fun extractPrefixFromBinaryName(name: String, buildType: NativeBuildType
name.substringBeforeLast(suffix.uppercaseFirstChar()) name.substringBeforeLast(suffix.uppercaseFirstChar())
} }
private fun iosTargetResourcesProvider(framework: Framework): Provider<IosTargetResources> { private fun iosTargetResourcesProvider(bin: NativeBinary): Provider<IosTargetResources> {
val kotlinTarget = framework.target val kotlinTarget = bin.target
val project = framework.project val project = bin.project
return project.provider { return project.provider {
val resourceDirs = framework.compilation.allKotlinSourceSets val resourceDirs = bin.compilation.allKotlinSourceSets
.flatMap { sourceSet -> .flatMap { sourceSet ->
sourceSet.resources.srcDirs.map { it.canonicalPath } sourceSet.resources.srcDirs.map { it.canonicalPath }
} }

19
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt

@ -93,6 +93,25 @@ class GradlePluginTest : GradlePluginTestBase() {
} }
} }
@Test
fun iosTestResources() {
Assumptions.assumeTrue(currentOS == OS.MacOS)
val testEnv = defaultTestEnvironment.copy(
useGradleConfigurationCache = TestProperties.gradleBaseVersionForTests.isAtLeastGradle8
)
with(testProject(TestProjects.iosResources, testEnv)) {
gradle(":linkDebugTestIosX64", "--dry-run").checks {
check.taskSkipped(":copyTestComposeResourcesForIosX64")
check.taskSkipped(":linkDebugTestIosX64")
}
gradle(":copyTestComposeResourcesForIosX64").checks {
check.taskSuccessful(":copyTestComposeResourcesForIosX64")
file("build/bin/iosX64/debugTest/compose-resources/compose-multiplatform.xml").checkExists()
}
}
}
@Test @Test
fun iosMokoResources() { fun iosMokoResources() {
Assumptions.assumeTrue(currentOS == OS.MacOS) Assumptions.assumeTrue(currentOS == OS.MacOS)

2
gradle-plugins/gradle.properties

@ -2,7 +2,7 @@ org.gradle.parallel=true
kotlin.code.style=official kotlin.code.style=official
# Default version of Compose Libraries used by Gradle plugin # Default version of Compose Libraries used by Gradle plugin
compose.version=1.6.0-dev1357 compose.version=1.6.0-dev1383
# The latest version of Compose Compiler used by Gradle plugin. Used only in tests/CI. # The latest version of Compose Compiler used by Gradle plugin. Used only in tests/CI.
compose.tests.compiler.version=1.5.8-beta01 compose.tests.compiler.version=1.5.8-beta01
# The latest version of Kotlin compatible with compose.tests.compiler.version. Used only in tests/CI. # The latest version of Kotlin compatible with compose.tests.compiler.version. Used only in tests/CI.

Loading…
Cancel
Save