Skip to content

Commit 45f5cc9

Browse files
committed
Cocoapods Gradle configuration cache
1 parent b30233e commit 45f5cc9

File tree

3 files changed

+58
-25
lines changed

3 files changed

+58
-25
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ SONATYPE_HOST=DEFAULT
1818
RELEASE_SIGNING_ENABLED=true
1919

2020
GROUP=co.touchlab.kmmbridge
21-
VERSION_NAME=1.1.0-a3
21+
VERSION_NAME=1.1.0-a4
2222
VERSION_NAME_3x=0.3.7
2323

2424
POM_URL=https://github.com/touchlab/KMMBridge

kmmbridge/src/main/kotlin/co/touchlab/kmmbridge/artifactmanager/MavenPublishArtifactManager.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,11 @@ internal class MavenPublishArtifactManager(
8484
// There may be more than one repo, but it's also possible we get none. This will allow us to continue and trying
8585
// to use the dependency should fail.
8686
// If there are multiple repos, the repo name needs to be specified.
87-
val mavenArtifactRepositoryUrl = if (!isMavenCentral) {
87+
return if (!isMavenCentral) {
8888
findArtifactRepository(publishingExtension).url.toString()
8989
} else {
90-
"https://repo.maven.apache.org/maven2/"
90+
"https://repo.maven.apache.org/maven2"
9191
}
92-
return mavenArtifactRepositoryUrl
9392
}
9493

9594
private fun publishingTasks(project: Project): List<TaskProvider<Task>> {

kmmbridge/src/main/kotlin/co/touchlab/kmmbridge/dependencymanager/CocoapodsDependencyManager.kt

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import org.gradle.api.Task
2525
import org.gradle.api.provider.Provider
2626
import org.gradle.api.provider.ProviderFactory
2727
import org.gradle.api.tasks.TaskProvider
28-
import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension
28+
import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension.PodspecPlatformSettings
2929
import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin
3030
import org.jetbrains.kotlin.gradle.plugin.mpp.Framework
3131
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
@@ -36,6 +36,24 @@ internal sealed class SpecRepo {
3636
class Private(val url: String) : SpecRepo()
3737
}
3838

39+
/**
40+
* State storage to help avoid Gradle configuration cache issues
41+
*/
42+
internal data class SafeCocoapodsData(
43+
val ios: PodspecPlatformSettings,
44+
val osx: PodspecPlatformSettings,
45+
val tvos: PodspecPlatformSettings,
46+
val watchos: PodspecPlatformSettings,
47+
val extraSpecAttributes: MutableMap<String, String>,
48+
val version: String?,
49+
val name: String,
50+
val homepage: String?,
51+
val license: String?,
52+
val authors: String?,
53+
val summary: String?,
54+
val podsDependencies: String
55+
)
56+
3957
internal class CocoapodsDependencyManager(
4058
private val specRepoDeferred: () -> SpecRepo,
4159
private val allowWarnings: Boolean,
@@ -58,14 +76,33 @@ internal class CocoapodsDependencyManager(
5876
dependsOn(uploadTask)
5977

6078
val cocoapodsExtension = project.kotlin.cocoapods
79+
80+
val safeCocoapodsData = SafeCocoapodsData(
81+
cocoapodsExtension.ios,
82+
cocoapodsExtension.osx,
83+
cocoapodsExtension.tvos,
84+
cocoapodsExtension.watchos,
85+
cocoapodsExtension.extraSpecAttributes,
86+
cocoapodsExtension.version,
87+
cocoapodsExtension.name,
88+
cocoapodsExtension.homepage,
89+
cocoapodsExtension.license,
90+
cocoapodsExtension.authors,
91+
cocoapodsExtension.summary,
92+
cocoapodsExtension.pods.joinToString(separator = "\n") { pod ->
93+
val versionSuffix = if (pod.version != null) ", '${pod.version}'" else ""
94+
"| spec.dependency '${pod.name}'$versionSuffix"
95+
}
96+
)
97+
6198
val urlFileLocal = project.urlFile
6299
val frameworkName = findFrameworkName(project)
63100

64101
@Suppress("ObjectLiteralToLambda")
65102
doLast(object : Action<Task> {
66103
override fun execute(t: Task) {
67104
generatePodspec(
68-
cocoapodsExtension, urlFileLocal, version, podSpecFile, frameworkName
105+
safeCocoapodsData, urlFileLocal, version, podSpecFile, frameworkName
69106
)
70107
}
71108
})
@@ -77,26 +114,31 @@ internal class CocoapodsDependencyManager(
77114
dependsOn(generatePodspecTask)
78115
outputs.upToDateWhen { false } // We want to always upload when this task is called
79116

117+
val allowWarningsLocal = allowWarnings
118+
val verboseErrorsLocal = verboseErrors
119+
val specRepo = specRepoDeferred()
120+
80121
@Suppress("ObjectLiteralToLambda")
81122
doLast(object : Action<Task> {
82123
override fun execute(t: Task) {
83124
val extras = mutableListOf<String>()
84125

85-
if (allowWarnings) {
126+
if (allowWarningsLocal) {
86127
extras.add("--allow-warnings")
87128
}
88129

89-
if (verboseErrors) {
130+
if (verboseErrorsLocal) {
90131
extras.add("--verbose")
91132
}
92133

93-
when (val specRepo = specRepoDeferred()) {
134+
when (specRepo) {
94135
is SpecRepo.Trunk -> {
95-
providers.exec {
136+
val execOutput = providers.exec {
96137
commandLine(
97138
"pod", "trunk", "push", podSpecFile, *extras.toTypedArray()
98139
)
99-
}.standardOutput.asText.get()
140+
}
141+
t.logger.info(execOutput.standardOutput.asText.get())
100142
}
101143

102144
is SpecRepo.Private -> {
@@ -110,12 +152,7 @@ internal class CocoapodsDependencyManager(
110152
*extras.toTypedArray()
111153
)
112154
}
113-
logger.info(execOutput.standardOutput.asText.get())
114-
val errorOut = execOutput.standardError.asText.get()
115-
val anyError = errorOut.lines().filter { it.isNotBlank() }.isNotEmpty()
116-
if(anyError){
117-
logger.error(errorOut)
118-
}
155+
t.logger.info(execOutput.standardOutput.asText.get())
119156
}
120157
}
121158
}
@@ -130,7 +167,7 @@ internal class CocoapodsDependencyManager(
130167
override val needsGitTags: Boolean = false
131168
}
132169

133-
private fun findFrameworkName(project: Project): org.gradle.api.provider.Provider<String> {
170+
private fun findFrameworkName(project: Project): Provider<String> {
134171
val anyPodFramework = project.provider {
135172
val anyTarget = project.kotlin.targets
136173
.withType(KotlinNativeTarget::class.java)
@@ -150,22 +187,19 @@ private fun findFrameworkName(project: Project): org.gradle.api.provider.Provide
150187
// TODO it might be nice to migrate this back to using the kotlin.cocoapods podspec task directly, but not worth the
151188
// effort to wire it up right now.
152189
private fun generatePodspec(
153-
cocoapodsExtension: CocoapodsExtension,
190+
safeCocoapodsData: SafeCocoapodsData,
154191
urlFile: File,
155-
projectVersion:String,
192+
projectVersion: String,
156193
outputFile: File,
157194
frameworkName: Provider<String>
158-
) = with(cocoapodsExtension) {
195+
) = with(safeCocoapodsData) {
159196
val deploymentTargets = run {
160197
listOf(ios, osx, tvos, watchos).filter { it.deploymentTarget != null }.joinToString("\n") {
161198
if (extraSpecAttributes.containsKey("${it.name}.deployment_target")) "" else "| spec.${it.name}.deployment_target = '${it.deploymentTarget}'"
162199
}
163200
}
164201

165-
val dependencies = pods.joinToString(separator = "\n") { pod ->
166-
val versionSuffix = if (pod.version != null) ", '${pod.version}'" else ""
167-
"| spec.dependency '${pod.name}'$versionSuffix"
168-
}
202+
val dependencies = podsDependencies
169203

170204
val vendoredFramework = "${frameworkName.get()}.xcframework"
171205
val vendoredFrameworks =

0 commit comments

Comments
 (0)