Unverified Commit c730c025 authored by Shagen Ogandzhanian's avatar Shagen Ogandzhanian Committed by GitHub

Split skia download/unzipping task creation and invocation (#960)

This commit is first step in set of actions we need to take to build
skia-package via gradle in the skiko repository

However it makes sense on it's own as well.
parent c4db278a
......@@ -3,6 +3,8 @@ import org.gradle.crypto.checksum.Checksum
import org.jetbrains.compose.internal.publishing.MavenCentralProperties
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import tasks.configuration.*
import kotlin.collections.HashMap
import declareSkiaTasks
plugins {
kotlin("multiplatform")
......@@ -46,6 +48,8 @@ repositories {
}
kotlin {
skikoProjectContext.declareSkiaTasks()
if (supportAwt) {
jvm("awt") {
compilations.all {
......
......@@ -5,6 +5,8 @@ import org.gradle.api.provider.Provider
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import java.io.File
......@@ -25,38 +27,70 @@ class SkikoProjectContext(
val allJvmRuntimeJars = mutableMapOf<Pair<OS, Arch>, TaskProvider<Jar>>()
}
fun SkikoProjectContext.declareSkiaTasks() {
val basicConfigs = listOf("android", "ios", "iosSim", "linux", "macos", "tvos", "tvosSim", "wasm", "windows")
basicConfigs.forEach { config ->
(if (config == "wasm") listOf("wasm") else listOf("arm64", "x64")).forEach { arch ->
val taskNameSuffix = joinToTitleCamelCase(config, arch)
val target = "$config-$arch"
val skiaReleaseTag = project.property("dependencies.skia.$target") as String
val skiaBaseUrl = "https://github.com/JetBrains/skia-pack/releases/download/$skiaReleaseTag"
val artifactId = "Skia-${skiaReleaseTag}-${config}-$buildType-${arch}"
val downloadSkiaTask = project.tasks.register<Download>("downloadSkia$buildType$taskNameSuffix") {
group = "Skia Binaries"
val skiaUrl = "$skiaBaseUrl/$artifactId.zip"
description = "downloads $skiaUrl"
onlyIfModified(true)
src(skiaUrl)
dest(skiko.dependenciesDir.resolve(
"skia/$skiaReleaseTag/Skia-$skiaReleaseTag-$config-Release-${arch}.zip")
)
}
project.tasks.register<Copy>("unzipSkia$buildType$taskNameSuffix") {
group = "Skia Binaries"
val outputDir = skiko.dependenciesDir.resolve("skia/$skiaReleaseTag/$artifactId")
description = "unzips to $outputDir"
dependsOn(downloadSkiaTask)
from(project.zipTree(downloadSkiaTask.get().dest))
into(outputDir)
}
}
}
}
/**
* Do not call inside tasks.register or tasks.call callback
* (tasks' registration during other task's registration is prohibited)
*/
fun SkikoProjectContext.registerOrGetSkiaDirProvider(
os: OS, arch: Arch, isUikitSim: Boolean = false
): Provider<File> = with(this.project) {
): Provider<File> {
val taskNameSuffix = joinToTitleCamelCase(buildType.id, os.idWithSuffix(isUikitSim = isUikitSim), arch.id)
val skiaRelease = skiko.skiaReleaseFor(os, arch, buildType, isUikitSim)
val downloadSkia = tasks.registerOrGetTask<Download>("downloadSkia$taskNameSuffix") {
onlyIf { !dest.exists() }
onlyIfModified(true)
val skiaUrl = "https://github.com/JetBrains/skia-pack/releases/download/$skiaRelease.zip"
inputs.property("skia.url", skiaUrl)
src(skiaUrl)
dest(skiko.dependenciesDir.resolve("skia/$skiaRelease.zip"))
}.map { it.dest.absoluteFile }
return if (skiko.skiaDir != null) {
tasks.registerOrGetTask<DefaultTask>("skiaDir$taskNameSuffix") {
val skiaDir = skiko.skiaDir
return if (skiaDir != null) {
project.tasks.registerOrGetTask<DefaultTask>("skiaDir$taskNameSuffix") {
// dummy task to simplify usage of the resulting provider (see `else` branch)
// if a file provider is not created from a task provider,
// then it cannot be used instead of a task in `dependsOn` clauses of other tasks.
// e.g. the resulting `skiaDir` could not be used in `dependsOn` of CppCompile configuration
enabled = false
}.map { skiko.skiaDir!!.absoluteFile }
}.map {
skiaDir.absoluteFile
}
} else {
tasks.registerOrGetTask<Copy>("unzipSkia$taskNameSuffix") {
dependsOn(downloadSkia)
from(downloadSkia.map { zipTree(it) })
into(skiko.dependenciesDir.resolve("skia/$skiaRelease"))
}.map { it.destinationDir.absoluteFile }
project.tasks.withType<Copy>().named("unzipSkia$taskNameSuffix").map { it.destinationDir.absoluteFile }
}
}
......
import org.gradle.api.GradleException
import org.gradle.api.Project
import java.io.File
......@@ -141,12 +142,6 @@ class SkikoProperties(private val myProject: Project) {
val includeTestHelpers: Boolean
get() = !isRelease
fun skiaReleaseFor(os: OS, arch: Arch, buildType: SkiaBuildType, isIosSim: Boolean = false): String {
val target = "${os.idWithSuffix(isUikitSim = isIosSim)}-${arch.id}"
val tag = myProject.property("dependencies.skia.$target") as String
return "${tag}/Skia-${tag}-${os.idWithSuffix(isUikitSim = isIosSim)}-${buildType.id}-${arch.id}"
}
val releaseGithubVersion: String
get() = (myProject.property("release.github.version") as String)
......@@ -158,11 +153,12 @@ class SkikoProperties(private val myProject: Project) {
// todo: make compatible with the configuration cache
val skiaDir: File?
get() = (
System.getenv()["SKIA_DIR"]
?: System.getProperty("skia.dir")
?: myProject.findProperty("skia.dir")?.toString()
)?.let { File(it) }?.takeIf { it.isDirectory }
get() = (System.getenv()["SKIA_DIR"] ?: System.getProperty("skia.dir") ?: myProject.findProperty("skia.dir")
?.toString())?.let { skiaDirProp ->
val file = File(skiaDirProp)
if (!file.isDirectory) throw (GradleException("\"skiko.skiaDir\" property was explicitly set to ${skiaDirProp} which is not resolved as a directory"))
file
}
val composeRepoUrl: String
get() = System.getenv("COMPOSE_REPO_URL") ?: "https://maven.pkg.jetbrains.space/public/p/compose/dev"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment