[Build] Fix configuration cache issues (part 1)

* Make `clean` task compatible with configuration cache
* Make Java compile instrumentation compatible with configuration cache
* Make settings.gradle compatible with configuration cache
* Initial work on making IntelliJInstrumentCodeTask compatible with configuration cache
* Make writeStdlibVersion task compatible with configuration cache
* Copy some properties to not capture it's owning object into lambda to support configuration cache

Relates to #KT-44611
This commit is contained in:
Alexander Likhachev
2021-01-29 05:44:51 +03:00
parent 111e67dc8d
commit 27956adf3f
11 changed files with 120 additions and 88 deletions
+14 -10
View File
@@ -21,22 +21,26 @@ artifacts.add(buildVersion.name, file(buildVersionFilePath)) {
builtBy(writeBuildNumber)
}
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.registering {
val kotlinVersionLocal = kotlinVersion
val versionFile = rootDir.resolve("libraries/stdlib/src/kotlin/util/KotlinVersion.kt")
inputs.property("version", kotlinVersion)
inputs.property("version", kotlinVersionLocal)
outputs.file(versionFile)
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))
}
doLast {
replaceVersion(versionFile, """fun get\(\): KotlinVersion = KotlinVersion\((\d+, \d+, \d+)\)""") {
val (major, minor, _, optPatch) = Regex("""^(\d+)\.(\d+)(\.(\d+))?""").find(kotlinVersion)?.destructured ?: error("Cannot parse current version $kotlinVersion")
val (major, minor, _, optPatch) = Regex("""^(\d+)\.(\d+)(\.(\d+))?""").find(kotlinVersionLocal)?.destructured ?: error("Cannot parse current version $kotlinVersionLocal")
val newVersion = "$major, $minor, ${optPatch.takeIf { it.isNotEmpty() } ?: "0" }"
logger.lifecycle("Writing new standard library version components: $newVersion")
newVersion
+1 -1
View File
@@ -42,7 +42,7 @@ noDefaultJar()
// dummy is used for rewriting dependencies to the shaded packages in the embeddable compiler
compilerDummyJar(compilerDummyForDependenciesRewriting("compilerDummy") {
classifier = "dummy"
archiveClassifier.set("dummy")
})
class CoreXmlShadingTransformer : Transformer {