Build: Centralize compiler dist build logic in :kotlin-compiler project
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
@file:Suppress("HasPlatformType")
|
||||
|
||||
import java.io.File
|
||||
|
||||
val buildVersionFilePath = "${rootProject.extra["distDir"]}/build.txt"
|
||||
|
||||
val buildVersionFilePath = "$buildDir/build.txt"
|
||||
val buildVersion by configurations.creating
|
||||
val buildNumber: String by rootProject.extra
|
||||
val kotlinVersion: String by rootProject.extra
|
||||
@@ -17,6 +17,10 @@ val writeBuildNumber by tasks.creating {
|
||||
}
|
||||
}
|
||||
|
||||
artifacts.add(buildVersion.name, file(buildVersionFilePath)) {
|
||||
builtBy(writeBuildNumber)
|
||||
}
|
||||
|
||||
fun replaceVersion(versionFile: File, versionPattern: String, replacement: (MatchResult) -> String) {
|
||||
check(versionFile.isFile) { "Version file $versionFile is not found" }
|
||||
val text = versionFile.readText()
|
||||
@@ -69,15 +73,3 @@ val writePluginVersion by tasks.creating {
|
||||
val writeVersions by tasks.creating {
|
||||
dependsOn(writeBuildNumber, writeStdlibVersion, writeCompilerVersion)
|
||||
}
|
||||
|
||||
|
||||
artifacts.add(buildVersion.name, file(buildVersionFilePath)) {
|
||||
builtBy(writeBuildNumber)
|
||||
}
|
||||
|
||||
val distKotlinHomeDir: String by rootProject.extra
|
||||
|
||||
val dist by task<Copy> {
|
||||
from(writeBuildNumber)
|
||||
into(File(distKotlinHomeDir))
|
||||
}
|
||||
|
||||
@@ -36,9 +36,7 @@ sourceSets {
|
||||
}
|
||||
|
||||
projectTest {
|
||||
dependsOn(":kotlin-compiler:dist",
|
||||
":kotlin-stdlib:dist",
|
||||
":kotlin-script-runtime:dist")
|
||||
dependsOn(":dist")
|
||||
workingDir = File(rootDir, "libraries/tools/kotlin-compiler-client-embeddable-test/src")
|
||||
doFirst {
|
||||
systemProperty("kotlin.test.script.classpath", testSourceSet.output.classesDirs.joinToString(File.pathSeparator))
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
@file:Suppress("HasPlatformType")
|
||||
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import proguard.gradle.ProGuardTask
|
||||
import java.util.regex.Pattern.quote
|
||||
|
||||
description = "Kotlin Compiler"
|
||||
|
||||
@@ -12,21 +15,30 @@ plugins {
|
||||
// You can run Gradle with "-Pkotlin.build.proguard=true" to enable ProGuard run on kotlin-compiler.jar (on TeamCity, ProGuard always runs)
|
||||
val shrink = findProperty("kotlin.build.proguard")?.toString()?.toBoolean() ?: hasProperty("teamcity")
|
||||
|
||||
val jsIrDist = findProperty("kotlin.stdlib.js.ir.dist")?.toString()?.toBoolean() == true
|
||||
|
||||
val fatJarContents by configurations.creating
|
||||
val fatJarContentsStripMetadata by configurations.creating
|
||||
val fatJarContentsStripServices by configurations.creating
|
||||
|
||||
val runtimeJar by configurations.creating
|
||||
val compile by configurations // maven plugin writes pom compile scope from compile configuration by default
|
||||
val libraries by configurations.creating {
|
||||
val proguardLibraries by configurations.creating {
|
||||
extendsFrom(compile)
|
||||
}
|
||||
|
||||
val trove4jJar by configurations.creating
|
||||
val ktorNetworkJar by configurations.creating
|
||||
|
||||
val default by configurations
|
||||
default.extendsFrom(runtimeJar)
|
||||
// Libraries to copy to the lib directory
|
||||
val libraries by configurations.creating
|
||||
// Compiler plugins should be copied without `kotlin-` prefix
|
||||
val compilerPlugins by configurations.creating
|
||||
val sources by configurations.creating
|
||||
// contents of dist/maven directory
|
||||
val distMavenContents by configurations.creating
|
||||
// contents of dist/common directory
|
||||
val distCommonContents by configurations.creating
|
||||
val distStdlibMinimalForTests by configurations.creating
|
||||
val buildNumber by configurations.creating
|
||||
val distJSContents by configurations.creating
|
||||
|
||||
val compilerBaseName = name
|
||||
|
||||
@@ -34,14 +46,78 @@ val outputJar = fileFrom(buildDir, "libs", "$compilerBaseName.jar")
|
||||
|
||||
val compilerModules: Array<String> by rootProject.extra
|
||||
|
||||
val distLibraryProjects = listOfNotNull(
|
||||
":kotlin-annotation-processing",
|
||||
":kotlin-annotation-processing-cli",
|
||||
":kotlin-annotation-processing-runtime",
|
||||
":kotlin-annotations-android",
|
||||
":kotlin-annotations-jvm",
|
||||
":kotlin-ant",
|
||||
":kotlin-daemon",
|
||||
":kotlin-daemon-client",
|
||||
":kotlin-daemon-client-new",
|
||||
":kotlin-imports-dumper-compiler-plugin",
|
||||
":kotlin-main-kts",
|
||||
":kotlin-preloader",
|
||||
":kotlin-reflect",
|
||||
":kotlin-runner",
|
||||
":kotlin-script-runtime",
|
||||
":kotlin-scripting-common",
|
||||
":kotlin-scripting-compiler",
|
||||
":kotlin-scripting-compiler-impl",
|
||||
":kotlin-scripting-jvm",
|
||||
":kotlin-stdlib-js-ir".takeIf { jsIrDist },
|
||||
":kotlin-source-sections-compiler-plugin",
|
||||
":kotlin-test:kotlin-test-js",
|
||||
":kotlin-test:kotlin-test-js-ir".takeIf { jsIrDist },
|
||||
":kotlin-test:kotlin-test-junit",
|
||||
":kotlin-test:kotlin-test-junit5",
|
||||
":kotlin-test:kotlin-test-jvm",
|
||||
":kotlin-test:kotlin-test-testng",
|
||||
":libraries:tools:mutability-annotations-compat",
|
||||
":plugins:android-extensions-compiler",
|
||||
":plugins:jvm-abi-gen"
|
||||
)
|
||||
|
||||
val distCompilerPluginProjects = listOf(
|
||||
":kotlin-allopen-compiler-plugin",
|
||||
":kotlin-android-extensions-runtime",
|
||||
":kotlin-noarg-compiler-plugin",
|
||||
":kotlin-sam-with-receiver-compiler-plugin",
|
||||
":kotlinx-serialization-compiler-plugin"
|
||||
)
|
||||
|
||||
val distSourcesProjects = listOfNotNull(
|
||||
":kotlin-annotations-jvm",
|
||||
":kotlin-reflect",
|
||||
":kotlin-script-runtime",
|
||||
":kotlin-stdlib-jdk7".takeIf { !kotlinBuildProperties.isInJpsBuildIdeaSync },
|
||||
":kotlin-stdlib-jdk8".takeIf { !kotlinBuildProperties.isInJpsBuildIdeaSync },
|
||||
":kotlin-stdlib-js-ir".takeIf { jsIrDist },
|
||||
":kotlin-test:kotlin-test-js",
|
||||
":kotlin-test:kotlin-test-js-ir".takeIf { jsIrDist },
|
||||
":kotlin-test:kotlin-test-junit",
|
||||
":kotlin-test:kotlin-test-junit5",
|
||||
":kotlin-test:kotlin-test-jvm",
|
||||
":kotlin-test:kotlin-test-testng"
|
||||
)
|
||||
|
||||
libraries.apply {
|
||||
resolutionStrategy {
|
||||
preferProjectModules()
|
||||
}
|
||||
|
||||
exclude("org.jetbrains.kotlin", "kotlin-stdlib-common")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile(kotlinStdlib())
|
||||
compile(project(":kotlin-script-runtime"))
|
||||
compile(project(":kotlin-reflect"))
|
||||
compile(commonDep("org.jetbrains.intellij.deps", "trove4j"))
|
||||
|
||||
libraries(project(":kotlin-annotations-jvm"))
|
||||
libraries(
|
||||
proguardLibraries(project(":kotlin-annotations-jvm"))
|
||||
proguardLibraries(
|
||||
files(
|
||||
firstFromJavaHomeThatExists("jre/lib/rt.jar", "../Classes/classes.jar"),
|
||||
firstFromJavaHomeThatExists("jre/lib/jsse.jar", "../Classes/jsse.jar"),
|
||||
@@ -53,8 +129,39 @@ dependencies {
|
||||
fatJarContents(project(it)) { isTransitive = false }
|
||||
}
|
||||
|
||||
trove4jJar(intellijDep()) { includeIntellijCoreJarDependencies(project) { it.startsWith("trove4j") } }
|
||||
ktorNetworkJar(commonDep("io.ktor", "ktor-network"))
|
||||
libraries(intellijDep()) { includeIntellijCoreJarDependencies(project) { it.startsWith("trove4j") } }
|
||||
libraries(commonDep("io.ktor", "ktor-network"))
|
||||
libraries(kotlinStdlib("jdk8"))
|
||||
libraries(kotlinStdlib("js"))
|
||||
|
||||
distLibraryProjects.forEach {
|
||||
libraries(project(it)) { isTransitive = false }
|
||||
}
|
||||
|
||||
distCompilerPluginProjects.forEach {
|
||||
compilerPlugins(project(it)) { isTransitive = false }
|
||||
}
|
||||
|
||||
distSourcesProjects.forEach {
|
||||
sources(project(it, configuration = "sources"))
|
||||
}
|
||||
|
||||
if (!kotlinBuildProperties.isInJpsBuildIdeaSync) {
|
||||
sources(project(":kotlin-stdlib", configuration = "distSources"))
|
||||
sources(project(":kotlin-stdlib-js", configuration = "distSources"))
|
||||
|
||||
distStdlibMinimalForTests(project(":kotlin-stdlib:jvm-minimal-for-test"))
|
||||
|
||||
distJSContents(project(":kotlin-stdlib-js", configuration = "distJs"))
|
||||
distJSContents(project(":kotlin-test:kotlin-test-js", configuration = "distJs"))
|
||||
}
|
||||
|
||||
distCommonContents(kotlinStdlib(suffix = "common"))
|
||||
distCommonContents(kotlinStdlib(suffix = "common", classifier = "sources"))
|
||||
|
||||
distMavenContents(kotlinStdlib(classifier = "sources"))
|
||||
|
||||
buildNumber(project(":prepare:build.version", configuration = "buildVersion"))
|
||||
|
||||
fatJarContents(kotlinBuiltins())
|
||||
fatJarContents(commonDep("javax.inject"))
|
||||
@@ -96,7 +203,7 @@ noDefaultJar()
|
||||
val packCompiler by task<ShadowJar> {
|
||||
configurations = emptyList()
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
destinationDir = File(buildDir, "libs")
|
||||
destinationDirectory.set(File(buildDir, "libs"))
|
||||
|
||||
setupPublicJar(compilerBaseName, "before-proguard")
|
||||
|
||||
@@ -129,7 +236,7 @@ val proguard by task<ProGuardTask> {
|
||||
inputs.files(packCompiler.outputs.files.singleFile)
|
||||
outputs.file(outputJar)
|
||||
|
||||
libraryjars(mapOf("filter" to "!META-INF/versions/**"), libraries)
|
||||
libraryjars(mapOf("filter" to "!META-INF/versions/**"), proguardLibraries)
|
||||
|
||||
printconfiguration("$buildDir/compiler.pro.dump")
|
||||
|
||||
@@ -142,9 +249,56 @@ val proguard by task<ProGuardTask> {
|
||||
|
||||
val pack = if (shrink) proguard else packCompiler
|
||||
|
||||
dist(targetName = "$compilerBaseName.jar", fromTask = pack) {
|
||||
from(trove4jJar)
|
||||
from(ktorNetworkJar)
|
||||
val distDir: String by rootProject.extra
|
||||
|
||||
val distKotlinc = distTask<Sync>("distKotlinc") {
|
||||
destinationDir = File("$distDir/kotlinc")
|
||||
|
||||
from(buildNumber)
|
||||
|
||||
into("bin") {
|
||||
from(files("$rootDir/compiler/cli/bin"))
|
||||
}
|
||||
|
||||
into("license") {
|
||||
from(files("$rootDir/license"))
|
||||
}
|
||||
|
||||
into("lib") {
|
||||
from(pack) { rename { "$compilerBaseName.jar" } }
|
||||
from(libraries)
|
||||
from(sources)
|
||||
from(compilerPlugins) {
|
||||
rename { it.removePrefix("kotlin-") }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val distCommon = distTask<Sync>("distCommon") {
|
||||
destinationDir = File("$distDir/common")
|
||||
from(distCommonContents)
|
||||
}
|
||||
|
||||
val distMaven = distTask<Sync>("distMaven") {
|
||||
destinationDir = File("$distDir/maven")
|
||||
from(distMavenContents)
|
||||
}
|
||||
|
||||
val distJs = distTask<Sync>("distJs") {
|
||||
destinationDir = File("$distDir/js")
|
||||
from(distJSContents)
|
||||
}
|
||||
|
||||
distTask<Copy>("dist") {
|
||||
destinationDir = File(distDir)
|
||||
|
||||
dependsOn(distKotlinc)
|
||||
dependsOn(distCommon)
|
||||
dependsOn(distMaven)
|
||||
dependsOn(distJs)
|
||||
|
||||
from(buildNumber)
|
||||
from(distStdlibMinimalForTests)
|
||||
}
|
||||
|
||||
runtimeJarArtifactBy(pack, pack.outputs.files.singleFile) {
|
||||
@@ -161,3 +315,12 @@ sourcesJar {
|
||||
}
|
||||
|
||||
javadocJar()
|
||||
|
||||
inline fun <reified T : AbstractCopyTask> Project.distTask(
|
||||
name: String,
|
||||
crossinline block: T.() -> Unit
|
||||
) = tasks.register<T>(name) {
|
||||
duplicatesStrategy = DuplicatesStrategy.FAIL
|
||||
rename(quote("-$version"), "")
|
||||
block()
|
||||
}
|
||||
Reference in New Issue
Block a user