diff --git a/kotlin-native/endorsedLibraries/build.gradle b/kotlin-native/endorsedLibraries/build.gradle deleted file mode 100644 index 26d230826b8..00000000000 --- a/kotlin-native/endorsedLibraries/build.gradle +++ /dev/null @@ -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 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" - } -} diff --git a/kotlin-native/endorsedLibraries/build.gradle.kts b/kotlin-native/endorsedLibraries/build.gradle.kts new file mode 100644 index 00000000000..5dc481b63c2 --- /dev/null +++ b/kotlin-native/endorsedLibraries/build.gradle.kts @@ -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 by project +val cacheableTargetNames: List 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") + } +} diff --git a/kotlin-native/endorsedLibraries/kotlinx.cli/build.gradle.kts b/kotlin-native/endorsedLibraries/kotlinx.cli/build.gradle.kts index a57934ef6f9..040a4a0bcf1 100644 --- a/kotlin-native/endorsedLibraries/kotlinx.cli/build.gradle.kts +++ b/kotlin-native/endorsedLibraries/kotlinx.cli/build.gradle.kts @@ -61,7 +61,6 @@ val targetList: List by project val endorsedLibraries: Map by project(":kotlin-native:endorsedLibraries").ext val library = endorsedLibraries[project] ?: throw IllegalStateException("Library for $project is not set") -lateinit var buildTask: TaskProvider konanArtifacts { library(library.name) { @@ -87,12 +86,8 @@ konanArtifacts { commonSrcDir(commonSrc) srcDir(nativeSrc) - buildTask = project.findKonanBuildTask(library.name, project.platformManager.hostPlatform.target).apply { - configure { - dependsOn(":kotlin-native:distCompiler") - dependsOn(":kotlin-native:distRuntime") - } - } + dependsOn(":kotlin-native:distCompiler") + dependsOn(":kotlin-native:distRuntime") } } @@ -100,9 +95,8 @@ val hostName: String by project val cacheableTargetNames: List by project targetList.forEach { targetName -> - val copyTask = tasks.register("${targetName}${library.name}", Copy::class.java) { - require(::buildTask.isInitialized) - dependsOn(buildTask) + val copyTask = tasks.register("${targetName}${library.taskName}", Copy::class.java) { + dependsOn(project.findKonanBuildTask(library.name, project.platformManager.hostPlatform.target)) destinationDir = buildDir.resolve("$targetName${library.name}")