Skip to content

Commit 28cb8ff

Browse files
ting-yuanKSP Auto Pick
authored andcommitted
Customize KotlinCompilerVersion in symbol-processing-aa-embeddable
Also renamed META-INF/compiler.version to META-INF/ksp.compiler.version (cherry picked from commit 90e5b80)
1 parent e74274e commit 28cb8ff

2 files changed

Lines changed: 90 additions & 1 deletion

File tree

symbol-processing-aa-embeddable/build.gradle.kts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import java.util.zip.ZipFile
44

55
evaluationDependsOn(":kotlin-analysis-api")
66

7-
val kotlinBaseVersion: String by project
87
val signingKey: String? by project
98
val signingPassword: String? by project
109

@@ -68,6 +67,7 @@ tasks.withType<ShadowJar> {
6867
relocate(f, t)
6968
}
7069
mergeServiceFiles()
70+
exclude("META-INF/compiler.version")
7171

7272
// All bundled dependencies should be renamed.
7373
doLast {
@@ -203,3 +203,30 @@ signing {
203203
useInMemoryPgpKeys(signingKey, signingPassword)
204204
sign(extensions.getByType<PublishingExtension>().publications)
205205
}
206+
207+
abstract class WriteVersionSrcTask @Inject constructor(
208+
@get:Input val kotlinVersion: String,
209+
@get:OutputDirectory val outputResDir: File
210+
) : DefaultTask() {
211+
@TaskAction
212+
fun generate() {
213+
val metaInfDir = File(outputResDir, "META-INF")
214+
metaInfDir.mkdirs()
215+
File(metaInfDir, "ksp.compiler.version").writeText(kotlinVersion)
216+
}
217+
}
218+
219+
val kspVersionDir = File(project.buildDir, "generated/ksp-versions/META-INF")
220+
val writeVersionSrcTask = tasks.register<WriteVersionSrcTask>(
221+
"generateKSPVersions",
222+
aaKotlinBaseVersion,
223+
kspVersionDir
224+
)
225+
226+
kotlin {
227+
sourceSets {
228+
main {
229+
resources.srcDir(writeVersionSrcTask.map { it.outputResDir })
230+
}
231+
}
232+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
4+
*/
5+
6+
package org.jetbrains.kotlin.config;
7+
8+
import org.jetbrains.annotations.Nullable;
9+
10+
import java.io.BufferedReader;
11+
import java.io.IOException;
12+
import java.io.InputStreamReader;
13+
14+
public class KotlinCompilerVersion {
15+
public static final String VERSION_FILE_PATH = "/META-INF/ksp.compiler.version";
16+
public static final String VERSION;
17+
18+
// True if the latest stable language version supported by this compiler has not yet been released.
19+
// Binaries produced by this compiler with that language version (or any future language version) are going to be marked
20+
// as "pre-release" and will not be loaded by release versions of the compiler.
21+
// Change this value before and after every major release
22+
private static final boolean IS_PRE_RELEASE = true;
23+
24+
public static final String TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY = "kotlin.test.is.pre.release";
25+
26+
public static boolean isPreRelease() {
27+
String overridden = System.getProperty(TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY);
28+
if (overridden != null) {
29+
return Boolean.parseBoolean(overridden);
30+
}
31+
32+
return IS_PRE_RELEASE;
33+
}
34+
35+
/**
36+
* @return version of this compiler, or `null` if it isn't known (if VERSION is "@snapshot@")
37+
*/
38+
@Nullable
39+
public static String getVersion() {
40+
return VERSION.equals("@snapshot@") ? null : VERSION;
41+
}
42+
43+
@SuppressWarnings({"TryFinallyCanBeTryWithResources", "ConstantConditions"})
44+
private static String loadKotlinCompilerVersion() throws IOException {
45+
BufferedReader versionReader = new BufferedReader(
46+
new InputStreamReader(KotlinCompilerVersion.class.getResourceAsStream(VERSION_FILE_PATH)));
47+
try {
48+
return versionReader.readLine();
49+
} finally {
50+
versionReader.close();
51+
}
52+
}
53+
54+
static {
55+
try {
56+
VERSION = loadKotlinCompilerVersion();
57+
}
58+
catch (IOException e) {
59+
throw new IllegalStateException("Failed to read compiler version from " + VERSION_FILE_PATH);
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)