Skip to content

Commit d1ebefb

Browse files
committed
#827 fix apple executables run from gradle
1 parent 1b3bf3e commit d1ebefb

File tree

5 files changed

+33
-77
lines changed

5 files changed

+33
-77
lines changed

resources-generator/src/main/kotlin/dev/icerock/gradle/MultiplatformResourcesPlugin.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import dev.icerock.gradle.generator.platform.apple.setupAppleKLibResources
1414
import dev.icerock.gradle.generator.platform.apple.setupExecutableResources
1515
import dev.icerock.gradle.generator.platform.apple.setupFatFrameworkTasks
1616
import dev.icerock.gradle.generator.platform.apple.setupFrameworkResources
17-
import dev.icerock.gradle.generator.platform.apple.setupTestsResources
1817
import dev.icerock.gradle.generator.platform.js.setupJsKLibResources
1918
import dev.icerock.gradle.generator.platform.js.setupJsResourcesWithLinkTask
2019
import dev.icerock.gradle.tasks.GenerateMultiplatformResourcesTask
@@ -85,7 +84,6 @@ open class MultiplatformResourcesPlugin : Plugin<Project> {
8584
if (target is KotlinNativeTarget) {
8685
setupExecutableResources(target = target)
8786
setupFrameworkResources(target = target)
88-
setupTestsResources(target = target)
8987
}
9088

9189
if (target is KotlinJsIrTarget) {
@@ -186,6 +184,7 @@ open class MultiplatformResourcesPlugin : Plugin<Project> {
186184
sourceSet.resources.srcDir(genTaskProvider.map { it.outputResourcesDir })
187185
sourceSet.resources.srcDir(genTaskProvider.map { it.outputAssetsDir })
188186
}
187+
189188
KotlinPlatformType.androidJvm -> {
190189
// Fix: android sourceSets indexation in IDE
191190
// Usage of api of v2.model in AGP broken for IDE resources indexing
@@ -200,6 +199,7 @@ open class MultiplatformResourcesPlugin : Plugin<Project> {
200199
// see: dev.icerock.gradle.generator.platform.android.SetupAndroidUtilsKt.addGenerationTaskDependency
201200
// androidSourceSet.assets.srcDir(genTaskProvider.map { it.outputAssetsDir })
202201
}
202+
203203
KotlinPlatformType.common, KotlinPlatformType.native,
204204
KotlinPlatformType.wasm -> Unit
205205
}

resources-generator/src/main/kotlin/dev/icerock/gradle/data/ExtractingKotlinLibraryLayout.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ import org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl
1717
* https://github.com/JetBrains/kotlin/blob/00984f32ac1ebc2e7fb71b440c282be2a8b05f36/compiler/util-klib/src/org/jetbrains/kotlin/library/impl/KotlinLibraryLayoutImpl.kt
1818
*/
1919

20-
open class ExtractingKotlinLibraryLayout(zipped: KotlinLibraryLayoutImpl) : KotlinLibraryLayout {
20+
internal open class ExtractingKotlinLibraryLayout(zipped: KotlinLibraryLayoutImpl) : KotlinLibraryLayout {
2121
override val libFile: File get() = error("Extracting layout doesn't extract its own root")
2222
override val libraryName = zipped.libraryName
2323
override val component = zipped.component
2424
}
2525

26-
class ExtractingBaseLibraryImpl(zipped: KotlinLibraryLayoutImpl) : ExtractingKotlinLibraryLayout(zipped) {
26+
internal class ExtractingBaseLibraryImpl(zipped: KotlinLibraryLayoutImpl) : ExtractingKotlinLibraryLayout(zipped) {
2727
override val manifestFile: File by lazy { zipped.extract(zipped.manifestFile) }
2828
override val resourcesDir: File by lazy { zipped.extractDir(zipped.resourcesDir) }
2929
}

resources-generator/src/main/kotlin/dev/icerock/gradle/generator/platform/apple/SetupAppleUtils.kt

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractExecutable
3737
import org.jetbrains.kotlin.gradle.plugin.mpp.Framework
3838
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
3939
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
40-
import org.jetbrains.kotlin.gradle.plugin.mpp.TestExecutable
4140
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFrameworkTask
4241
import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask
4342
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
@@ -222,37 +221,39 @@ internal fun registerCopyXCFrameworkResourcesToAppTask(
222221
}
223222

224223
internal fun setupExecutableResources(target: KotlinNativeTarget) {
225-
val project: Project = target.project
226224
target.binaries.withType<AbstractExecutable>().configureEach { executable ->
227-
val copyTaskName: String =
228-
executable.linkTaskProvider.name.replace("link", "copyResources")
225+
setupExecutableGradleResources(executable)
226+
setupExecutableXcodeResources(executable)
227+
}
228+
}
229229

230-
project.tasks.register<CopyExecutableResourcesToApp>(copyTaskName) {
231-
dependsOn(executable.linkTaskProvider)
230+
internal fun setupExecutableXcodeResources(executable: AbstractExecutable) {
231+
val copyTaskName: String = executable.linkTaskProvider.name.replace("link", "copyResources")
232+
val project: Project = executable.project
232233

233-
klibs.from(executable.linkTaskProvider.map { it.klibs })
234+
project.tasks.register<CopyExecutableResourcesToApp>(copyTaskName) {
235+
dependsOn(executable.linkTaskProvider)
234236

235-
outputDirectory.set(
236-
project.layout.dir(
237-
project.provider {
238-
val buildProductsDir =
239-
project.property("moko.resources.BUILT_PRODUCTS_DIR") as String
240-
val contentsFolderPath =
241-
project.property("moko.resources.CONTENTS_FOLDER_PATH") as String
237+
klibs.from(executable.linkTaskProvider.map { it.klibs })
238+
239+
outputDirectory.set(
240+
project.layout.dir(
241+
project.provider {
242+
val buildProductsDir =
243+
project.property("moko.resources.BUILT_PRODUCTS_DIR") as String
244+
val contentsFolderPath =
245+
project.property("moko.resources.CONTENTS_FOLDER_PATH") as String
242246

243-
File("$buildProductsDir/$contentsFolderPath")
244-
}
245-
)
247+
File("$buildProductsDir/$contentsFolderPath")
248+
}
246249
)
247-
}
250+
)
248251
}
249252
}
250253

251-
internal fun setupTestsResources(target: KotlinNativeTarget) {
252-
target.binaries.withType<TestExecutable>().configureEach { executable ->
253-
executable.linkTaskProvider.configure { link ->
254-
link.doLast(CopyResourcesFromKLibsToExecutableAction())
255-
}
254+
internal fun setupExecutableGradleResources(executable: AbstractExecutable) {
255+
executable.linkTaskProvider.configure { link ->
256+
link.doLast(CopyResourcesFromKLibsToExecutableAction())
256257
}
257258
}
258259

samples/compose-resources-gallery/macosApp/build.gradle.kts

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
2-
import dev.icerock.gradle.data.ExtractingBaseLibraryImpl
3-
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink
4-
import java.io.File
5-
61
plugins {
72
kotlin("multiplatform")
83
id("org.jetbrains.compose")
@@ -66,43 +61,3 @@ kotlin {
6661
multiplatformResources {
6762
resourcesPackage.set("dev.icerock.moko.resources.sample")
6863
}
69-
70-
// TODO move to moko-resources gradle plugin
71-
// copy .bundle from all .klib to .kexe
72-
tasks.withType<KotlinNativeLink>().configureEach {
73-
val linkTask: KotlinNativeLink = this
74-
val outputDir: File = this.outputFile.get().parentFile
75-
76-
@Suppress("ObjectLiteralToLambda") // lambda broke up-to-date
77-
val action = object : Action<Task> {
78-
override fun execute(t: Task) {
79-
(linkTask.libraries + linkTask.sources)
80-
.filter { library -> library.extension == "klib" }
81-
.filter(File::exists)
82-
.forEach { inputFile ->
83-
val klibKonan = org.jetbrains.kotlin.konan.file.File(inputFile.path)
84-
val klib = org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl(
85-
klib = klibKonan,
86-
component = "default"
87-
)
88-
val layout = ExtractingBaseLibraryImpl(klib)
89-
90-
// extracting bundles
91-
layout
92-
.resourcesDir
93-
.absolutePath
94-
.let(::File)
95-
.listFiles { file: File -> file.extension == "bundle" }
96-
// copying bundles to app
97-
?.forEach {
98-
logger.info("${it.absolutePath} copying to $outputDir")
99-
it.copyRecursively(
100-
target = File(outputDir, it.name),
101-
overwrite = true
102-
)
103-
}
104-
}
105-
}
106-
}
107-
doLast(action)
108-
}

samples/kotlin-2-sample/gradle/libs.versions.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[versions]
2-
agp = "8.11.0"
3-
kotlin = "2.2.0"
4-
compose = "1.8.3"
5-
compose-material3 = "1.3.2"
6-
androidx-activityCompose = "1.10.1"
2+
agp = "8.4.0"
3+
kotlin = "2.0.0"
4+
compose = "1.6.7"
5+
compose-material3 = "1.2.1"
6+
androidx-activityCompose = "1.9.0"
77

88
[libraries]
99
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }

0 commit comments

Comments
 (0)