2021-10-18 22:31:18 -04:00
|
|
|
import java.nio.file.Path
|
2021-01-16 20:41:47 -08:00
|
|
|
import java.time.LocalDateTime
|
|
|
|
|
import java.time.format.DateTimeFormatter
|
|
|
|
|
|
2026-04-11 12:14:42 -05:00
|
|
|
ext.getCurrentVersion = {
|
|
|
|
|
String tagIsh = "dev-unknown"
|
|
|
|
|
try {
|
|
|
|
|
tagIsh = providers.exec {
|
|
|
|
|
commandLine 'git', 'describe', '--tags', '--match=v*'
|
|
|
|
|
}.standardOutput.asText.get().trim().toLowerCase()
|
|
|
|
|
} catch (Exception ignored) {
|
|
|
|
|
tagIsh = "dev-unknown"
|
2021-01-16 20:41:47 -08:00
|
|
|
}
|
|
|
|
|
|
2026-04-11 12:14:42 -05:00
|
|
|
// Dev tags: v2021.1.6-3-gf922466d
|
|
|
|
|
// We're specifically looking to capture the middle -3-
|
|
|
|
|
boolean isDev = tagIsh.matches(".*-[0-9]*-g[0-9a-f]*")
|
|
|
|
|
if (isDev && !tagIsh.startsWith("dev-")) tagIsh = "dev-" + tagIsh
|
|
|
|
|
println("Picked up version: " + tagIsh)
|
|
|
|
|
return tagIsh
|
|
|
|
|
}
|
2021-10-18 22:31:18 -04:00
|
|
|
|
2026-04-11 12:14:42 -05:00
|
|
|
if (!ext.has("versionString")) {
|
|
|
|
|
ext.versionString = getCurrentVersion()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ext.writePhotonVersionFile = {File versionFileIn, Path path, String version ->
|
|
|
|
|
println("Writing " + version + " to " + path.toAbsolutePath().toString())
|
|
|
|
|
String date = DateTimeFormatter.ofPattern("yyyy-M-d hh:mm:ss").format(LocalDateTime.now())
|
|
|
|
|
File versionFileOut = new File(path.toAbsolutePath().toString())
|
|
|
|
|
versionFileOut.delete()
|
|
|
|
|
|
|
|
|
|
def read = versionFileIn.text
|
|
|
|
|
.replace('${version}', version)
|
|
|
|
|
.replace('${date}', date)
|
|
|
|
|
.replace('${wpilibVersion}', wpilibVersion)
|
|
|
|
|
// Note that OpenCV is usually {VERSION}-{some suffix}, we just want the first bit
|
|
|
|
|
.replace('${opencvVersion}', openCVversion.split("-").first())
|
|
|
|
|
if (!versionFileOut.parentFile.exists()) versionFileOut.parentFile.mkdirs()
|
|
|
|
|
if (!versionFileOut.exists()) versionFileOut.createNewFile()
|
|
|
|
|
versionFileOut.write(read)
|
2021-01-16 20:41:47 -08:00
|
|
|
}
|