Write compiler and stdlib versions from gradle build
This commit is contained in:
+1
-8
@@ -75,14 +75,7 @@
|
|||||||
</macrodef>
|
</macrodef>
|
||||||
|
|
||||||
<target name="writeCompilerVersionToTemplateFile">
|
<target name="writeCompilerVersionToTemplateFile">
|
||||||
<mkdir dir="${version_substitute_dir}"/>
|
<!-- empty, version is written in gradle build -->
|
||||||
|
|
||||||
<substituteVersionInFile
|
|
||||||
target.file="${compiler.version.java}"
|
|
||||||
target.file.bk="${compiler.version.java.bk}"
|
|
||||||
target.file.versioned="${compiler.version.java.versioned}"
|
|
||||||
test.string="public static final String VERSION = "@snapshot@";"
|
|
||||||
version="${compiler.version.number}"/>
|
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="writePluginVersionToTemplateFile">
|
<target name="writePluginVersionToTemplateFile">
|
||||||
|
|||||||
@@ -20,3 +20,6 @@ tasks.withType<JavaCompile> {
|
|||||||
sourceCompatibility = "1.6"
|
sourceCompatibility = "1.6"
|
||||||
targetCompatibility = "1.6"
|
targetCompatibility = "1.6"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (project.hasProperty("teamcity"))
|
||||||
|
tasks["compileJava"].dependsOn(":prepare:build.version:writeCompilerVersion")
|
||||||
@@ -128,6 +128,7 @@ compileBuiltinsKotlin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
compileKotlin {
|
compileKotlin {
|
||||||
|
dependsOn(":prepare:build.version:writeStdlibVersion")
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
freeCompilerArgs = [
|
freeCompilerArgs = [
|
||||||
"-version",
|
"-version",
|
||||||
|
|||||||
@@ -68,8 +68,7 @@ public class KotlinVersion(val major: Int, val minor: Int, val patch: Int) : Com
|
|||||||
/**
|
/**
|
||||||
* Returns the current version of the Kotlin standard library.
|
* Returns the current version of the Kotlin standard library.
|
||||||
*/
|
*/
|
||||||
// TODO: get from metadata or hardcode automatically during build
|
|
||||||
@kotlin.jvm.JvmField
|
@kotlin.jvm.JvmField
|
||||||
public val CURRENT: KotlinVersion = KotlinVersion(1, 2, 0)
|
public val CURRENT: KotlinVersion = KotlinVersion(1, 2, 0) // value is written here automatically during build
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,31 +4,66 @@ import java.io.File
|
|||||||
val buildVersionFilePath = "${rootProject.extra["distDir"]}/build.txt"
|
val buildVersionFilePath = "${rootProject.extra["distDir"]}/build.txt"
|
||||||
|
|
||||||
val buildVersion by configurations.creating
|
val buildVersion by configurations.creating
|
||||||
|
val buildNumber: String by rootProject.extra
|
||||||
|
val kotlinVersion: String by rootProject.extra
|
||||||
|
|
||||||
val prepare = task("prepare") {
|
val writeBuildNumber by tasks.creating {
|
||||||
val versionString = rootProject.extra["buildNumber"].toString()
|
|
||||||
val versionFile = File(buildVersionFilePath)
|
val versionFile = File(buildVersionFilePath)
|
||||||
outputs.file(buildVersionFilePath)
|
inputs.property("version", buildNumber)
|
||||||
outputs.upToDateWhen {
|
outputs.file(versionFile)
|
||||||
(versionFile.exists() && versionFile.readText().trim() == versionString).also {
|
|
||||||
if (!it) {
|
|
||||||
logger.info("$versionFile is not up-to-date: ${versionFile.takeIf { it.exists() }?.readText()?.trim()}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
doLast {
|
doLast {
|
||||||
versionFile.parentFile.mkdirs()
|
versionFile.parentFile.mkdirs()
|
||||||
versionFile.writeText(versionString)
|
versionFile.writeText(buildNumber)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun replaceVersion(versionFile: File, versionPattern: String, replacement: (MatchResult) -> String) {
|
||||||
|
check(versionFile.isFile) { "Version file $versionFile is not found" }
|
||||||
|
val text = versionFile.readText()
|
||||||
|
val pattern = Regex(versionPattern)
|
||||||
|
val match = pattern.find(text) ?: error("Version pattern is missing in file $versionFile")
|
||||||
|
val newValue = replacement(match)
|
||||||
|
versionFile.writeText(text.replaceRange(match.groups[1]!!.range, newValue))
|
||||||
|
}
|
||||||
|
|
||||||
|
val writeStdlibVersion by tasks.creating {
|
||||||
|
val versionFile = rootDir.resolve("libraries/stdlib/src/kotlin/util/KotlinVersion.kt")
|
||||||
|
inputs.property("version", kotlinVersion)
|
||||||
|
outputs.file(versionFile)
|
||||||
|
doLast {
|
||||||
|
replaceVersion(versionFile, """val CURRENT: KotlinVersion = KotlinVersion\((\d+, \d+, \d+)\)""") {
|
||||||
|
val (major, minor, _, optPatch) = Regex("""^(\d+)\.(\d+)(\.(\d+))?""").find(kotlinVersion)?.destructured ?: error("Cannot parse current version $kotlinVersion")
|
||||||
|
val newVersion = "$major, $minor, ${optPatch.takeIf { it.isNotEmpty() } ?: "0" }"
|
||||||
|
logger.lifecycle("Writing new standard library version components: $newVersion")
|
||||||
|
newVersion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val writeCompilerVersion by tasks.creating {
|
||||||
|
val versionFile = rootDir.resolve("core/util.runtime/src/org/jetbrains/kotlin/config/KotlinCompilerVersion.java")
|
||||||
|
inputs.property("version", kotlinVersion)
|
||||||
|
outputs.file(versionFile)
|
||||||
|
doLast {
|
||||||
|
replaceVersion(versionFile, """public static final String VERSION = "([^"]+)"""") {
|
||||||
|
logger.lifecycle("Writing new compiler version: $kotlinVersion")
|
||||||
|
kotlinVersion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val writeVersions by tasks.creating {
|
||||||
|
dependsOn(writeBuildNumber, writeStdlibVersion, writeCompilerVersion)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
artifacts.add(buildVersion.name, file(buildVersionFilePath)) {
|
artifacts.add(buildVersion.name, file(buildVersionFilePath)) {
|
||||||
builtBy(prepare)
|
builtBy(writeBuildNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
val distKotlinHomeDir: String by rootProject.extra
|
val distKotlinHomeDir: String by rootProject.extra
|
||||||
|
|
||||||
val dist by task<Copy> {
|
val dist by task<Copy> {
|
||||||
from(prepare)
|
from(writeBuildNumber)
|
||||||
into(File(distKotlinHomeDir))
|
into(File(distKotlinHomeDir))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user