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 ...@@ -3,6 +3,8 @@ import org.gradle.crypto.checksum.Checksum
import org.jetbrains.compose.internal.publishing.MavenCentralProperties import org.jetbrains.compose.internal.publishing.MavenCentralProperties
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import tasks.configuration.* import tasks.configuration.*
import kotlin.collections.HashMap
import declareSkiaTasks
plugins { plugins {
kotlin("multiplatform") kotlin("multiplatform")
...@@ -46,6 +48,8 @@ repositories { ...@@ -46,6 +48,8 @@ repositories {
} }
kotlin { kotlin {
skikoProjectContext.declareSkiaTasks()
if (supportAwt) { if (supportAwt) {
jvm("awt") { jvm("awt") {
compilations.all { compilations.all {
......
...@@ -5,6 +5,8 @@ import org.gradle.api.provider.Provider ...@@ -5,6 +5,8 @@ import org.gradle.api.provider.Provider
import org.gradle.api.tasks.Copy import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.TaskProvider import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.bundling.Jar 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 org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import java.io.File import java.io.File
...@@ -25,38 +27,70 @@ class SkikoProjectContext( ...@@ -25,38 +27,70 @@ class SkikoProjectContext(
val allJvmRuntimeJars = mutableMapOf<Pair<OS, Arch>, TaskProvider<Jar>>() 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 * Do not call inside tasks.register or tasks.call callback
* (tasks' registration during other task's registration is prohibited) * (tasks' registration during other task's registration is prohibited)
*/ */
fun SkikoProjectContext.registerOrGetSkiaDirProvider( fun SkikoProjectContext.registerOrGetSkiaDirProvider(
os: OS, arch: Arch, isUikitSim: Boolean = false 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 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) { val skiaDir = skiko.skiaDir
tasks.registerOrGetTask<DefaultTask>("skiaDir$taskNameSuffix") { return if (skiaDir != null) {
project.tasks.registerOrGetTask<DefaultTask>("skiaDir$taskNameSuffix") {
// dummy task to simplify usage of the resulting provider (see `else` branch) // dummy task to simplify usage of the resulting provider (see `else` branch)
// if a file provider is not created from a task provider, // 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. // 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 // e.g. the resulting `skiaDir` could not be used in `dependsOn` of CppCompile configuration
enabled = false enabled = false
}.map { skiko.skiaDir!!.absoluteFile } }.map {
skiaDir.absoluteFile
}
} else { } else {
tasks.registerOrGetTask<Copy>("unzipSkia$taskNameSuffix") { project.tasks.withType<Copy>().named("unzipSkia$taskNameSuffix").map { it.destinationDir.absoluteFile }
dependsOn(downloadSkia)
from(downloadSkia.map { zipTree(it) })
into(skiko.dependenciesDir.resolve("skia/$skiaRelease"))
}.map { it.destinationDir.absoluteFile }
} }
} }
......
import org.gradle.api.GradleException
import org.gradle.api.Project import org.gradle.api.Project
import java.io.File import java.io.File
...@@ -141,12 +142,6 @@ class SkikoProperties(private val myProject: Project) { ...@@ -141,12 +142,6 @@ class SkikoProperties(private val myProject: Project) {
val includeTestHelpers: Boolean val includeTestHelpers: Boolean
get() = !isRelease 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 val releaseGithubVersion: String
get() = (myProject.property("release.github.version") as String) get() = (myProject.property("release.github.version") as String)
...@@ -158,11 +153,12 @@ class SkikoProperties(private val myProject: Project) { ...@@ -158,11 +153,12 @@ class SkikoProperties(private val myProject: Project) {
// todo: make compatible with the configuration cache // todo: make compatible with the configuration cache
val skiaDir: File? val skiaDir: File?
get() = ( get() = (System.getenv()["SKIA_DIR"] ?: System.getProperty("skia.dir") ?: myProject.findProperty("skia.dir")
System.getenv()["SKIA_DIR"] ?.toString())?.let { skiaDirProp ->
?: System.getProperty("skia.dir") val file = File(skiaDirProp)
?: myProject.findProperty("skia.dir")?.toString() if (!file.isDirectory) throw (GradleException("\"skiko.skiaDir\" property was explicitly set to ${skiaDirProp} which is not resolved as a directory"))
)?.let { File(it) }?.takeIf { it.isDirectory } file
}
val composeRepoUrl: String val composeRepoUrl: String
get() = System.getenv("COMPOSE_REPO_URL") ?: "https://maven.pkg.jetbrains.space/public/p/compose/dev" 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