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
|
|
|
|
|
|
|
|
|
|
gradle.allprojects {
|
2023-10-24 23:02:59 -04:00
|
|
|
ext.getCurrentVersion = {
|
|
|
|
|
->
|
2021-01-16 20:41:47 -08:00
|
|
|
def stdout = new ByteArrayOutputStream()
|
|
|
|
|
String tagIsh
|
|
|
|
|
try {
|
2025-10-21 00:14:57 -05:00
|
|
|
project.exec {
|
2021-11-23 20:22:54 -05:00
|
|
|
commandLine 'git', 'describe', '--tags', "--match=v*"
|
2021-01-16 20:41:47 -08:00
|
|
|
standardOutput = stdout
|
|
|
|
|
}
|
|
|
|
|
tagIsh = stdout.toString().trim().toLowerCase()
|
2021-10-18 22:31:18 -04:00
|
|
|
} catch (Exception e) {
|
2021-01-16 20:41:47 -08:00
|
|
|
tagIsh = "dev-Unknown"
|
|
|
|
|
}
|
2021-11-23 20:22:54 -05:00
|
|
|
|
2021-10-07 11:13:11 -04:00
|
|
|
// Dev tags: v2021.1.6-3-gf922466d
|
|
|
|
|
// We're specifically looking to capture the middle -3-
|
2025-10-21 00:14:57 -05:00
|
|
|
boolean isDev = tagIsh.matches(".*-[0-9a-z]*-g[0-9a-f]*")
|
2021-10-18 22:31:18 -04:00
|
|
|
if (isDev && !tagIsh.startsWith("dev-")) tagIsh = "dev-" + tagIsh
|
2021-01-16 20:41:47 -08:00
|
|
|
println("Picked up version: " + tagIsh)
|
|
|
|
|
return tagIsh
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 22:31:18 -04:00
|
|
|
if (!ext.has("versionString")) {
|
2021-01-16 20:41:47 -08:00
|
|
|
ext.versionString = getCurrentVersion()
|
|
|
|
|
}
|
2021-10-18 22:31:18 -04:00
|
|
|
|
2022-01-24 12:38:45 -05:00
|
|
|
ext.writePhotonVersionFile = {File versionFileIn, Path path, String version ->
|
2021-10-18 22:31:18 -04:00
|
|
|
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()
|
2025-02-10 17:52:48 -08:00
|
|
|
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())
|
2022-01-24 12:38:45 -05:00
|
|
|
if (!versionFileOut.parentFile.exists()) versionFileOut.parentFile.mkdirs()
|
|
|
|
|
if (!versionFileOut.exists()) versionFileOut.createNewFile()
|
2021-10-18 22:31:18 -04:00
|
|
|
versionFileOut.write(read)
|
|
|
|
|
}
|
2021-01-16 20:41:47 -08:00
|
|
|
}
|