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 @@ -13,6 +13,7 @@ import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Nested
import org.gradle.api.tasks.Optional
import org.jetbrains.kotlin.gradle.plugin.mpp.Framework

open class CocoapodsExtension(private val project: Project) {
@get:Input
Expand Down Expand Up @@ -47,17 +48,23 @@ open class CocoapodsExtension(private val project: Project) {
@Input
var homepage: String? = null

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

/**
* Configure if framework should be static.
*/
internal var frameworkConfiguration: Framework.() -> Unit = {}

internal fun configureFramework(framework: Framework){
framework.setDefaults()
framework.frameworkConfiguration()
}

@Optional
@Input
var isStatic: Boolean = true
fun framework(configure: Framework.() -> Unit) {
frameworkConfiguration = configure
}

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

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

data class CocoapodsDependency(
private val name: String,
@get:Optional @get:Input val version: String?,
@get:Input val moduleName: String
private val name: String,
@get:Optional @get:Input val version: String?,
@get:Input val moduleName: String
) : Named {
@Input
override fun getName(): String = name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import co.touchlab.kotlin.gradle.tasks.*
import co.touchlab.kotlin.gradle.utils.asValidTaskName
import co.touchlab.kotlin.gradle.utils.lowerCamelCaseName
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask
import org.jetbrains.kotlin.konan.target.HostManager
import org.jetbrains.kotlin.konan.target.KonanTarget
Expand Down Expand Up @@ -63,11 +64,8 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {

private fun createDefaultFrameworks(kotlinExtension: KotlinMultiplatformExtension, cocoapodsExtension: CocoapodsExtension) {
kotlinExtension.supportedTargets().all { target ->
target.binaries.framework {
baseName = cocoapodsExtension.frameworkName
// baseNameProvider = project.provider { cocoapodsExtension.frameworkName }
println("cocoapodsExtension.isStatic ${cocoapodsExtension.isStatic}")
isStatic = cocoapodsExtension.isStatic
target.binaries.framework{
cocoapodsExtension.configureFramework(this)
}
}
}
Expand Down Expand Up @@ -164,17 +162,27 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
}

private fun createPodspecGenerationTask(
project: Project,
cocoapodsExtension: CocoapodsExtension
project: Project,
kotlinExtension: KotlinMultiplatformExtension,
cocoapodsExtension: CocoapodsExtension
) {
val firstFramework = kotlinExtension.supportedTargets()
.single()
.binaries
.run {
findFramework(NativeBuildType.RELEASE) ?: getFramework(NativeBuildType.DEBUG)
}

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

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.dependsOn(dummyFrameworkTask)
val generateWrapper = project.findProperty(GENERATE_WRAPPER_PROPERTY)?.toString()?.toBoolean() ?: false
if (generateWrapper) {
Expand Down Expand Up @@ -259,7 +267,7 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
afterEvaluate {
createDefaultFrameworks(kotlinExtension, cocoapodsExtension)
createSyncTask(project, kotlinExtension)
createPodspecGenerationTask(project, cocoapodsExtension)
createPodspecGenerationTask(project, kotlinExtension, cocoapodsExtension)
createInterops(project, kotlinExtension, cocoapodsExtension)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import co.touchlab.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin.Companio
import co.touchlab.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin.Companion.SYNC_TASK_NAME
import co.touchlab.kotlin.gradle.plugin.cocoapods.asValidFrameworkName
import co.touchlab.kotlin.gradle.plugin.cocoapods.cocoapodsBuildDirs
import org.jetbrains.kotlin.gradle.plugin.mpp.Framework
import java.io.File

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

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

@get:Nested
internal lateinit var settings: CocoapodsExtension

@get:Nested
internal lateinit var framework: Framework

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

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

@get:Nested
internal lateinit var settings: CocoapodsExtension

@get:Nested
internal lateinit var framework: Framework

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

Expand Down