Skip to content

Commit

Permalink
Download and use a codesign-client from an internal jb repository ins…
Browse files Browse the repository at this point in the history
…tead of using a hardcoded one (JetBrains#859)

* Download and use a codesign-client from an internal jb repository instead of using a hardcoded one

* Download a codesign-client for hostArch only

* Make the downloaded codesign-client executable

* Update skiko/buildSrc/src/main/kotlin/tasks/configuration/JvmTasksConfiguration.kt

Co-authored-by: Igor Demin <[email protected]>

---------

Co-authored-by: Igor Demin <[email protected]>
  • Loading branch information
eymar and igordmn authored Jan 26, 2024
1 parent 5b5ee68 commit 03928d6
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
2 changes: 1 addition & 1 deletion skiko/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ publishing {
}

val mavenCentral = MavenCentralProperties(project)
if (skiko.isCIBuild || mavenCentral.signArtifacts) {
if (skiko.isTeamcityCIBuild || mavenCentral.signArtifacts) {
signing {
sign(publishing.publications)
useInMemoryPgpKeys(mavenCentral.signArtifactsKey.get(), mavenCentral.signArtifactsPassword.get())
Expand Down
2 changes: 1 addition & 1 deletion skiko/buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ dependencies {
implementation(kotlin("stdlib"))
compileOnly(gradleApi())
implementation(kotlin("gradle-plugin", "1.9.21"))
implementation("de.undercouch:gradle-download-task:5.4.0")
implementation("de.undercouch:gradle-download-task:5.5.0")
}
5 changes: 4 additions & 1 deletion skiko/buildSrc/src/main/kotlin/properties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ enum class OS(
val isWindows
get() = this == Windows

val isMacOs
get() = this == MacOS

fun idWithSuffix(isIosSim: Boolean = false): String {
return id + if (isIosSim) "Sim" else ""
}
Expand Down Expand Up @@ -113,7 +116,7 @@ fun targetId(os: OS, arch: Arch) = "${os.id}-${arch.id}"
val jdkHome = System.getProperty("java.home") ?: error("'java.home' is null")

class SkikoProperties(private val myProject: Project) {
val isCIBuild: Boolean
val isTeamcityCIBuild: Boolean
get() = myProject.hasProperty("teamcity")

val planeDeployVersion: String = myProject.property("deploy.version") as String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import SkiaBuildType
import SkikoProjectContext
import compilerForTarget
import dynamicLibExt
import hostArch
import hostOs
import joinToTitleCamelCase
import linkerForTarget
import org.gradle.api.GradleException
import org.gradle.api.JavaVersion
Expand Down Expand Up @@ -327,13 +329,44 @@ fun SkikoProjectContext.createLinkJvmBindings(
flags.set(listOf(*osFlags))
}

private val Arch.darwinSignClientName: String
get() = when (this) {
Arch.X64 -> "codesign-client-darwin-amd64"
Arch.Arm64 -> "codesign-client-darwin-arm64"
else -> error("Unexpected Arch = $this for codesign-client")
}

fun SkikoProjectContext.createDownloadCodeSignClientDarwinTask(
targetOs: OS,
hostArch: Arch
) = project.registerSkikoTask<de.undercouch.gradle.tasks.download.Download>("downloadCodeSignClient", targetOs, hostArch) {
val fileUrl = "https://codesign-distribution.labs.jb.gg/${hostArch.darwinSignClientName}"

src(fileUrl)
dest(project.layout.buildDirectory)
overwrite(false)

// only Teamcity agents have access to download the codesign-client executable file
enabled = this@createDownloadCodeSignClientDarwinTask.skiko.isTeamcityCIBuild

doLast {
val downloadedFile = project.layout.buildDirectory.get().asFile.resolve(hostArch.darwinSignClientName)
downloadedFile.setExecutable(true)
}
}

fun SkikoProjectContext.maybeSignOrSealTask(
targetOs: OS,
targetArch: Arch,
linkJvmBindings: Provider<LinkSkikoTask>
) = project.registerSkikoTask<SealAndSignSharedLibraryTask>("maybeSign", targetOs, targetArch) {
dependsOn(linkJvmBindings)

if (targetOs.isMacOs) {
val downloadCodesignClientTask = "downloadCodeSignClient" + joinToTitleCamelCase(targetOs.id, hostArch.id)
dependsOn(project.tasks.getByName(downloadCodesignClientTask))
}

val linkOutputFile = linkJvmBindings.map { task ->
task.outDir.get().asFile.walk().single { it.name.endsWith(targetOs.dynamicLibExt) }.absoluteFile
}
Expand All @@ -352,8 +385,8 @@ fun SkikoProjectContext.maybeSignOrSealTask(
}
}

if (hostOs == OS.MacOS) {
codesignClient.set(toolsDir.file("codesign-client-darwin-x64"))
if (hostOs == OS.MacOS && this@maybeSignOrSealTask.skiko.isTeamcityCIBuild) {
codesignClient.set(project.layout.buildDirectory.file(hostArch.darwinSignClientName))
}
signHost.set(skiko.signHost)
signUser.set(skiko.signUser)
Expand All @@ -379,6 +412,9 @@ fun SkikoProjectContext.createSkikoJvmJarTask(os: OS, arch: Arch, commonJar: Tas
val objcCompile = if (os == OS.MacOS) createObjcCompileTask(os, arch, skiaBindingsDir) else null
val linkBindings =
createLinkJvmBindings(os, arch, skiaBindingsDir, compileBindings, objcCompile)
if (os.isMacOs) {
createDownloadCodeSignClientDarwinTask(os, hostArch)
}
val maybeSign = maybeSignOrSealTask(os, arch, linkBindings)
val nativeLib = maybeSign.map { it.outputFiles.get().single() }
val createChecksums = createChecksumsTask(os, arch, nativeLib)
Expand Down
Binary file removed skiko/tools/codesign-client-darwin-x64
Binary file not shown.

0 comments on commit 03928d6

Please sign in to comment.