1
0
Fork 0
tt9/gradle/scripts/version-tools.gradle
Dimo Karaivanov 44ecb8999e
Build scripts cleanup and dictionary loading optimization
* moved the source languages out of assets/ into their own directory (#356)
  
  * split build.gradle into several smaller files

  * improved word frequency validation during build time

  * slightly optimized dictionary loading speed using pre-calculated file size

  * fixed a potential crash when loading invalid assets

  * fixed dictionary loading progress starting at 100% then jumping to 0% when manually loading two dictionaries one after another

  * documentation update
2023-08-21 15:29:30 +03:00

62 lines
1.7 KiB
Groovy

def execThing (String cmdStr) {
def stdout = new ByteArrayOutputStream()
String prefix = System.getenv("GITCMDPREFIX")
if (prefix != null) {
String cmd = prefix + cmdStr
exec {
commandLine cmd.tokenize()
standardOutput = stdout
}
} else {
exec {
commandLine cmdStr.tokenize()
standardOutput = stdout
}
}
return stdout.toString().trim()
}
def getCurrentGitHash() {
return execThing('git log -1 --format=%h')
}
def generateVersionName() {
// major version
String versionTagsRaw = execThing('git tag --list v[0-9]*')
int versionTagsCount = versionTagsRaw == "" ? 0 : versionTagsRaw.split('\n').size()
// minor version
String commitsSinceLastTag = "0"
if (versionTagsCount > 1) {
String lastVersionTag = execThing('git describe --match v[0-9]* --tags --abbrev=0')
String gitLogResult = execThing("git log $lastVersionTag..HEAD --oneline")
commitsSinceLastTag = gitLogResult == '' ? "0" : gitLogResult.split('\n').size()
}
// the commit we are building from
// beta string, if this is a beta
String lastTagName = (execThing('git tag --list') == "") ? "" : execThing('git describe --tags --abbrev=0')
String lastTagHash = (lastTagName == "") ? "" : execThing("git log -1 --format=%h $lastTagName")
String betaString = lastTagHash == getCurrentGitHash() && lastTagName.contains("-beta") ? '-beta' : ''
return "$versionTagsCount.$commitsSinceLastTag$betaString"
}
ext.getVersionName = { ->
return generateVersionName()
}
ext.getVersionCode = { ->
String commitsCount = execThing("git rev-list --count HEAD")
return Integer.valueOf(commitsCount)
}
ext.getDebugVersion = { ->
return "git-${getCurrentGitHash()} (debug)"
}
ext.getReleaseVersion = { ->
return "${generateVersionName()} (${getCurrentGitHash()})"
}