Skip to content
This repository was archived by the owner on Oct 19, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@file:Suppress("PackageDirectoryMismatch") // Old package for compatibility
package co.touchlab.kotlin.gradle.plugin.cocoapods

import org.gradle.api.Action
import org.gradle.api.Named
import org.gradle.api.NamedDomainObjectSet
import org.gradle.api.Project
Expand Down Expand Up @@ -48,22 +49,22 @@ open class CocoapodsExtension(private val project: Project) {
@Input
var homepage: String? = null

private fun Framework.setDefaults(){
private fun Framework.setDefaults() {
baseName = project.name.asValidFrameworkName()
isStatic = true
}

internal var frameworkConfiguration: Framework.() -> Unit = {}

internal fun configureFramework(framework: Framework){
framework.setDefaults()
framework.frameworkConfiguration()
internal fun configureFramework(frameworkToConfigure: Framework) {
frameworkToConfigure.setDefaults()
frameworkAction?.execute(frameworkToConfigure)
}

@Optional
@Input
fun framework(configure: Framework.() -> Unit) {
frameworkConfiguration = configure
//Not an input because we pull relevant values from the configured frameworks instead of here
@Internal
var frameworkAction: Action<Framework>? = null

fun framework(action: Action<Framework>) {
frameworkAction = action
}

private val _pods = project.container(CocoapodsDependency::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,22 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
cocoapodsExtension: CocoapodsExtension
) {
val firstFramework = kotlinExtension.supportedTargets()
.single()
.first()
.binaries
.run {
findFramework(NativeBuildType.RELEASE) ?: getFramework(NativeBuildType.DEBUG)
}

val dummyFrameworkTask = project.tasks.create("generateDummyFramework", DummyFrameworkTask::class.java) {
it.settings = cocoapodsExtension
it.framework = firstFramework
it.frameworkName = firstFramework.baseName
}

project.tasks.create("podspec", PodspecTask::class.java) {
it.group = TASK_GROUP
it.description = "Generates a podspec file for CocoaPods import"
it.settings = cocoapodsExtension
it.framework = firstFramework
it.frameworkName = firstFramework.baseName
it.isStatic = firstFramework.isStatic
it.dependsOn(dummyFrameworkTask)
val generateWrapper = project.findProperty(GENERATE_WRAPPER_PROPERTY)?.toString()?.toBoolean() ?: false
if (generateWrapper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ open class PodspecTask : DefaultTask() {
@OutputFile
val outputFile: File = project.projectDir.resolve("$specName.podspec")

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

@get:Nested
internal lateinit var settings: CocoapodsExtension
@get:Input
internal var isStatic:Boolean = true

@get:Nested
internal lateinit var framework: Framework
internal lateinit var settings: CocoapodsExtension

// TODO: Handle Framework name customization - rename the framework during sync process.
@TaskAction
Expand Down Expand Up @@ -75,8 +75,8 @@ open class PodspecTask : DefaultTask() {
| spec.license = '${settings.license.orEmpty()}'
| spec.summary = '${settings.summary.orEmpty()}'
|
|${if(framework.isStatic){" spec.static_framework = true"}else{""}}
| spec.vendored_frameworks = "$frameworkDir/${frameworkNameProvider.get()}.framework"
|${if(isStatic){" spec.static_framework = true"}else{""}}
| spec.vendored_frameworks = "$frameworkDir/$frameworkName.framework"
| spec.libraries = "c++"
| spec.module_name = "#{spec.name}_umbrella"
|
Expand Down Expand Up @@ -146,17 +146,11 @@ open class DummyFrameworkTask : DefaultTask() {
@OutputDirectory
val destinationDir = project.cocoapodsBuildDirs.framework

@Input
val frameworkNameProvider: Provider<String> = project.provider { framework.baseName }

@get:Nested
internal lateinit var settings: CocoapodsExtension

@get:Nested
internal lateinit var framework: Framework
@get:Input
lateinit var frameworkName:String

private val frameworkDir: File
get() = destinationDir.resolve("${frameworkNameProvider.get()}.framework")
get() = destinationDir.resolve("$frameworkName.framework")

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

// Copy files for the dummy framework.
copyFrameworkFile("Info.plist")
copyFrameworkFile("dummy", frameworkNameProvider.get())
copyFrameworkFile("dummy", frameworkName)
copyFrameworkFile("Headers/dummy.h")
copyFrameworkTextFile("Modules/module.modulemap") {
if (it == "framework module dummy {") {
it.replace("dummy", frameworkNameProvider.get())
it.replace("dummy", frameworkName)
} else {
it
}
Expand Down