Remove MiraiConsoleBuildConstants from git and generate it everytime on build

This commit is contained in:
Him188 2021-12-26 17:41:04 +00:00
parent d904cd9992
commit 41b424c555
3 changed files with 22 additions and 24 deletions

View File

@ -0,0 +1 @@
src/internal/MiraiConsoleBuildConstants.kt

View File

@ -11,8 +11,8 @@
import BinaryCompatibilityConfigurator.configureBinaryValidator
import BinaryCompatibilityConfigurator.configureBinaryValidators
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.time.Instant
import java.time.*
import java.time.format.*
plugins {
kotlin("jvm")
@ -53,29 +53,22 @@ dependencies {
}
tasks {
val compileKotlin by getting {}
register("fillBuildConstants") {
val task = register("generateBuildConstants") {
group = "mirai"
doLast {
(compileKotlin as KotlinCompile).source.filter { it.name == "MiraiConsoleBuildConstants.kt" }.single()
.let { file ->
file.writeText(
file.readText()
.replace(
Regex("""val buildDate: Instant = Instant.ofEpochSecond\(.*\)""")
) {
"""val buildDate: Instant = Instant.ofEpochSecond(${
Instant.now().epochSecond
})"""
}
.replace(
Regex("""const val versionConst:\s+String\s+=\s+".*"""")
) { """const val versionConst: String = "${project.version}"""" }
)
}
val now = Instant.now()
project.file("src/internal/MiraiConsoleBuildConstants.kt").writeText(
project.file("src/internal/MiraiConsoleBuildConstants.kt.template").readText()
.replace("GENERATION_DATE", now.atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME))
.replace("BUILD_DATE", now.epochSecond.toString())
.replace("VERSION_CONSTANT", project.version.toString())
)
}
}
afterEvaluate {
getByName("compileKotlin").dependsOn(task)
}
}
configurePublishing("mirai-console")

View File

@ -7,15 +7,19 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
/*
* Important: This file is generated on build by Gradle task 'generateBuildConstants', on GENERATION_DATE
*/
package net.mamoe.mirai.console.internal
import net.mamoe.mirai.console.util.SemVersion
import java.time.Instant
internal object MiraiConsoleBuildConstants { // auto-filled on build (task :mirai-console:fillBuildConstants)
internal object MiraiConsoleBuildConstants {
@JvmStatic
val buildDate: Instant = Instant.ofEpochSecond(1628666895)
const val versionConst: String = "2.7.0"
val buildDate: Instant = Instant.ofEpochSecond(BUILD_DATE)
const val versionConst: String = "VERSION_CONSTANT"
@JvmStatic
val version: SemVersion = SemVersion(versionConst)