From 5dddad94dc6597d031a01433cf2fe44a68b405b1 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Wed, 8 May 2024 21:21:57 +0200 Subject: [PATCH] Fix resources with cocoapods integration (#4783) The PR sets a static path to the compose resources for the cocoapods integration because there maybe only one integration framework for a gradle module. Fixes https://github.com/JetBrains/compose-multiplatform/issues/4720 ## Release Notes ### Fixes - Resources - _(prerelease fix)_ Fix resources with cocoapods integration (cherry picked from commit b8846788ce790bc5973519b9bd9d5f34817b161f) --- .../compose/resources/IosResources.kt | 16 +++--- .../test/tests/integration/ResourcesTest.kt | 11 +++- .../expected/iosResources.podspec | 50 +++++++++++++++++++ 3 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 gradle-plugins/compose/src/test/test-projects/misc/iosResources/expected/iosResources.podspec diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/IosResources.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/IosResources.kt index f950f48855..bdb114d4ac 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/IosResources.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/IosResources.kt @@ -86,13 +86,13 @@ internal fun Project.configureSyncIosComposeResources( extraSpecAttributes["resources"] = specAttr project.tasks.named("podInstall").configure { it.doFirst { - if (extraSpecAttributes["resources"] != specAttr) { - error(""" - |Kotlin.cocoapods.extraSpecAttributes["resources"] is not compatible with Compose Multiplatform's resources management for iOS. - | * Recommended action: remove extraSpecAttributes["resources"] from '${project.buildFile}' and run '${project.path}:podInstall' once; - | * Alternative action: turn off Compose Multiplatform's resources management for iOS by adding '${ComposeProperties.SYNC_RESOURCES_PROPERTY}=false' to your gradle.properties; - """.trimMargin()) - } + if (extraSpecAttributes["resources"] != specAttr) error( + """ + |Kotlin.cocoapods.extraSpecAttributes["resources"] is not compatible with Compose Multiplatform's resources management for iOS. + | * Recommended action: remove extraSpecAttributes["resources"] from '${project.buildFile}' and run '${project.path}:podInstall' once; + | * Alternative action: turn off Compose Multiplatform's resources management for iOS by adding '${ComposeProperties.SYNC_RESOURCES_PROPERTY}=false' to your gradle.properties; + """.trimMargin() + ) syncDir.mkdirs() } } @@ -113,7 +113,7 @@ private fun Framework.isCocoapodsFramework() = name.startsWith("pod") private fun Framework.getFinalResourcesDir(): Provider { val providers = project.providers return if (isCocoapodsFramework()) { - project.layout.buildDirectory.dir("compose/ios/$baseName/$IOS_COMPOSE_RESOURCES_ROOT_DIR/") + project.layout.buildDirectory.dir("compose/cocoapods/$IOS_COMPOSE_RESOURCES_ROOT_DIR/") } else { providers.environmentVariable("BUILT_PRODUCTS_DIR") .zip( diff --git a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/ResourcesTest.kt b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/ResourcesTest.kt index 07346a051c..3a3da032cf 100644 --- a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/ResourcesTest.kt +++ b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/ResourcesTest.kt @@ -706,8 +706,15 @@ class ResourcesTest : GradlePluginTestBase() { check.taskNoSource(":prepareComposeResourcesTaskForIosX64Main") check.taskSkipped(":generateResourceAccessorsForIosX64Main") - file("build/compose/ios/shared/compose-resources/drawable/compose-multiplatform.xml").checkExists() - file("build/compose/ios/shared/compose-resources/drawable/icon.xml").checkExists() + file("build/compose/cocoapods/compose-resources/drawable/compose-multiplatform.xml").checkExists() + file("build/compose/cocoapods/compose-resources/drawable/icon.xml").checkExists() + } + + gradle(":podspec", "-Pkotlin.native.cocoapods.generate.wrapper=true").checks { + assertEqualTextFiles( + file("iosResources.podspec"), + file("expected/iosResources.podspec") + ) } } } diff --git a/gradle-plugins/compose/src/test/test-projects/misc/iosResources/expected/iosResources.podspec b/gradle-plugins/compose/src/test/test-projects/misc/iosResources/expected/iosResources.podspec new file mode 100644 index 0000000000..f08c84b958 --- /dev/null +++ b/gradle-plugins/compose/src/test/test-projects/misc/iosResources/expected/iosResources.podspec @@ -0,0 +1,50 @@ +Pod::Spec.new do |spec| + spec.name = 'iosResources' + spec.version = '1.0' + spec.homepage = 'Link to a Kotlin/Native module homepage' + spec.source = { :http=> ''} + spec.authors = '' + spec.license = '' + spec.summary = 'Some description for a Kotlin/Native module' + spec.vendored_frameworks = 'build/cocoapods/framework/shared.framework' + spec.libraries = 'c++' + + spec.dependency 'Base64', '1.1.2' + + if !Dir.exist?('build/cocoapods/framework/shared.framework') || Dir.empty?('build/cocoapods/framework/shared.framework') + raise " + + Kotlin framework 'shared' doesn't exist yet, so a proper Xcode project can't be generated. + 'pod install' should be executed after running ':generateDummyFramework' Gradle task: + + ./gradlew :generateDummyFramework + + Alternatively, proper pod installation is performed during Gradle sync in the IDE (if Podfile location is set)" + end + + spec.pod_target_xcconfig = { + 'KOTLIN_PROJECT_PATH' => '', + 'PRODUCT_MODULE_NAME' => 'shared', + } + + spec.script_phases = [ + { + :name => 'Build iosResources', + :execution_position => :before_compile, + :shell_path => '/bin/sh', + :script => <<-SCRIPT + if [ "YES" = "$OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED" ]; then + echo "Skipping Gradle build task invocation due to OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED environment variable set to \"YES\"" + exit 0 + fi + set -ev + REPO_ROOT="$PODS_TARGET_SRCROOT" + "$REPO_ROOT/gradlew" -p "$REPO_ROOT" $KOTLIN_PROJECT_PATH:syncFramework \ + -Pkotlin.native.cocoapods.platform=$PLATFORM_NAME \ + -Pkotlin.native.cocoapods.archs="$ARCHS" \ + -Pkotlin.native.cocoapods.configuration="$CONFIGURATION" + SCRIPT + } + ] + spec.resources = ['build/compose/cocoapods/compose-resources'] +end \ No newline at end of file