Skip to content

Commit

Permalink
fixup! Support compose resources in native macOS framework in additio…
Browse files Browse the repository at this point in the history
…n to existing executable support
  • Loading branch information
Thomas-Vos committed Nov 29, 2024
1 parent 100409a commit 2a806ae
Showing 1 changed file with 5 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal fun Project.configureSyncIosComposeResources(
nativeTarget.binaries.withType(Framework::class.java).all { iosFramework ->
val frameworkClassifier = iosFramework.getClassifier()
val checkNoSandboxTask = tasks.registerOrConfigure<CheckCanAccessComposeResourcesDirectory>(
"checkCanSync${frameworkClassifier}ComposeResourcesFor${nativeTarget.getTaskSuffix()}"
"checkCanSync${frameworkClassifier}ComposeResourcesForIos"
) {}

val frameworkResources = files()
Expand Down Expand Up @@ -115,29 +115,20 @@ private fun Framework.getClassifier(): String {
else name.substringBeforeLast(suffix.uppercaseFirstChar()).uppercaseFirstChar()
}

internal fun Framework.getSyncResourcesTaskName() =
"sync${getClassifier()}ComposeResourcesFor${target.getTaskSuffix()}"
internal fun Framework.getSyncResourcesTaskName() = "sync${getClassifier()}ComposeResourcesForIos"

private fun Framework.isCocoapodsFramework() = name.startsWith("pod")

private fun KotlinNativeTarget.getTaskSuffix(): String =
when {
isIosTarget() -> "Ios"
isMacTarget() -> "Macos"
else -> error("Unknown target: $this")
}

private fun Framework.getFinalResourcesDir(): Provider<Directory> {
val providers = project.providers
return if (isCocoapodsFramework()) {
project.layout.buildDirectory.dir("compose/cocoapods/$IOS_COMPOSE_RESOURCES_ROOT_DIR/")
} else {
providers.environmentVariable("BUILT_PRODUCTS_DIR")
.zip(
providers.environmentVariable("CONTENTS_FOLDER_PATH")
) { builtProductsDir, contentsFolderPath ->
val pathSuffix = if (target.isMacTarget()) "/Resources" else ""
File("$builtProductsDir/$contentsFolderPath$pathSuffix/$IOS_COMPOSE_RESOURCES_ROOT_DIR").canonicalPath
providers.environmentVariable("UNLOCALIZED_RESOURCES_FOLDER_PATH")
) { builtProductsDir, unlocalizedResourcesFolderPath ->
File("$builtProductsDir/$unlocalizedResourcesFolderPath/$IOS_COMPOSE_RESOURCES_ROOT_DIR").canonicalPath
}
.flatMap {
project.objects.directoryProperty().apply { set(File(it)) }
Expand Down

0 comments on commit 2a806ae

Please sign in to comment.