From b33d245dfbd47136bd66b89a854ddfd99108b0a5 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 8 Mar 2021 14:22:04 +0100 Subject: [PATCH] Do not print stdlib version substitution message if nothing changed --- prepare/build.version/build.gradle.kts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/prepare/build.version/build.gradle.kts b/prepare/build.version/build.gradle.kts index f0b9a6aa3a5..0c670eb3ca3 100644 --- a/prepare/build.version/build.gradle.kts +++ b/prepare/build.version/build.gradle.kts @@ -30,21 +30,25 @@ val writeStdlibVersion by tasks.registering { inputs.property("version", kotlinVersionLocal) outputs.file(versionFile) - fun replaceVersion(versionFile: File, versionPattern: String, replacement: (MatchResult) -> String) { + fun Task.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 group = match.groups[1]!! val newValue = replacement(match) - versionFile.writeText(text.replaceRange(match.groups[1]!!.range, newValue)) + if (newValue != group.value) { + logger.lifecycle("Writing new standard library version components: $newValue (was: ${group.value})") + versionFile.writeText(text.replaceRange(group.range, newValue)) + } else { + logger.info("Standard library version components: ${group.value}") + } } doLast { replaceVersion(versionFile, """fun get\(\): KotlinVersion = KotlinVersion\((\d+, \d+, \d+)\)""") { 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 + "$major, $minor, ${optPatch.takeIf { it.isNotEmpty() } ?: "0" }" } } }