[Gradle] Use unique artifact name for podspec task + avoid redundant task registration
^KT-51518 Verification Pending
This commit is contained in:
committed by
Space Team
parent
1828f7a374
commit
143a233a9e
+76
-16
@@ -32,15 +32,15 @@ class NativeLibraryDslWithCocoapodsIT : BaseGradleIT() {
|
|||||||
build(":shared:tasks") {
|
build(":shared:tasks") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
assertTasksRegistered(
|
assertTasksRegistered(
|
||||||
":shared:generateMylibPodspec",
|
":shared:generateMylibStaticLibraryLinuxX64Podspec",
|
||||||
":shared:generateMyslibPodspec",
|
":shared:generateMyslibSharedLibraryLinuxX64Podspec",
|
||||||
":shared:generateMyframePodspec",
|
":shared:generateMyframeFrameworkIosArm64Podspec",
|
||||||
":shared:generateMyfatframePodspec",
|
":shared:generateMyfatframeFatFrameworkPodspec",
|
||||||
":shared:generateSharedPodspec",
|
":shared:generateSharedXCFrameworkPodspec",
|
||||||
":lib:generateGrooframePodspec",
|
":lib:generateGrooframeFrameworkIosArm64Podspec",
|
||||||
)
|
":lib:generateGrooxcframeXCFrameworkPodspec",
|
||||||
assertTasksNotRegistered(
|
":shared:generateMyframewihtoutpodspecFrameworkIosArm64Podspec",
|
||||||
":shared:generateMyfatframewithoutpodspecPodspec",
|
":lib:generateGrooxcframewithoutpodspecXCFrameworkPodspec",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ class NativeLibraryDslWithCocoapodsIT : BaseGradleIT() {
|
|||||||
project {
|
project {
|
||||||
build(":shared:assembleMylibStaticLibraryLinuxX64") {
|
build(":shared:assembleMylibStaticLibraryLinuxX64") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
assertTasksExecuted(":shared:generateMylibPodspec")
|
assertTasksExecuted(":shared:generateMylibStaticLibraryLinuxX64Podspec")
|
||||||
assertFilesContentEqual("podspecs/mylib.podspec", "/shared/build/out/static/mylib.podspec")
|
assertFilesContentEqual("podspecs/mylib.podspec", "/shared/build/out/static/mylib.podspec")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,29 +62,50 @@ class NativeLibraryDslWithCocoapodsIT : BaseGradleIT() {
|
|||||||
project {
|
project {
|
||||||
build(":shared:assembleMyslibSharedLibraryLinuxX64") {
|
build(":shared:assembleMyslibSharedLibraryLinuxX64") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
assertTasksExecuted(":shared:generateMyslibPodspec")
|
assertTasksExecuted(":shared:generateMyslibSharedLibraryLinuxX64Podspec")
|
||||||
assertFilesContentEqual("podspecs/myslib.podspec", "/shared/build/out/dynamic/myslib.podspec")
|
assertFilesContentEqual("podspecs/myslib.podspec", "/shared/build/out/dynamic/myslib.podspec")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `not generate podspec when withPodspec is empty`() {
|
||||||
|
project {
|
||||||
|
build(":shared:assembleMyslibwithoutpodspecSharedLibraryLinuxX64") {
|
||||||
|
assertSuccessful()
|
||||||
|
assertTasksSkipped(":shared:generateMyslibwithoutpodspecSharedLibraryLinuxX64Podspec")
|
||||||
|
assertContains("Skipping task ':shared:generateMyslibwithoutpodspecSharedLibraryLinuxX64Podspec' because there are no podspec attributes defined")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `generate podspec when assembling framework`() {
|
fun `generate podspec when assembling framework`() {
|
||||||
project {
|
project {
|
||||||
build(":shared:assembleMyframeFrameworkIosArm64") {
|
build(":shared:assembleMyframeFrameworkIosArm64") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
assertTasksExecuted(":shared:generateMyframePodspec")
|
assertTasksExecuted(":shared:generateMyframeFrameworkIosArm64Podspec")
|
||||||
assertFilesContentEqual("podspecs/myframe.podspec", "/shared/build/out/framework/myframe.podspec")
|
assertFilesContentEqual("podspecs/myframe.podspec", "/shared/build/out/framework/myframe.podspec")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `not generate podspec when there is no withPodspec`() {
|
||||||
|
project {
|
||||||
|
build(":shared:assembleMyframewihtoutpodspecFrameworkIosArm64") {
|
||||||
|
assertSuccessful()
|
||||||
|
assertTasksSkipped(":shared:generateMyframewihtoutpodspecFrameworkIosArm64Podspec")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `generate podspec when assembling fat framework`() {
|
fun `generate podspec when assembling fat framework`() {
|
||||||
project {
|
project {
|
||||||
build(":shared:assembleMyfatframeFatFramework") {
|
build(":shared:assembleMyfatframeFatFramework") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
assertTasksExecuted(":shared:generateMyfatframePodspec")
|
assertTasksExecuted(":shared:generateMyfatframeFatFrameworkPodspec")
|
||||||
assertFilesContentEqual("podspecs/myfatframe.podspec", "/shared/build/out/fatframework/myfatframe.podspec")
|
assertFilesContentEqual("podspecs/myfatframe.podspec", "/shared/build/out/fatframework/myfatframe.podspec")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,23 +116,62 @@ class NativeLibraryDslWithCocoapodsIT : BaseGradleIT() {
|
|||||||
project {
|
project {
|
||||||
build(":shared:assembleSharedXCFramework") {
|
build(":shared:assembleSharedXCFramework") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
assertTasksExecuted(":shared:generateSharedPodspec")
|
assertTasksExecuted(":shared:generateSharedXCFrameworkPodspec")
|
||||||
assertFilesContentEqual("podspecs/shared.podspec", "/shared/build/out/xcframework/shared.podspec")
|
assertFilesContentEqual("podspecs/shared.podspec", "/shared/build/out/xcframework/shared.podspec")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `generate podspec when assembling framework from groovy`() {
|
fun `generate podspec when assembling xcframework from groovy`() {
|
||||||
project {
|
project {
|
||||||
build(":lib:assembleGrooframeFrameworkIosArm64") {
|
build(":lib:assembleGrooframeFrameworkIosArm64") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
assertTasksExecuted(":lib:generateGrooframePodspec")
|
assertTasksExecuted(":lib:generateGrooframeFrameworkIosArm64Podspec")
|
||||||
assertFilesContentEqual("podspecs/grooframe.podspec", "/lib/build/out/framework/grooframe.podspec")
|
assertFilesContentEqual("podspecs/grooframe.podspec", "/lib/build/out/framework/grooframe.podspec")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `not generate podspec from groovy when withPodspec is empty`() {
|
||||||
|
project {
|
||||||
|
build(":lib:assembleGrooxcframeXCFramework") {
|
||||||
|
assertSuccessful()
|
||||||
|
assertTasksSkipped(":lib:generateGrooxcframeXCFrameworkPodspec")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `not generate podspec from groovy when there is no withPodspec`() {
|
||||||
|
project {
|
||||||
|
build(":lib:assembleGrooxcframewithoutpodspecXCFramework") {
|
||||||
|
assertSuccessful()
|
||||||
|
assertTasksSkipped(":lib:generateGrooxcframewithoutpodspecXCFrameworkPodspec")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `generate podspecs when several frameworks have with the same name`() {
|
||||||
|
project {
|
||||||
|
projectDir.resolve("shared/build.gradle.kts").appendText("""
|
||||||
|
kotlinArtifacts {
|
||||||
|
Native.Library {
|
||||||
|
target = linuxX64
|
||||||
|
|
||||||
|
withPodspec {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""".trimIndent())
|
||||||
|
|
||||||
|
build(":shared:assembleSharedXCFramework") {
|
||||||
|
assertSuccessful()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun project(block: Project.() -> Unit) {
|
private fun project(block: Project.() -> Unit) {
|
||||||
transformProjectWithPluginsDsl("new-kn-library-dsl-cocoapods").block()
|
transformProjectWithPluginsDsl("new-kn-library-dsl-cocoapods").block()
|
||||||
}
|
}
|
||||||
|
|||||||
+12
@@ -23,9 +23,21 @@ kotlinArtifacts {
|
|||||||
attribute('homepage', 'https://example.com/lib')
|
attribute('homepage', 'https://example.com/lib')
|
||||||
attribute('ios.deployment_target', '"10.0"')
|
attribute('ios.deployment_target', '"10.0"')
|
||||||
attribute('swift_versions', '[\'4\', \'5\']')
|
attribute('swift_versions', '[\'4\', \'5\']')
|
||||||
|
}
|
||||||
|
|
||||||
|
withPodspec {
|
||||||
rawStatement(' # This is raw statement that is appended \'as is\' to the podspec')
|
rawStatement(' # This is raw statement that is appended \'as is\' to the podspec')
|
||||||
rawStatement(' spec.frameworks = \'CFNetwork\'')
|
rawStatement(' spec.frameworks = \'CFNetwork\'')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
it.native.XCFramework("grooxcframe") {
|
||||||
|
targets(iosX64, iosArm64, iosSimulatorArm64)
|
||||||
|
|
||||||
|
withPodspec {}
|
||||||
|
}
|
||||||
|
|
||||||
|
it.native.XCFramework("grooxcframewithoutpodspec") {
|
||||||
|
targets(iosX64, iosArm64, iosSimulatorArm64)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -1,5 +1,6 @@
|
|||||||
Pod::Spec.new do |spec|
|
Pod::Spec.new do |spec|
|
||||||
spec.name = 'myslib'
|
spec.name = 'myslib'
|
||||||
spec.version = '0.1'
|
|
||||||
spec.vendored_library = 'libmyslib.dylib'
|
spec.vendored_library = 'libmyslib.dylib'
|
||||||
|
|
||||||
|
spec.version = '111'
|
||||||
end
|
end
|
||||||
|
|||||||
+14
@@ -42,6 +42,16 @@ kotlinArtifacts {
|
|||||||
modes(DEBUG)
|
modes(DEBUG)
|
||||||
addModule(project(":lib"))
|
addModule(project(":lib"))
|
||||||
|
|
||||||
|
withPodspec {
|
||||||
|
attribute("version", "111")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Native.Library("myslibwithoutpodspec") {
|
||||||
|
target = linuxX64
|
||||||
|
isStatic = false
|
||||||
|
modes(DEBUG)
|
||||||
|
addModule(project(":lib"))
|
||||||
|
|
||||||
withPodspec {} // intentionally empty
|
withPodspec {} // intentionally empty
|
||||||
}
|
}
|
||||||
Native.Framework("myframe") {
|
Native.Framework("myframe") {
|
||||||
@@ -83,13 +93,17 @@ kotlinArtifacts {
|
|||||||
attribute("license", "MIT")
|
attribute("license", "MIT")
|
||||||
attribute("homepage", "https://github.com/Alpaca/Alpaca")
|
attribute("homepage", "https://github.com/Alpaca/Alpaca")
|
||||||
attribute("source", "{ :git => 'https://github.com/Alpaca/Alpaca.git', :tag => spec.version }")
|
attribute("source", "{ :git => 'https://github.com/Alpaca/Alpaca.git', :tag => spec.version }")
|
||||||
|
}
|
||||||
|
|
||||||
|
withPodspec {
|
||||||
attribute("ios.deployment_target", "10.0")
|
attribute("ios.deployment_target", "10.0")
|
||||||
attribute("osx.deployment_target", "10.12")
|
attribute("osx.deployment_target", "10.12")
|
||||||
attribute("watchos.deployment_target", "3.0")
|
attribute("watchos.deployment_target", "3.0")
|
||||||
|
|
||||||
attribute("swift_versions", "['4', '5']")
|
attribute("swift_versions", "['4', '5']")
|
||||||
|
}
|
||||||
|
|
||||||
|
withPodspec {
|
||||||
rawStatement(" # This is raw statement that is appended 'as is' to the podspec")
|
rawStatement(" # This is raw statement that is appended 'as is' to the podspec")
|
||||||
rawStatement(" spec.frameworks = 'CFNetwork'")
|
rawStatement(" spec.frameworks = 'CFNetwork'")
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-4
@@ -5,13 +5,11 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.targets.native.cocoapods
|
package org.jetbrains.kotlin.gradle.targets.native.cocoapods
|
||||||
|
|
||||||
import org.gradle.api.*
|
|
||||||
import org.gradle.api.plugins.ExtensionAware
|
import org.gradle.api.plugins.ExtensionAware
|
||||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin
|
import org.jetbrains.kotlin.gradle.plugin.cocoapods.KotlinCocoapodsPlugin
|
||||||
import org.jetbrains.kotlin.gradle.plugin.findExtension
|
import org.jetbrains.kotlin.gradle.plugin.findExtension
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
abstract class KotlinArtifactsPodspecExtension @Inject constructor(private val project: Project) {
|
abstract class KotlinArtifactsPodspecExtension {
|
||||||
|
|
||||||
private val attrs = mutableMapOf<String, String>()
|
private val attrs = mutableMapOf<String, String>()
|
||||||
private val statements = mutableListOf<String>()
|
private val statements = mutableListOf<String>()
|
||||||
@@ -22,14 +20,20 @@ abstract class KotlinArtifactsPodspecExtension @Inject constructor(private val p
|
|||||||
internal val rawStatements: List<String>
|
internal val rawStatements: List<String>
|
||||||
get() = statements
|
get() = statements
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends an attribute to the generated podspec
|
||||||
|
*/
|
||||||
fun attribute(key: String, value: String) {
|
fun attribute(key: String, value: String) {
|
||||||
attrs[key] = value
|
attrs[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends a statement 'as is' to the end of the generated podspec
|
||||||
|
*/
|
||||||
fun rawStatement(statement: String) {
|
fun rawStatement(statement: String) {
|
||||||
statements.add(statement)
|
statements.add(statement)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val ExtensionAware.kotlinArtifactsPodspecExtension: KotlinArtifactsPodspecExtension?
|
internal val ExtensionAware.kotlinArtifactsPodspecExtension: KotlinArtifactsPodspecExtension?
|
||||||
get() = findExtension(KotlinCocoapodsPlugin.ARTIFACTS_PODSPEC_EXTENSION_NAME)
|
get() = findExtension(KotlinCocoapodsPlugin.ARTIFACTS_PODSPEC_EXTENSION_NAME)
|
||||||
+4
-6
@@ -412,7 +412,7 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
|
|||||||
) {
|
) {
|
||||||
val artifactName = artifact.artifactName
|
val artifactName = artifact.artifactName
|
||||||
val assembleTask = project.tasks.named(artifact.taskName)
|
val assembleTask = project.tasks.named(artifact.taskName)
|
||||||
val podspecTaskName = lowerCamelCaseName("generate", artifactName, "podspec")
|
val podspecTaskName = lowerCamelCaseName("generate", artifact.name, "podspec")
|
||||||
|
|
||||||
val artifactType = when (artifact) {
|
val artifactType = when (artifact) {
|
||||||
is KotlinNativeLibrary -> when {
|
is KotlinNativeLibrary -> when {
|
||||||
@@ -446,16 +446,14 @@ open class KotlinCocoapodsPlugin : Plugin<Project> {
|
|||||||
cocoapodsExtension: CocoapodsExtension,
|
cocoapodsExtension: CocoapodsExtension,
|
||||||
) {
|
) {
|
||||||
artifactsExtension.artifactConfigs.withType(KotlinNativeArtifactConfig::class.java) { artifactConfig ->
|
artifactsExtension.artifactConfigs.withType(KotlinNativeArtifactConfig::class.java) { artifactConfig ->
|
||||||
val podspecExtension = project.objects.newInstance<KotlinArtifactsPodspecExtension>(project)
|
val podspecExtension = project.objects.newInstance<KotlinArtifactsPodspecExtension>()
|
||||||
artifactConfig.addExtension(ARTIFACTS_PODSPEC_EXTENSION_NAME, podspecExtension)
|
artifactConfig.addExtension(ARTIFACTS_PODSPEC_EXTENSION_NAME, podspecExtension)
|
||||||
}
|
}
|
||||||
|
|
||||||
artifactsExtension.artifacts.withType(KotlinNativeArtifact::class.java) { artifact ->
|
artifactsExtension.artifacts.withType(KotlinNativeArtifact::class.java) { artifact ->
|
||||||
val podspecExtension = artifact.kotlinArtifactsPodspecExtension
|
val podspecExtension = requireNotNull(artifact.kotlinArtifactsPodspecExtension)
|
||||||
|
|
||||||
if (podspecExtension != null) {
|
registerPodspecTask(project, artifact, podspecExtension, cocoapodsExtension)
|
||||||
registerPodspecTask(project, artifact, podspecExtension, cocoapodsExtension)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.gradle.targets.native.tasks
|
|||||||
import org.gradle.api.DefaultTask
|
import org.gradle.api.DefaultTask
|
||||||
import org.gradle.api.file.DirectoryProperty
|
import org.gradle.api.file.DirectoryProperty
|
||||||
import org.gradle.api.file.RegularFile
|
import org.gradle.api.file.RegularFile
|
||||||
|
import org.gradle.api.logging.Logger
|
||||||
import org.gradle.api.provider.ListProperty
|
import org.gradle.api.provider.ListProperty
|
||||||
import org.gradle.api.provider.MapProperty
|
import org.gradle.api.provider.MapProperty
|
||||||
import org.gradle.api.provider.Property
|
import org.gradle.api.provider.Property
|
||||||
@@ -23,6 +24,16 @@ abstract class GenerateArtifactPodspecTask : DefaultTask() {
|
|||||||
StaticLibrary, DynamicLibrary, Framework, FatFramework, XCFramework
|
StaticLibrary, DynamicLibrary, Framework, FatFramework, XCFramework
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
this.onlyIf {
|
||||||
|
val shouldRun = attributes.get().isNotEmpty() || rawStatements.get().isNotEmpty()
|
||||||
|
if (!shouldRun) {
|
||||||
|
logger.info("Skipping task '$path' because there are no podspec attributes defined")
|
||||||
|
}
|
||||||
|
shouldRun
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@get:Input
|
@get:Input
|
||||||
abstract val specName: Property<String>
|
abstract val specName: Property<String>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user