2023-11-13 02:50:57 -08:00
|
|
|
import co.electriccoin.zcash.Git
|
2024-07-18 01:48:02 -07:00
|
|
|
import publish.ChangelogParser
|
2024-11-18 03:33:33 -08:00
|
|
|
import publish.LanguageTag
|
2021-10-19 06:24:45 -07:00
|
|
|
import java.text.SimpleDateFormat
|
2024-11-11 03:47:16 -08:00
|
|
|
import java.util.Date
|
|
|
|
import java.util.TimeZone
|
2021-10-19 06:24:45 -07:00
|
|
|
|
|
|
|
plugins {
|
|
|
|
kotlin("multiplatform")
|
2022-06-13 11:06:23 -07:00
|
|
|
id("secant.kotlin-multiplatform-build-conventions")
|
|
|
|
id("secant.dependency-conventions")
|
2021-10-19 06:24:45 -07:00
|
|
|
}
|
|
|
|
|
2024-11-11 03:47:16 -08:00
|
|
|
private val gitShaKey = "gitSha"
|
|
|
|
private val gitCommitCountKey = "gitCommitCount"
|
|
|
|
private val releaseNotesEn = "releaseNotesEn"
|
|
|
|
private val releaseNotesEs = "releaseNotesEs"
|
|
|
|
|
|
|
|
private val releaseNotesEnPath = "docs/whatsNew/WHATS_NEW_EN.md"
|
|
|
|
private val releaseNotesEsPath = "docs/whatsNew/WHATS_NEW_ES.md"
|
|
|
|
|
2021-10-19 06:24:45 -07:00
|
|
|
// Injects build information
|
|
|
|
// Note timestamp is not currently injected because it effectively disables the cache since it
|
|
|
|
// changes with every build
|
|
|
|
val generateBuildConfigTask = tasks.create("buildConfig") {
|
2023-08-31 01:10:52 -07:00
|
|
|
val generatedDir = layout.buildDirectory.dir("generated").get().asFile
|
2021-10-19 06:24:45 -07:00
|
|
|
|
2023-11-13 02:50:57 -08:00
|
|
|
val gitInfo = co.electriccoin.zcash.Git.newInfo(
|
|
|
|
Git.HEAD,
|
|
|
|
parent!!.projectDir
|
|
|
|
)
|
2024-07-18 01:48:02 -07:00
|
|
|
|
2024-11-11 03:47:16 -08:00
|
|
|
inputs.property(gitShaKey, gitInfo.sha)
|
|
|
|
inputs.property(gitCommitCountKey, gitInfo.commitCount)
|
2024-07-18 01:48:02 -07:00
|
|
|
|
2024-11-11 03:47:16 -08:00
|
|
|
//val buildTimestamp = newIso8601Timestamp()
|
2021-10-19 06:24:45 -07:00
|
|
|
//inputs.property("buildTimestamp", buildTimestamp)
|
|
|
|
|
2024-11-11 03:47:16 -08:00
|
|
|
// Add release notes for all supported languages
|
|
|
|
fillInReleaseNotes(inputs)
|
2024-07-18 01:48:02 -07:00
|
|
|
|
2023-08-31 01:10:52 -07:00
|
|
|
outputs.dir(generatedDir)
|
2021-10-19 06:24:45 -07:00
|
|
|
|
|
|
|
doLast {
|
|
|
|
val outputFile = File("$generatedDir/co/electriccoin/zcash/build/BuildConfig.kt")
|
|
|
|
outputFile.parentFile.mkdirs()
|
|
|
|
|
|
|
|
// To add timestamp, add this to the output below
|
|
|
|
// import kotlinx.datetime.Instant
|
|
|
|
// import kotlinx.datetime.toInstant
|
|
|
|
// val buildTimestamp: Instant = "$buildTimestamp".toInstant()
|
|
|
|
outputFile.writeText(
|
|
|
|
"""
|
|
|
|
// Generated file
|
|
|
|
package co.electriccoin.zcash.build
|
|
|
|
|
2024-11-11 03:47:16 -08:00
|
|
|
const val gitSha: String = "${inputs.properties[gitShaKey]}"
|
|
|
|
const val gitCommitCount: Int = ${inputs.properties[gitCommitCountKey]}
|
|
|
|
const val releaseNotesEn: String = "${inputs.properties[releaseNotesEn]}"
|
|
|
|
const val releaseNotesEs: String = "${inputs.properties[releaseNotesEs]}"
|
2021-10-19 06:24:45 -07:00
|
|
|
""".trimIndent()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
kotlin {
|
|
|
|
jvm()
|
|
|
|
sourceSets {
|
|
|
|
getByName("commonMain") {
|
|
|
|
dependencies {
|
|
|
|
kotlin.srcDir(generateBuildConfigTask)
|
|
|
|
//api(libs.kotlinx.datetime)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
getByName("commonTest") {
|
|
|
|
dependencies {
|
|
|
|
implementation(kotlin("test"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
getByName("jvmMain") {
|
|
|
|
dependencies {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
getByName("jvmTest") {
|
|
|
|
dependencies {
|
|
|
|
implementation(kotlin("test"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Current ISO 8601 timestamp.
|
|
|
|
*/
|
|
|
|
fun newIso8601Timestamp(): String {
|
|
|
|
val formatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ").apply {
|
|
|
|
timeZone = TimeZone.getTimeZone("UTC")
|
|
|
|
}
|
|
|
|
return formatter.format(Date())
|
|
|
|
}
|
2024-11-11 03:47:16 -08:00
|
|
|
|
|
|
|
fun fillInReleaseNotes(inputs: TaskInputs) {
|
|
|
|
val gradleVersionName = project.property("ZCASH_VERSION_NAME").toString()
|
|
|
|
|
|
|
|
val releaseNotesEnJson = ChangelogParser.getChangelogEntry(
|
|
|
|
filePath = releaseNotesEnPath,
|
2024-11-18 03:33:33 -08:00
|
|
|
versionNameFallback = gradleVersionName,
|
|
|
|
languageTag = LanguageTag.English()
|
2024-11-11 03:47:16 -08:00
|
|
|
).toJsonString()
|
|
|
|
|
|
|
|
inputs.property(releaseNotesEn, releaseNotesEnJson)
|
|
|
|
|
|
|
|
val releaseNotesEsJson = ChangelogParser.getChangelogEntry(
|
|
|
|
filePath = releaseNotesEsPath,
|
2024-11-18 03:33:33 -08:00
|
|
|
versionNameFallback = gradleVersionName,
|
|
|
|
languageTag = LanguageTag.Spanish()
|
2024-11-11 03:47:16 -08:00
|
|
|
).toJsonString()
|
|
|
|
|
|
|
|
inputs.property(releaseNotesEs, releaseNotesEsJson)
|
|
|
|
}
|