Refactor compiler-related published projects

- move preparation into separate projects
- rename projects for publishing
- add compiler plugins
This commit is contained in:
Ilya Chernikov
2017-09-11 13:03:35 +02:00
parent aa4fdaa713
commit e18b77af21
19 changed files with 229 additions and 343 deletions
@@ -1,38 +1,7 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
description = "Kotlin compiler client embeddable"
buildscript {
repositories {
jcenter()
@@ -53,7 +22,6 @@ val jarContents by configurations.creating
val testRuntimeCompilerJar by configurations.creating
val testStdlibJar by configurations.creating
val testScriptRuntimeJar by configurations.creating
val default by configurations
val archives by configurations
val projectsToInclude = listOf(
@@ -70,18 +38,11 @@ dependencies {
testCompile(commonDep("junit:junit"))
testCompile(project(":kotlin-test:kotlin-test-jvm"))
testCompile(project(":kotlin-test:kotlin-test-junit"))
testRuntimeCompilerJar(project(":compiler", configuration = "compilerJar"))
testRuntimeCompilerJar(project(":kotlin-compiler", configuration = "runtimeJar"))
testStdlibJar(project(":kotlin-stdlib", configuration = "mainJar"))
testScriptRuntimeJar(project(":kotlin-script-runtime", configuration = "mainJar"))
}
val shadowJar by task<ShadowJar> {
setupRuntimeJar("Kotlin compiler client embeddable")
baseName = "kotlin-compiler-client-embeddable"
from(jarContents)
classifier = ""
}
configureKotlinProjectSources() // no sources
configureKotlinProjectTests("libraries/tools/kotlin-compiler-client-embeddable-test/src", sourcesBaseDir = rootDir)
@@ -108,18 +69,15 @@ archives.artifacts.let { artifacts ->
}
}
artifacts.add(default.name, shadowJar.outputs.files.singleFile) {
builtBy(shadowJar)
classifier = ""
runtimeJar(task<ShadowJar>("shadowJar")) {
from(jarContents)
}
sourcesJar()
javadocJar()
artifacts.add("archives", shadowJar.outputs.files.singleFile) {
builtBy(shadowJar)
classifier = ""
}
apply<plugins.PublishedKotlinModule>()
publish()
// TODO: remove after finalizing publishing (now due to the problems with sam-with-receiver, the code is not fully navigable in the buildSrc)
//tasks {
// "uploadArchives"(Upload::class) {
//
+11 -15
View File
@@ -1,6 +1,8 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
description = "Kotlin Compiler (embeddable)"
buildscript {
repositories {
jcenter()
@@ -11,10 +13,7 @@ buildscript {
}
}
val embedCfg = configurations.create("embed")
val mainCfg = configurations.create("default")
val embeddableCompilerBaseName: String by rootProject.extra
val compilerJar by configurations.creating
val kotlinEmbeddableRootPackage = "org.jetbrains.kotlin"
@@ -31,16 +30,14 @@ val packagesToRelocate =
"org.fusesource")
dependencies {
embedCfg(project(":prepare:compiler", configuration = "default"))
compilerJar(project(":kotlin-compiler", configuration = "runtimeJar"))
}
val embeddableTask = task<ShadowJar>("prepare") {
runtimeJar(task<ShadowJar>("embeddable")) {
destinationDir = File(buildDir, "libs")
baseName = embeddableCompilerBaseName
configurations = listOf(mainCfg)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
dependsOn(":build-common:assemble", ":core:script.runtime:assemble")
from(embedCfg.files)
// dependsOn(":kotlin-compiler:proguard")
from(compilerJar)
relocate("com.google.protobuf", "org.jetbrains.kotlin.protobuf")
packagesToRelocate.forEach {
relocate(it, "$kotlinEmbeddableRootPackage.$it")
@@ -51,9 +48,8 @@ val embeddableTask = task<ShadowJar>("prepare") {
}
}
defaultTasks(embeddableTask.name)
sourcesJar()
javadocJar()
publish()
artifacts.add(mainCfg.name, embeddableTask.outputs.files.singleFile) {
builtBy(embeddableTask)
classifier = ""
}
+90 -57
View File
@@ -4,6 +4,8 @@ import proguard.gradle.ProGuardTask
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.api.file.DuplicatesStrategy
description = "Kotlin Compiler"
buildscript {
repositories {
jcenter()
@@ -15,22 +17,21 @@ buildscript {
}
}
apply { plugin("maven") }
plugins {
`java-base`
}
// Set to false to disable proguard run on kotlin-compiler.jar. Speeds up the build
val shrink = true
val bootstrapBuild = false
val compilerManifestClassPath =
if (bootstrapBuild) "kotlin-runtime-internal-bootstrap.jar kotlin-reflect-internal-bootstrap.jar kotlin-script-runtime-internal-bootstrap.jar"
else "kotlin-runtime.jar kotlin-reflect.jar kotlin-script-runtime.jar"
"kotlin-runtime.jar kotlin-reflect.jar kotlin-script-runtime.jar"
val ideaSdkCoreCfg = configurations.create("ideaSdk-core")
val otherDepsCfg = configurations.create("other-deps")
val proguardLibraryJarsCfg = configurations.create("library-jars")
val mainCfg = configurations.create("default_")
val packedCfg = configurations.create("packed")
//val withBootstrapRuntimeCfg = configurations.create("withBootstrapRuntime")
val fatJarContents by configurations.creating
val fatSourcesJarContents by configurations.creating
val proguardLibraryJars by configurations.creating
val fatJar by configurations.creating
val compilerJar by configurations.creating
val archives by configurations
val compilerBaseName: String by rootProject.extra
@@ -38,81 +39,113 @@ val outputJar = File(buildDir, "libs", "$compilerBaseName.jar")
val javaHome = System.getProperty("java.home")
val compilerProject = project(":compiler")
val compilerModules: Array<String> by rootProject.extra
dependencies {
ideaSdkCoreCfg(ideaSdkCoreDeps(*(rootProject.extra["ideaCoreSdkJars"] as Array<String>)))
ideaSdkCoreCfg(ideaSdkDeps("jna-platform", "oromatcher"))
ideaSdkCoreCfg(ideaSdkDeps("jps-model.jar", subdir = "jps"))
otherDepsCfg(commonDep("javax.inject"))
otherDepsCfg(commonDep("org.jline", "jline"))
otherDepsCfg(protobufFull())
otherDepsCfg(commonDep("com.github.spullara.cli-parser", "cli-parser"))
otherDepsCfg(commonDep("com.google.code.findbugs", "jsr305"))
otherDepsCfg(commonDep("io.javaslang","javaslang"))
otherDepsCfg(preloadedDeps("json-org"))
buildVersion()
proguardLibraryJarsCfg(files("$javaHome/lib/rt.jar".takeIf { File(it).exists() } ?: "$javaHome/../Classes/classes.jar",
"$javaHome/lib/jsse.jar".takeIf { File(it).exists() } ?: "$javaHome/../Classes/jsse.jar"))
proguardLibraryJarsCfg(kotlinDep("stdlib"))
proguardLibraryJarsCfg(kotlinDep("script-runtime"))
proguardLibraryJarsCfg(kotlinDep("reflect"))
proguardLibraryJarsCfg(files("${System.getProperty("java.home")}/../lib/tools.jar"))
// proguardLibraryJarsCfg(project(":prepare:runtime", configuration = "default").apply { isTransitive = false })
// proguardLibraryJarsCfg(project(":prepare:reflect", configuration = "default").apply { isTransitive = false })
// proguardLibraryJarsCfg(project(":core:script.runtime").apply { isTransitive = false })
val packagesToRelocate =
listOf("com.intellij",
"com.google",
"com.sampullara",
"org.apache",
"org.jdom",
"org.picocontainer",
"jline",
"gnu",
"javax.inject",
"org.fusesource")
fun firstFromJavaHomeThatExists(vararg paths: String): File =
paths.mapNotNull { File(javaHome, it).takeIf { it.exists() } }.firstOrNull()
?: throw GradleException("Cannot find under '$javaHome' neither of: ${paths.joinToString()}")
compilerModules.forEach { evaluationDependsOn(it) }
val compiledModulesSources = compilerModules.map {
project(it).the<JavaPluginConvention>().sourceSets.getByName("main").allSource
}
val packCompilerTask = task<ShadowJar>("internal.pack-compiler") {
configurations = listOf(packedCfg)
dependencies {
compilerModules.forEach {
fatJarContents(project(it)) { isTransitive = false }
}
compiledModulesSources.forEach {
fatSourcesJarContents(it)
}
// buildVersion()
fatJarContents(project(":core:builtins", configuration = "builtins"))
fatJarContents(ideaSdkCoreDeps(*(rootProject.extra["ideaCoreSdkJars"] as Array<String>)))
fatJarContents(ideaSdkDeps("jna-platform", "oromatcher"))
fatJarContents(ideaSdkDeps("jps-model.jar", subdir = "jps"))
fatJarContents(commonDep("javax.inject"))
fatJarContents(commonDep("org.jline", "jline"))
fatJarContents(protobufFull())
fatJarContents(commonDep("com.github.spullara.cli-parser", "cli-parser"))
fatJarContents(commonDep("com.google.code.findbugs", "jsr305"))
fatJarContents(commonDep("io.javaslang", "javaslang"))
fatJarContents(preloadedDeps("json-org"))
proguardLibraryJars(files(firstFromJavaHomeThatExists("lib/rt.jar", "../Classes/classes.jar"),
firstFromJavaHomeThatExists("lib/jsse.jar", "../Classes/jsse.jar"),
firstFromJavaHomeThatExists("../lib/tools.jar", "../Classes/tools.jar")))
proguardLibraryJars(project(":kotlin-stdlib", configuration = "mainJar"))
proguardLibraryJars(project(":kotlin-script-runtime", configuration = "mainJar"))
proguardLibraryJars(project(":kotlin-reflect", configuration = "mainJar"))
proguardLibraryJars(preloadedDeps("kotlinx-coroutines-core"))
// proguardLibraryJars(project(":prepare:runtime", configuration = "default").apply { isTransitive = false })
// proguardLibraryJars(project(":prepare:reflect", configuration = "default").apply { isTransitive = false })
// proguardLibraryJars(project(":core:script.runtime").apply { isTransitive = false })
}
val packCompiler by task<ShadowJar> {
configurations = listOf(fatJar)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
destinationDir = File(buildDir, "libs")
baseName = compilerBaseName + "-before-shrink"
// baseName = compilerBaseName
dependsOn(protobufFullTask)
setupRuntimeJar("Kotlin Compiler")
(rootProject.extra["compilerModules"] as Array<String>).forEach {
dependsOn("$it:classes")
from(project(it).getCompiledClasses())
}
from(ideaSdkCoreCfg.files)
from(otherDepsCfg.files)
from(project(":core:builtins").getResourceFiles()) { include("kotlin/**") }
setupPublicJar("before-proguard", "")
from(fatJarContents)
manifest.attributes.put("Class-Path", compilerManifestClassPath)
manifest.attributes.put("Main-Class", "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler")
}
val proguardTask = task<ProGuardTask>("internal.proguard-compiler") {
dependsOn(packCompilerTask)
val proguard by task<ProGuardTask> {
dependsOn(packCompiler)
configuration("$rootDir/compiler/compiler.pro")
inputs.files(packCompilerTask.outputs.files.singleFile)
val outputJar = File(buildDir, "libs", "$compilerBaseName-after-proguard.jar")
inputs.files(packCompiler.outputs.files.singleFile)
outputs.file(outputJar)
// TODO: remove after dropping compatibility with ant build
doFirst {
System.setProperty("kotlin-compiler-jar-before-shrink", packCompilerTask.outputs.files.singleFile.canonicalPath)
System.setProperty("kotlin-compiler-jar-before-shrink", packCompiler.outputs.files.singleFile.canonicalPath)
System.setProperty("kotlin-compiler-jar", outputJar.canonicalPath)
}
proguardLibraryJarsCfg.files.forEach { jar ->
libraryjars(jar)
}
libraryjars(proguardLibraryJars)
printconfiguration("$buildDir/compiler.pro.dump")
}
dist {
if (shrink) {
from(proguardTask)
from(proguard)
} else {
from(packCompilerTask)
rename("-before-shrink", "")
from(packCompiler)
}
rename(".*", compilerBaseName + ".jar")
}
artifacts.add(mainCfg.name, proguardTask.outputs.files.singleFile) {
builtBy(proguardTask)
runtimeJarArtifactBy(proguard, proguard.outputs.files.singleFile) {
name = compilerBaseName
classifier = ""
}
sourcesJar {
from(fatSourcesJarContents)
}
javadocJar()
publish()
+31
View File
@@ -0,0 +1,31 @@
description = "Kotlin Daemon Client"
apply { plugin("kotlin") }
val nativePlatformUberjar = "$rootDir/dependencies/native-platform-uberjar.jar"
dependencies {
val compile by configurations
compile(project(":compiler:util"))
compile(project(":compiler:cli-common"))
compile(project(":compiler:daemon-common"))
compile(files(nativePlatformUberjar))
buildVersion()
}
configureKotlinProjectSourcesDefault()
configureKotlinProjectNoTests()
val jar = runtimeJar {
from(zipTree(nativePlatformUberjar))
}
sourcesJar()
javadocJar()
dist {
from(jar)
}
publish()