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.
This commit is contained in:
Vyacheslav Gerasimov
2020-02-29 19:12:09 +03:00
parent c2457cae60
commit bab87c9837
10 changed files with 55 additions and 29 deletions
-10
View File
@@ -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<JavaCompile> {
sourceCompatibility = "1.6"
targetCompatibility = "1.6"
}
tasks.named<ProcessResources>("processResources") {
inputs.property("compilerVersion", kotlinVersion)
filesMatching("META-INF/compiler.version") {
filter<ReplaceTokens>("tokens" to mapOf("snapshot" to kotlinVersion))
}
}
@@ -1 +0,0 @@
@snapshot@
@@ -1,79 +0,0 @@
/*
* 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.
*/
package org.jetbrains.kotlin.config;
import org.jetbrains.annotations.Nullable;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class KotlinCompilerVersion {
public static final String VERSION_FILE_PATH = "/META-INF/compiler.version";
public static final String VERSION;
// True if the latest stable language version supported by this compiler has not yet been released.
// Binaries produced by this compiler with that language version (or any future language version) are going to be marked
// as "pre-release" and will not be loaded by release versions of the compiler.
// Change this value before and after every major release
private static final boolean IS_PRE_RELEASE = true;
public static final String TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY = "kotlin.test.is.pre.release";
public static boolean isPreRelease() {
String overridden = System.getProperty(TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY);
if (overridden != null) {
return Boolean.parseBoolean(overridden);
}
return IS_PRE_RELEASE;
}
/**
* @return version of this compiler, or `null` if it isn't known (if VERSION is "@snapshot@")
*/
@Nullable
public static String getVersion() {
return VERSION.equals("@snapshot@") ? null : VERSION;
}
private static String loadKotlinCompilerVersion() throws IOException {
BufferedReader versionReader = new BufferedReader(
new InputStreamReader(KotlinCompilerVersion.class.getResourceAsStream(VERSION_FILE_PATH)));
try {
return versionReader.readLine();
} finally {
versionReader.close();
}
}
static {
try {
VERSION = loadKotlinCompilerVersion();
}
catch (IOException e) {
throw new IllegalStateException("Failed to read compiler version from " + VERSION_FILE_PATH);
}
if (!VERSION.equals("@snapshot@") && !VERSION.contains("-") && IS_PRE_RELEASE) {
throw new IllegalStateException(
"IS_PRE_RELEASE cannot be true for a compiler without '-' in its version.\n" +
"Please change IS_PRE_RELEASE to false, commit and push this change to master"
);
}
}
}