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.file.Directory
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskContainer
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.uppercaseFirstChar
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.Framework
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
import org.jetbrains.kotlin.gradle.plugin.mpp.*
import java.io.File
private val incompatiblePlugins = listOf(
@ -30,6 +30,8 @@ private val incompatiblePlugins = listOf(
"io.github.skeptick.libres",
)
private const val IOS_COMPOSE_RESOURCES_ROOT_DIR = "compose-resources"
internal fun Project.configureSyncTask(mppExt: KotlinMultiplatformExtension) {
fun reportSyncIsDisabled(reason: String) {
logger.info("Compose Multiplatform resource management for iOS is disabled: $reason")
@ -60,13 +62,13 @@ private class SyncIosResourcesContext(
fun syncDirFor(framework: Framework): Provider<Directory> {
val providers = framework.project.providers
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 {
providers.environmentVariable("BUILT_PRODUCTS_DIR")
.zip(providers.environmentVariable("CONTENTS_FOLDER_PATH")) { builtProductsDir, contentsFolderPath ->
File(builtProductsDir)
.resolve(contentsFolderPath)
.resolve("compose-resources")
.resolve(IOS_COMPOSE_RESOURCES_ROOT_DIR)
.canonicalPath
}.flatMap {
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) {
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
@ -186,11 +209,11 @@ private fun extractPrefixFromBinaryName(name: String, buildType: NativeBuildType
name.substringBeforeLast(suffix.uppercaseFirstChar())
}
private fun iosTargetResourcesProvider(framework: Framework): Provider<IosTargetResources> {
val kotlinTarget = framework.target
val project = framework.project
private fun iosTargetResourcesProvider(bin: NativeBinary): Provider<IosTargetResources> {
val kotlinTarget = bin.target
val project = bin.project
return project.provider {
val resourceDirs = framework.compilation.allKotlinSourceSets
val resourceDirs = bin.compilation.allKotlinSourceSets
.flatMap { sourceSet ->
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
fun iosMokoResources() {
Assumptions.assumeTrue(currentOS == OS.MacOS)

2
gradle-plugins/gradle.properties

@ -2,7 +2,7 @@ org.gradle.parallel=true
kotlin.code.style=official
# 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.
compose.tests.compiler.version=1.5.8-beta01
# The latest version of Kotlin compatible with compose.tests.compiler.version. Used only in tests/CI.

Loading…
Cancel
Save