Skip to content
This repository was archived by the owner on Oct 19, 2021. It is now read-only.

Commit 2c55461

Browse files
authored
Merge pull request #4 from touchlab/sh/framework-config
Allow Framework Configuration
2 parents ae3a46b + 2795525 commit 2c55461

File tree

3 files changed

+45
-23
lines changed

3 files changed

+45
-23
lines changed

gradle-plugin/src/main/kotlin/co/touchlab/kotlin/gradle/targets/native/cocoapods/CocoapodsExtension.kt

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import org.gradle.api.tasks.Input
1313
import org.gradle.api.tasks.Internal
1414
import org.gradle.api.tasks.Nested
1515
import org.gradle.api.tasks.Optional
16+
import org.jetbrains.kotlin.gradle.plugin.mpp.Framework
1617

1718
open class CocoapodsExtension(private val project: Project) {
1819
@get:Input
@@ -47,17 +48,23 @@ open class CocoapodsExtension(private val project: Project) {
4748
@Input
4849
var homepage: String? = null
4950

50-
/**
51-
* Configure framework name of the pod built from this project.
52-
*/
53-
@Input
54-
var frameworkName: String = project.name.asValidFrameworkName()
51+
private fun Framework.setDefaults(){
52+
baseName = project.name.asValidFrameworkName()
53+
isStatic = true
54+
}
5555

56-
/**
57-
* Configure if framework should be static.
58-
*/
56+
internal var frameworkConfiguration: Framework.() -> Unit = {}
57+
58+
internal fun configureFramework(framework: Framework){
59+
framework.setDefaults()
60+
framework.frameworkConfiguration()
61+
}
62+
63+
@Optional
5964
@Input
60-
var isStatic: Boolean = true
65+
fun framework(configure: Framework.() -> Unit) {
66+
frameworkConfiguration = configure
67+
}
6168

6269
private val _pods = project.container(CocoapodsDependency::class.java)
6370

@@ -84,9 +91,9 @@ open class CocoapodsExtension(private val project: Project) {
8491
}
8592

8693
data class CocoapodsDependency(
87-
private val name: String,
88-
@get:Optional @get:Input val version: String?,
89-
@get:Input val moduleName: String
94+
private val name: String,
95+
@get:Optional @get:Input val version: String?,
96+
@get:Input val moduleName: String
9097
) : Named {
9198
@Input
9299
override fun getName(): String = name

gradle-plugin/src/main/kotlin/co/touchlab/kotlin/gradle/targets/native/cocoapods/KotlinCocoapodsPlugin.kt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
1818
import co.touchlab.kotlin.gradle.tasks.*
1919
import co.touchlab.kotlin.gradle.utils.asValidTaskName
2020
import co.touchlab.kotlin.gradle.utils.lowerCamelCaseName
21+
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
2122
import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask
2223
import org.jetbrains.kotlin.konan.target.HostManager
2324
import org.jetbrains.kotlin.konan.target.KonanTarget
@@ -63,11 +64,8 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
6364

6465
private fun createDefaultFrameworks(kotlinExtension: KotlinMultiplatformExtension, cocoapodsExtension: CocoapodsExtension) {
6566
kotlinExtension.supportedTargets().all { target ->
66-
target.binaries.framework {
67-
baseName = cocoapodsExtension.frameworkName
68-
// baseNameProvider = project.provider { cocoapodsExtension.frameworkName }
69-
println("cocoapodsExtension.isStatic ${cocoapodsExtension.isStatic}")
70-
isStatic = cocoapodsExtension.isStatic
67+
target.binaries.framework{
68+
cocoapodsExtension.configureFramework(this)
7169
}
7270
}
7371
}
@@ -164,17 +162,27 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
164162
}
165163

166164
private fun createPodspecGenerationTask(
167-
project: Project,
168-
cocoapodsExtension: CocoapodsExtension
165+
project: Project,
166+
kotlinExtension: KotlinMultiplatformExtension,
167+
cocoapodsExtension: CocoapodsExtension
169168
) {
169+
val firstFramework = kotlinExtension.supportedTargets()
170+
.single()
171+
.binaries
172+
.run {
173+
findFramework(NativeBuildType.RELEASE) ?: getFramework(NativeBuildType.DEBUG)
174+
}
175+
170176
val dummyFrameworkTask = project.tasks.create("generateDummyFramework", DummyFrameworkTask::class.java) {
171177
it.settings = cocoapodsExtension
178+
it.framework = firstFramework
172179
}
173180

174181
project.tasks.create("podspec", PodspecTask::class.java) {
175182
it.group = TASK_GROUP
176183
it.description = "Generates a podspec file for CocoaPods import"
177184
it.settings = cocoapodsExtension
185+
it.framework = firstFramework
178186
it.dependsOn(dummyFrameworkTask)
179187
val generateWrapper = project.findProperty(GENERATE_WRAPPER_PROPERTY)?.toString()?.toBoolean() ?: false
180188
if (generateWrapper) {
@@ -259,7 +267,7 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
259267
afterEvaluate {
260268
createDefaultFrameworks(kotlinExtension, cocoapodsExtension)
261269
createSyncTask(project, kotlinExtension)
262-
createPodspecGenerationTask(project, cocoapodsExtension)
270+
createPodspecGenerationTask(project, kotlinExtension, cocoapodsExtension)
263271
createInterops(project, kotlinExtension, cocoapodsExtension)
264272
}
265273
}

gradle-plugin/src/main/kotlin/co/touchlab/kotlin/gradle/targets/native/tasks/CocoapodsTasks.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import co.touchlab.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin.Companio
1818
import co.touchlab.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin.Companion.SYNC_TASK_NAME
1919
import co.touchlab.kotlin.gradle.plugin.cocoapods.asValidFrameworkName
2020
import co.touchlab.kotlin.gradle.plugin.cocoapods.cocoapodsBuildDirs
21+
import org.jetbrains.kotlin.gradle.plugin.mpp.Framework
2122
import java.io.File
2223

2324
/**
@@ -32,11 +33,14 @@ open class PodspecTask : DefaultTask() {
3233
val outputFile: File = project.projectDir.resolve("$specName.podspec")
3334

3435
@Input
35-
val frameworkNameProvider: Provider<String> = project.provider { settings.frameworkName }
36+
val frameworkNameProvider: Provider<String> = project.provider { framework.baseName}
3637

3738
@get:Nested
3839
internal lateinit var settings: CocoapodsExtension
3940

41+
@get:Nested
42+
internal lateinit var framework: Framework
43+
4044
// TODO: Handle Framework name customization - rename the framework during sync process.
4145
@TaskAction
4246
fun generate() {
@@ -71,7 +75,7 @@ open class PodspecTask : DefaultTask() {
7175
| spec.license = '${settings.license.orEmpty()}'
7276
| spec.summary = '${settings.summary.orEmpty()}'
7377
|
74-
|${if(settings.isStatic){" spec.static_framework = true"}else{""}}
78+
|${if(framework.isStatic){" spec.static_framework = true"}else{""}}
7579
| spec.vendored_frameworks = "$frameworkDir/${frameworkNameProvider.get()}.framework"
7680
| spec.libraries = "c++"
7781
| spec.module_name = "#{spec.name}_umbrella"
@@ -143,11 +147,14 @@ open class DummyFrameworkTask : DefaultTask() {
143147
val destinationDir = project.cocoapodsBuildDirs.framework
144148

145149
@Input
146-
val frameworkNameProvider: Provider<String> = project.provider { settings.frameworkName }
150+
val frameworkNameProvider: Provider<String> = project.provider { framework.baseName }
147151

148152
@get:Nested
149153
internal lateinit var settings: CocoapodsExtension
150154

155+
@get:Nested
156+
internal lateinit var framework: Framework
157+
151158
private val frameworkDir: File
152159
get() = destinationDir.resolve("${frameworkNameProvider.get()}.framework")
153160

0 commit comments

Comments
 (0)