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

Commit 68b1959

Browse files
authored
Merge pull request #6 from touchlab/sh/firstFramework
Use first framework
2 parents dc67ea1 + ccf7fda commit 68b1959

File tree

3 files changed

+27
-32
lines changed

3 files changed

+27
-32
lines changed

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
@file:Suppress("PackageDirectoryMismatch") // Old package for compatibility
77
package co.touchlab.kotlin.gradle.plugin.cocoapods
88

9+
import org.gradle.api.Action
910
import org.gradle.api.Named
1011
import org.gradle.api.NamedDomainObjectSet
1112
import org.gradle.api.Project
@@ -48,22 +49,22 @@ open class CocoapodsExtension(private val project: Project) {
4849
@Input
4950
var homepage: String? = null
5051

51-
private fun Framework.setDefaults(){
52+
private fun Framework.setDefaults() {
5253
baseName = project.name.asValidFrameworkName()
5354
isStatic = true
5455
}
5556

56-
internal var frameworkConfiguration: Framework.() -> Unit = {}
57-
58-
internal fun configureFramework(framework: Framework){
59-
framework.setDefaults()
60-
framework.frameworkConfiguration()
57+
internal fun configureFramework(frameworkToConfigure: Framework) {
58+
frameworkToConfigure.setDefaults()
59+
frameworkAction?.execute(frameworkToConfigure)
6160
}
6261

63-
@Optional
64-
@Input
65-
fun framework(configure: Framework.() -> Unit) {
66-
frameworkConfiguration = configure
62+
//Not an input because we pull relevant values from the configured frameworks instead of here
63+
@Internal
64+
var frameworkAction: Action<Framework>? = null
65+
66+
fun framework(action: Action<Framework>) {
67+
frameworkAction = action
6768
}
6869

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

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,22 +167,22 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
167167
cocoapodsExtension: CocoapodsExtension
168168
) {
169169
val firstFramework = kotlinExtension.supportedTargets()
170-
.single()
170+
.first()
171171
.binaries
172172
.run {
173173
findFramework(NativeBuildType.RELEASE) ?: getFramework(NativeBuildType.DEBUG)
174174
}
175175

176176
val dummyFrameworkTask = project.tasks.create("generateDummyFramework", DummyFrameworkTask::class.java) {
177-
it.settings = cocoapodsExtension
178-
it.framework = firstFramework
177+
it.frameworkName = firstFramework.baseName
179178
}
180179

181180
project.tasks.create("podspec", PodspecTask::class.java) {
182181
it.group = TASK_GROUP
183182
it.description = "Generates a podspec file for CocoaPods import"
184183
it.settings = cocoapodsExtension
185-
it.framework = firstFramework
184+
it.frameworkName = firstFramework.baseName
185+
it.isStatic = firstFramework.isStatic
186186
it.dependsOn(dummyFrameworkTask)
187187
val generateWrapper = project.findProperty(GENERATE_WRAPPER_PROPERTY)?.toString()?.toBoolean() ?: false
188188
if (generateWrapper) {

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

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ open class PodspecTask : DefaultTask() {
3232
@OutputFile
3333
val outputFile: File = project.projectDir.resolve("$specName.podspec")
3434

35-
@Input
36-
val frameworkNameProvider: Provider<String> = project.provider { framework.baseName}
35+
@get:Input
36+
internal lateinit var frameworkName:String
3737

38-
@get:Nested
39-
internal lateinit var settings: CocoapodsExtension
38+
@get:Input
39+
internal var isStatic:Boolean = true
4040

4141
@get:Nested
42-
internal lateinit var framework: Framework
42+
internal lateinit var settings: CocoapodsExtension
4343

4444
// TODO: Handle Framework name customization - rename the framework during sync process.
4545
@TaskAction
@@ -75,8 +75,8 @@ open class PodspecTask : DefaultTask() {
7575
| spec.license = '${settings.license.orEmpty()}'
7676
| spec.summary = '${settings.summary.orEmpty()}'
7777
|
78-
|${if(framework.isStatic){" spec.static_framework = true"}else{""}}
79-
| spec.vendored_frameworks = "$frameworkDir/${frameworkNameProvider.get()}.framework"
78+
|${if(isStatic){" spec.static_framework = true"}else{""}}
79+
| spec.vendored_frameworks = "$frameworkDir/$frameworkName.framework"
8080
| spec.libraries = "c++"
8181
| spec.module_name = "#{spec.name}_umbrella"
8282
|
@@ -146,17 +146,11 @@ open class DummyFrameworkTask : DefaultTask() {
146146
@OutputDirectory
147147
val destinationDir = project.cocoapodsBuildDirs.framework
148148

149-
@Input
150-
val frameworkNameProvider: Provider<String> = project.provider { framework.baseName }
151-
152-
@get:Nested
153-
internal lateinit var settings: CocoapodsExtension
154-
155-
@get:Nested
156-
internal lateinit var framework: Framework
149+
@get:Input
150+
lateinit var frameworkName:String
157151

158152
private val frameworkDir: File
159-
get() = destinationDir.resolve("${frameworkNameProvider.get()}.framework")
153+
get() = destinationDir.resolve("$frameworkName.framework")
160154

161155
private fun copyResource(from: String, to: File) {
162156
to.parentFile.mkdirs()
@@ -202,11 +196,11 @@ open class DummyFrameworkTask : DefaultTask() {
202196

203197
// Copy files for the dummy framework.
204198
copyFrameworkFile("Info.plist")
205-
copyFrameworkFile("dummy", frameworkNameProvider.get())
199+
copyFrameworkFile("dummy", frameworkName)
206200
copyFrameworkFile("Headers/dummy.h")
207201
copyFrameworkTextFile("Modules/module.modulemap") {
208202
if (it == "framework module dummy {") {
209-
it.replace("dummy", frameworkNameProvider.get())
203+
it.replace("dummy", frameworkName)
210204
} else {
211205
it
212206
}

0 commit comments

Comments
 (0)