From a5bb76f0e6bd35aa2241c9b2ea322531bb7c26f9 Mon Sep 17 00:00:00 2001 From: Sam Hill Date: Thu, 7 May 2020 16:36:43 -0400 Subject: [PATCH 1/3] Use first framework Get the framework from the first target rather than using single(). There may be multiple supported targets. We can grab just the first because we configure the framework the same for every supported target --- .../gradle/targets/native/cocoapods/KotlinCocoapodsPlugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle-plugin/src/main/kotlin/co/touchlab/kotlin/gradle/targets/native/cocoapods/KotlinCocoapodsPlugin.kt b/gradle-plugin/src/main/kotlin/co/touchlab/kotlin/gradle/targets/native/cocoapods/KotlinCocoapodsPlugin.kt index 177e13e..e89ef27 100644 --- a/gradle-plugin/src/main/kotlin/co/touchlab/kotlin/gradle/targets/native/cocoapods/KotlinCocoapodsPlugin.kt +++ b/gradle-plugin/src/main/kotlin/co/touchlab/kotlin/gradle/targets/native/cocoapods/KotlinCocoapodsPlugin.kt @@ -167,7 +167,7 @@ open class KotlinCocoapodsPlugin : Plugin { cocoapodsExtension: CocoapodsExtension ) { val firstFramework = kotlinExtension.supportedTargets() - .single() + .first() .binaries .run { findFramework(NativeBuildType.RELEASE) ?: getFramework(NativeBuildType.DEBUG) From 14b7cd455e21cdf22237468dd28e073fb3a4e6be Mon Sep 17 00:00:00 2001 From: Sam Hill Date: Fri, 8 May 2020 12:31:17 -0400 Subject: [PATCH 2/3] Update podspec inputs --- .../native/cocoapods/CocoapodsExtension.kt | 21 ++++++------- .../native/cocoapods/KotlinCocoapodsPlugin.kt | 6 ++-- .../targets/native/tasks/CocoapodsTasks.kt | 30 ++++++++----------- 3 files changed, 26 insertions(+), 31 deletions(-) diff --git a/gradle-plugin/src/main/kotlin/co/touchlab/kotlin/gradle/targets/native/cocoapods/CocoapodsExtension.kt b/gradle-plugin/src/main/kotlin/co/touchlab/kotlin/gradle/targets/native/cocoapods/CocoapodsExtension.kt index 428e4ee..8e3a394 100644 --- a/gradle-plugin/src/main/kotlin/co/touchlab/kotlin/gradle/targets/native/cocoapods/CocoapodsExtension.kt +++ b/gradle-plugin/src/main/kotlin/co/touchlab/kotlin/gradle/targets/native/cocoapods/CocoapodsExtension.kt @@ -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 @@ -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? = null + + fun framework(action: Action) { + frameworkAction = action } private val _pods = project.container(CocoapodsDependency::class.java) diff --git a/gradle-plugin/src/main/kotlin/co/touchlab/kotlin/gradle/targets/native/cocoapods/KotlinCocoapodsPlugin.kt b/gradle-plugin/src/main/kotlin/co/touchlab/kotlin/gradle/targets/native/cocoapods/KotlinCocoapodsPlugin.kt index e89ef27..f4a42c4 100644 --- a/gradle-plugin/src/main/kotlin/co/touchlab/kotlin/gradle/targets/native/cocoapods/KotlinCocoapodsPlugin.kt +++ b/gradle-plugin/src/main/kotlin/co/touchlab/kotlin/gradle/targets/native/cocoapods/KotlinCocoapodsPlugin.kt @@ -174,15 +174,15 @@ open class KotlinCocoapodsPlugin : Plugin { } 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) { diff --git a/gradle-plugin/src/main/kotlin/co/touchlab/kotlin/gradle/targets/native/tasks/CocoapodsTasks.kt b/gradle-plugin/src/main/kotlin/co/touchlab/kotlin/gradle/targets/native/tasks/CocoapodsTasks.kt index 814a50d..1d8f912 100644 --- a/gradle-plugin/src/main/kotlin/co/touchlab/kotlin/gradle/targets/native/tasks/CocoapodsTasks.kt +++ b/gradle-plugin/src/main/kotlin/co/touchlab/kotlin/gradle/targets/native/tasks/CocoapodsTasks.kt @@ -32,14 +32,14 @@ open class PodspecTask : DefaultTask() { @OutputFile val outputFile: File = project.projectDir.resolve("$specName.podspec") - @Input - val frameworkNameProvider: Provider = project.provider { framework.baseName} + @get:Input + lateinit var frameworkName:String - @get:Nested - internal lateinit var settings: CocoapodsExtension + @get:Input + 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 @@ -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" | @@ -146,17 +146,11 @@ open class DummyFrameworkTask : DefaultTask() { @OutputDirectory val destinationDir = project.cocoapodsBuildDirs.framework - @Input - val frameworkNameProvider: Provider = 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() @@ -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 } From ccf7fda033ce2e46e2335ebb8f4b38bc457606c6 Mon Sep 17 00:00:00 2001 From: Sam Hill Date: Thu, 14 May 2020 11:31:18 -0400 Subject: [PATCH 3/3] Make inputs internal --- .../kotlin/gradle/targets/native/tasks/CocoapodsTasks.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle-plugin/src/main/kotlin/co/touchlab/kotlin/gradle/targets/native/tasks/CocoapodsTasks.kt b/gradle-plugin/src/main/kotlin/co/touchlab/kotlin/gradle/targets/native/tasks/CocoapodsTasks.kt index 1d8f912..7f1856c 100644 --- a/gradle-plugin/src/main/kotlin/co/touchlab/kotlin/gradle/targets/native/tasks/CocoapodsTasks.kt +++ b/gradle-plugin/src/main/kotlin/co/touchlab/kotlin/gradle/targets/native/tasks/CocoapodsTasks.kt @@ -33,10 +33,10 @@ open class PodspecTask : DefaultTask() { val outputFile: File = project.projectDir.resolve("$specName.podspec") @get:Input - lateinit var frameworkName:String + internal lateinit var frameworkName:String @get:Input - var isStatic:Boolean = true + internal var isStatic:Boolean = true @get:Nested internal lateinit var settings: CocoapodsExtension