[K/N][build] Rewrite endorsed libraries build to kts
This commit is contained in:
@@ -1,109 +0,0 @@
|
|||||||
import org.jetbrains.kotlin.UtilsKt
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.konan.tasks.KonanCacheTask
|
|
||||||
import org.jetbrains.kotlin.EndorsedLibraryInfo
|
|
||||||
import org.jetbrains.kotlin.UtilsKt
|
|
||||||
import org.jetbrains.kotlin.konan.target.HostManager
|
|
||||||
|
|
||||||
apply plugin: 'konan'
|
|
||||||
|
|
||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
if (UtilsKt.getCacheRedirectorEnabled(project))
|
|
||||||
maven { url 'https://cache-redirector.jetbrains.com/jcenter' }
|
|
||||||
else
|
|
||||||
jcenter()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (HostManager.host.name == "macos_arm64") {
|
|
||||||
JvmToolchain.configureJvmToolchain(project, JdkMajorVersion.JDK_17)
|
|
||||||
}
|
|
||||||
|
|
||||||
ext {
|
|
||||||
endorsedLibraries = [
|
|
||||||
new EndorsedLibraryInfo(project('kotlinx.cli'), "org.jetbrains.kotlinx.kotlinx-cli")
|
|
||||||
].collectEntries { [it.project, it] }
|
|
||||||
}
|
|
||||||
|
|
||||||
Collection<EndorsedLibraryInfo> endorsedLibrariesList = ext.endorsedLibraries.values()
|
|
||||||
|
|
||||||
tasks.named("clean") {
|
|
||||||
doFirst {
|
|
||||||
delete buildDir
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
task jvmJar {
|
|
||||||
endorsedLibrariesList.each { library ->
|
|
||||||
dependsOn "$library.projectName:jvmJar"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build all default libraries.
|
|
||||||
targetList.each { target ->
|
|
||||||
task("${target}EndorsedLibraries") {
|
|
||||||
endorsedLibrariesList.each { library ->
|
|
||||||
dependsOn task("${target}${library.name}EndorsedLibraries", type: Copy) {
|
|
||||||
dependsOn "$library.projectName:${target}${library.name}"
|
|
||||||
destinationDir project.file("${project.buildDir}/${library.name}")
|
|
||||||
|
|
||||||
from(library.project.file("build/${target}${library.name}")) {
|
|
||||||
include('**')
|
|
||||||
eachFile {
|
|
||||||
if (name == 'manifest') {
|
|
||||||
def existingManifest = file("$destinationDir/$path")
|
|
||||||
if (existingManifest.exists()) {
|
|
||||||
UtilsKt.mergeManifestsByTargets(project, file, existingManifest)
|
|
||||||
exclude()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (target in cacheableTargetNames) {
|
|
||||||
def cacheTask = task("${target}Cache", type: Copy) {
|
|
||||||
destinationDir project.file("${project.buildDir}/cache/$target")
|
|
||||||
|
|
||||||
endorsedLibrariesList.each { library ->
|
|
||||||
from(library.project.file("build/cache/$target")) {
|
|
||||||
include('**')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
endorsedLibrariesList.each { library ->
|
|
||||||
cacheTask.dependsOn "${library.projectName}:${target}${library.taskName}Cache"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
endorsedLibrariesList.each { library ->
|
|
||||||
task("${library.taskName}CommonSources", type: Zip) {
|
|
||||||
destinationDirectory = file("${UtilsKt.getKotlinNativeDist(project)}/sources")
|
|
||||||
archiveFileName = "${library.name}-common-sources.zip"
|
|
||||||
|
|
||||||
includeEmptyDirs = false
|
|
||||||
include('**/*.kt')
|
|
||||||
|
|
||||||
from(library.project.file('src/main/kotlin'))
|
|
||||||
}
|
|
||||||
task("${library.taskName}NativeSources", type: Zip) {
|
|
||||||
destinationDirectory = file("${UtilsKt.getKotlinNativeDist(project)}/sources")
|
|
||||||
archiveFileName = "${library.name}-native-sources.zip"
|
|
||||||
|
|
||||||
includeEmptyDirs = false
|
|
||||||
include('**/*.kt')
|
|
||||||
|
|
||||||
from(library.project.file('src/main/kotlin-native'))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
task endorsedLibsSources {
|
|
||||||
endorsedLibrariesList.each { library ->
|
|
||||||
dependsOn "${library.taskName}CommonSources"
|
|
||||||
dependsOn "${library.taskName}NativeSources"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
import org.jetbrains.kotlin.EndorsedLibraryInfo
|
||||||
|
import org.jetbrains.kotlin.konan.target.HostManager
|
||||||
|
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||||
|
import org.jetbrains.kotlin.kotlinNativeDist
|
||||||
|
import org.jetbrains.kotlin.mergeManifestsByTargets
|
||||||
|
|
||||||
|
if (HostManager.host == KonanTarget.MACOS_ARM64) {
|
||||||
|
project.configureJvmToolchain(JdkMajorVersion.JDK_17)
|
||||||
|
}
|
||||||
|
|
||||||
|
val endorsedLibraries = listOf(EndorsedLibraryInfo(project("kotlinx.cli"), "org.jetbrains.kotlinx.kotlinx-cli"))
|
||||||
|
|
||||||
|
extra["endorsedLibraries"] = endorsedLibraries.associateBy { it.project }
|
||||||
|
|
||||||
|
tasks.register("jvmJar") {
|
||||||
|
endorsedLibraries.forEach { library ->
|
||||||
|
dependsOn("${library.projectName}:jvmJar")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val targetList: List<String> by project
|
||||||
|
val cacheableTargetNames: List<String> by project
|
||||||
|
|
||||||
|
// Build all default libraries.
|
||||||
|
targetList.forEach { target ->
|
||||||
|
tasks.create("${target}EndorsedLibraries") {
|
||||||
|
endorsedLibraries.forEach { library ->
|
||||||
|
dependsOn(tasks.register("${target}${library.name}EndorsedLibraries", Copy::class.java) {
|
||||||
|
dependsOn("${library.projectName}:${target}${library.taskName}")
|
||||||
|
destinationDir = project.file("${project.buildDir}/${library.name}")
|
||||||
|
|
||||||
|
from(library.project.file("build/${target}${library.name}")) {
|
||||||
|
include("**")
|
||||||
|
eachFile {
|
||||||
|
if (name == "manifest") {
|
||||||
|
val existingManifest = file("$destinationDir/$path")
|
||||||
|
if (existingManifest.exists()) {
|
||||||
|
project.mergeManifestsByTargets(file, existingManifest)
|
||||||
|
exclude()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target in cacheableTargetNames) {
|
||||||
|
val cacheTask = tasks.register("${target}Cache", Copy::class.java) {
|
||||||
|
destinationDir = project.file("${project.buildDir}/cache/$target")
|
||||||
|
|
||||||
|
endorsedLibraries.forEach { library ->
|
||||||
|
from(library.project.file("build/cache/$target")) {
|
||||||
|
include("**")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
endorsedLibraries.forEach { library ->
|
||||||
|
cacheTask.configure {
|
||||||
|
dependsOn("${library.projectName}:${target}${library.taskName}Cache")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
endorsedLibraries.forEach { library ->
|
||||||
|
tasks.register("${library.taskName}CommonSources", Zip::class.java) {
|
||||||
|
destinationDirectory.set(file("${project.kotlinNativeDist}/sources"))
|
||||||
|
archiveFileName.set("${library.name}-common-sources.zip")
|
||||||
|
|
||||||
|
includeEmptyDirs = false
|
||||||
|
include("**/*.kt")
|
||||||
|
|
||||||
|
from(library.project.file("src/main/kotlin"))
|
||||||
|
}
|
||||||
|
tasks.register("${library.taskName}NativeSources", Zip::class.java) {
|
||||||
|
destinationDirectory.set(file("${project.kotlinNativeDist}/sources"))
|
||||||
|
archiveFileName.set("${library.name}-native-sources.zip")
|
||||||
|
|
||||||
|
includeEmptyDirs = false
|
||||||
|
include("**/*.kt")
|
||||||
|
|
||||||
|
from(library.project.file("src/main/kotlin-native"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.register("endorsedLibsSources") {
|
||||||
|
endorsedLibraries.forEach { library ->
|
||||||
|
dependsOn("${library.taskName}CommonSources")
|
||||||
|
dependsOn("${library.taskName}NativeSources")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -61,7 +61,6 @@ val targetList: List<String> by project
|
|||||||
val endorsedLibraries: Map<Project, EndorsedLibraryInfo> by project(":kotlin-native:endorsedLibraries").ext
|
val endorsedLibraries: Map<Project, EndorsedLibraryInfo> by project(":kotlin-native:endorsedLibraries").ext
|
||||||
|
|
||||||
val library = endorsedLibraries[project] ?: throw IllegalStateException("Library for $project is not set")
|
val library = endorsedLibraries[project] ?: throw IllegalStateException("Library for $project is not set")
|
||||||
lateinit var buildTask: TaskProvider<Task>
|
|
||||||
|
|
||||||
konanArtifacts {
|
konanArtifacts {
|
||||||
library(library.name) {
|
library(library.name) {
|
||||||
@@ -87,12 +86,8 @@ konanArtifacts {
|
|||||||
commonSrcDir(commonSrc)
|
commonSrcDir(commonSrc)
|
||||||
srcDir(nativeSrc)
|
srcDir(nativeSrc)
|
||||||
|
|
||||||
buildTask = project.findKonanBuildTask(library.name, project.platformManager.hostPlatform.target).apply {
|
dependsOn(":kotlin-native:distCompiler")
|
||||||
configure {
|
dependsOn(":kotlin-native:distRuntime")
|
||||||
dependsOn(":kotlin-native:distCompiler")
|
|
||||||
dependsOn(":kotlin-native:distRuntime")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,9 +95,8 @@ val hostName: String by project
|
|||||||
val cacheableTargetNames: List<String> by project
|
val cacheableTargetNames: List<String> by project
|
||||||
|
|
||||||
targetList.forEach { targetName ->
|
targetList.forEach { targetName ->
|
||||||
val copyTask = tasks.register("${targetName}${library.name}", Copy::class.java) {
|
val copyTask = tasks.register("${targetName}${library.taskName}", Copy::class.java) {
|
||||||
require(::buildTask.isInitialized)
|
dependsOn(project.findKonanBuildTask(library.name, project.platformManager.hostPlatform.target))
|
||||||
dependsOn(buildTask)
|
|
||||||
|
|
||||||
destinationDir = buildDir.resolve("$targetName${library.name}")
|
destinationDir = buildDir.resolve("$targetName${library.name}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user