From bab87c983789c5e3e1a9ef643e9d41d855c94507 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gerasimov Date: Sat, 29 Feb 2020 19:12:09 +0300 Subject: [PATCH] Build: Extract compiler version to separate module to improve caching Compiler version changes every build and makes impossible to reuse caches for heavy tasks such as compiler proguard. We may fix that by adding version module directly to the final jar. --- build.gradle.kts | 1 + compiler/compiler.version/build.gradle.kts | 31 +++++++++++++++++++ .../resources/META-INF/compiler.version | 0 .../kotlin/config/KotlinCompilerVersion.java | 15 ++------- compiler/util/build.gradle.kts | 6 ++-- core/util.runtime/build.gradle.kts | 10 ------ prepare/compiler/build.gradle.kts | 16 ++++++++-- prepare/idea-plugin/build.gradle.kts | 1 + prepare/jps-plugin/build.gradle.kts | 3 +- settings.gradle | 1 + 10 files changed, 55 insertions(+), 29 deletions(-) create mode 100644 compiler/compiler.version/build.gradle.kts rename {core/util.runtime => compiler/compiler.version}/resources/META-INF/compiler.version (100%) rename {core/util.runtime => compiler/compiler.version}/src/org/jetbrains/kotlin/config/KotlinCompilerVersion.java (79%) diff --git a/build.gradle.kts b/build.gradle.kts index 7e852a6a997..ea408da0cbb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -234,6 +234,7 @@ extra["compilerModules"] = arrayOf( ":compiler:cli", ":compiler:cli-js", ":compiler:incremental-compilation-impl", + ":compiler:compiler.version", ":js:js.ast", ":js:js.serializer", ":js:js.parser", diff --git a/compiler/compiler.version/build.gradle.kts b/compiler/compiler.version/build.gradle.kts new file mode 100644 index 00000000000..42a948f9c9b --- /dev/null +++ b/compiler/compiler.version/build.gradle.kts @@ -0,0 +1,31 @@ +import org.apache.tools.ant.filters.ReplaceTokens + +plugins { + java +} + +jvmTarget = "1.6" +javaHome = rootProject.extra["JDK_16"] as String + +val kotlinVersion: String by rootProject.extra + +dependencies { + compileOnly("org.jetbrains:annotations:13.0") +} + +sourceSets { + "main" { projectDefault() } + "test" {} +} + +tasks.withType { + sourceCompatibility = "1.6" + targetCompatibility = "1.6" +} + +tasks.named("processResources") { + inputs.property("compilerVersion", kotlinVersion) + filesMatching("META-INF/compiler.version") { + filter("tokens" to mapOf("snapshot" to kotlinVersion)) + } +} \ No newline at end of file diff --git a/core/util.runtime/resources/META-INF/compiler.version b/compiler/compiler.version/resources/META-INF/compiler.version similarity index 100% rename from core/util.runtime/resources/META-INF/compiler.version rename to compiler/compiler.version/resources/META-INF/compiler.version diff --git a/core/util.runtime/src/org/jetbrains/kotlin/config/KotlinCompilerVersion.java b/compiler/compiler.version/src/org/jetbrains/kotlin/config/KotlinCompilerVersion.java similarity index 79% rename from core/util.runtime/src/org/jetbrains/kotlin/config/KotlinCompilerVersion.java rename to compiler/compiler.version/src/org/jetbrains/kotlin/config/KotlinCompilerVersion.java index 3c72e919971..17e53820f0d 100644 --- a/core/util.runtime/src/org/jetbrains/kotlin/config/KotlinCompilerVersion.java +++ b/compiler/compiler.version/src/org/jetbrains/kotlin/config/KotlinCompilerVersion.java @@ -1,17 +1,6 @@ /* - * 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-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.config; diff --git a/compiler/util/build.gradle.kts b/compiler/util/build.gradle.kts index c7864e52463..0eea3d74a72 100644 --- a/compiler/util/build.gradle.kts +++ b/compiler/util/build.gradle.kts @@ -5,8 +5,10 @@ plugins { } dependencies { - compile(kotlinStdlib()) - compile(project(":core:deserialization")) + api(kotlinStdlib()) + api(project(":compiler:compiler.version")) + api(project(":core:deserialization")) + compileOnly(project(":kotlin-reflect-api")) compileOnly(intellijCoreDep()) { includeJars("intellij-core") } compileOnly(intellijDep()) { includeIntellijCoreJarDependencies(project) } diff --git a/core/util.runtime/build.gradle.kts b/core/util.runtime/build.gradle.kts index 2af07e5767f..395445f6a14 100644 --- a/core/util.runtime/build.gradle.kts +++ b/core/util.runtime/build.gradle.kts @@ -1,4 +1,3 @@ -import org.apache.tools.ant.filters.ReplaceTokens plugins { java @@ -9,8 +8,6 @@ plugins { jvmTarget = "1.6" javaHome = rootProject.extra["JDK_16"] as String -val kotlinVersion: String by rootProject.extra - dependencies { compileOnly(kotlinStdlib()) } @@ -24,10 +21,3 @@ tasks.withType { sourceCompatibility = "1.6" targetCompatibility = "1.6" } - -tasks.named("processResources") { - inputs.property("compilerVersion", kotlinVersion) - filesMatching("META-INF/compiler.version") { - filter("tokens" to mapOf("snapshot" to kotlinVersion)) - } -} \ No newline at end of file diff --git a/prepare/compiler/build.gradle.kts b/prepare/compiler/build.gradle.kts index f8a884895d7..dee693ad059 100644 --- a/prepare/compiler/build.gradle.kts +++ b/prepare/compiler/build.gradle.kts @@ -15,6 +15,7 @@ plugins { val fatJarContents by configurations.creating val fatJarContentsStripMetadata by configurations.creating val fatJarContentsStripServices by configurations.creating +val compilerVersion by configurations.creating // JPS build assumes fat jar is built from embedded configuration, // but we can't use it in gradle build since slightly more complex processing is required like stripping metadata & services from some jars @@ -139,9 +140,13 @@ dependencies { ) ) - compilerModules.forEach { - fatJarContents(project(it)) { isTransitive = false } - } + compilerVersion(project(":compiler:compiler.version")) + proguardLibraries(project(":compiler:compiler.version")) + compilerModules + .filter { it != ":compiler:compiler.version" } // Version will be added directly to the final jar excluding proguard and relocation + .forEach { + fatJarContents(project(it)) { isTransitive = false } + } libraries(intellijDep()) { includeIntellijCoreJarDependencies(project) { it.startsWith("trove4j") } } libraries(commonDep("io.ktor", "ktor-network")) @@ -272,11 +277,16 @@ val distDir: String by rootProject.extra val jar = runtimeJar { dependsOn(pack) + dependsOn(compilerVersion) from { zipTree(pack.get().outputs.files.singleFile) } + from { + compilerVersion.map(::zipTree) + } + manifest.attributes["Class-Path"] = compilerManifestClassPath manifest.attributes["Main-Class"] = "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler" } diff --git a/prepare/idea-plugin/build.gradle.kts b/prepare/idea-plugin/build.gradle.kts index e75b5e2ca4e..1fe6e32aac4 100644 --- a/prepare/idea-plugin/build.gradle.kts +++ b/prepare/idea-plugin/build.gradle.kts @@ -74,6 +74,7 @@ val projectsToShadow by extra(listOf( ":compiler:resolution", ":compiler:serialization", ":compiler:util", + ":compiler:compiler.version", ":core:util.runtime", ":plugins:lint", ":plugins:uast-kotlin", diff --git a/prepare/jps-plugin/build.gradle.kts b/prepare/jps-plugin/build.gradle.kts index 47b33ed941a..fc5db5c3b3c 100644 --- a/prepare/jps-plugin/build.gradle.kts +++ b/prepare/jps-plugin/build.gradle.kts @@ -20,7 +20,8 @@ val projectsToShadow = listOf( ":jps-plugin", ":kotlin-preloader", ":compiler:util", - ":core:util.runtime" + ":core:util.runtime", + ":compiler:compiler.version" ) dependencies { diff --git a/settings.gradle b/settings.gradle index 17a7677d74c..6bf37b5e285 100644 --- a/settings.gradle +++ b/settings.gradle @@ -138,6 +138,7 @@ include ":kotlin-build-common", ":core:metadata", ":core:metadata.jvm", ":core:util.runtime", + ":compiler:compiler.version", ":dependencies:android-sdk", ":idea:idea-jvm", ":idea:idea-maven",