co.touchlab.faktory.ProjectExtensions.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kmmbridge Show documentation
Show all versions of kmmbridge Show documentation
KMP Xcode XCFramework Packaging and tooling
/*
* Copyright (c) 2024 Touchlab.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package co.touchlab.faktory
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.UnknownTaskException
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.plugins.ExtraPropertiesExtension
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.tasks.TaskProvider
import org.gradle.kotlin.dsl.findByType
import org.gradle.kotlin.dsl.getByType
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.cocoapods.CocoapodsExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
import java.io.File
internal val Project.layoutBuildDir get() = layout.buildDirectory.get().asFile
internal val Project.kotlin: KotlinMultiplatformExtension get() = extensions.getByType()
internal val Project.kmmBridgeExtension get() = extensions.getByType()
internal val Project.publishingExtension get() = extensions.getByType()
internal val Project.urlFile get() = file("$layoutBuildDir/faktory/url")
// Cocoapods is an extension of KMP extension, so you can't just do project.extensions.getByType()
internal val KotlinMultiplatformExtension.cocoapodsOrNull get() = (this as ExtensionAware).extensions.findByType()
internal val KotlinMultiplatformExtension.cocoapods
get() = cocoapodsOrNull
?: error("You must apply the org.jetbrains.kotlin.native.cocoapods plugin to use cocoapods() configuration")
// This previously defaulted to 'false', but now you can disable it if needed, but otherwise ignore
internal val Project.enablePublishing: Boolean
get() = project.findStringProperty("ENABLE_PUBLISHING")?.toBoolean() ?: true
internal val Project.spmBuildTargets: String?
get() = project.findStringProperty("spmBuildTargets")
@Suppress("SpellCheckingInspection")
internal fun Project.zipFilePath(): File {
val tempDir = file("$layoutBuildDir/faktory/zip")
val artifactName = "frameworkarchive.zip"
return file("$tempDir/$artifactName")
}
internal fun Project.findStringProperty(name: String): String? {
rootProject.extensions.getByType(ExtraPropertiesExtension::class.java).run {
if (has(name))
return get(name).toString()
}
return null
}
internal const val TASK_GROUP_NAME = "kmmbridge"
internal const val EXTENSION_NAME = "kmmbridge"
internal fun Project.findXCFrameworkAssembleTask(buildType: NativeBuildType? = null): TaskProvider {
val extension = extensions.getByType()
val name = extension.frameworkName.get()
val buildTypeString = (buildType ?: extension.buildType.get()).getName().capitalized()
val taskWithoutName = "assemble${buildTypeString}XCFramework"
val taskWithName = "assemble${name.capitalized()}${buildTypeString}XCFramework"
return runCatching {
tasks.named(taskWithName)
}.recoverCatching {
tasks.named(taskWithoutName)
}.getOrElse {
throw UnknownTaskException(
"Cannot find XCFramework assemble task. Tried $taskWithName and ${taskWithoutName}."
)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy