spiegel-keyman/android/version.gradle
Eberhard Beilharz 4d81589f48
maint(common): use unique names for Keyman version variables
Previously the builder scripts defined a readonly `VERSION` environment
variable for the Keyman version. That caused problems when another
(external) script tried to define a `VERSION` variable. We encountered
this problem when trying to move the TC build steps of a configuration
into a single script (#13399) when we tried to source `~/.nvm/nvm.sh`.

This change uses a Keyman specific prefix for the version variables and
renames `VERSION` → `KEYMAN_VERSION` etc. Unfortunately these variables
are used in a lot of places, so this turned out to be a bit of a yak
shave.

Test-bot: skip
2025-05-07 18:46:51 +02:00

100 lines
No EOL
3.9 KiB
Groovy

// version.gradle
//
// This depends on ext.rootPath = path to /android folder in repository
// It can be a relative path. Gradle does not appear to support relative
// paths from included scripts.
//
def getVersionCode = { ->
String env_version_major = System.getenv("KEYMAN_VERSION_MAJOR")
String env_version_minor = System.getenv("KEYMAN_VERSION_MINOR")
String env_version_patch = System.getenv("KEYMAN_VERSION_PATCH")
if(env_version_patch != null && env_version_minor != null && env_version_patch != null) {
// Version code is, for 17.1.33: 1810033. This supports up to 9999
// builds for a given major.minor version. We only support up to 9 minor
// versions for a given major version but at present we are not using
// minor versions at all.
//
// Despite this calculation, the version_code should be treated as an
// opaque integer, used only for Play Store publishing.
//
// NOTE: accidental publish of beta 17.0.6 during 16.0 beta cycle has
// forced a version_major bump, which is a permanent change. Relates to
// #7705.
Integer version_code =
(env_version_major.toInteger() + 1) * 100000 +
env_version_minor.toInteger() * 10000 +
env_version_patch.toInteger()
println "Using version code " + version_code
return version_code
}
// Probably building from IDE
println "Using fixed version code 100"
return 100
}
def getVersionMD = { ->
String env_version = System.getenv("KEYMAN_VERSION")
if (env_version != null) {
// If building from script, we have build number in KEYMAN_VERSION
println "Using build $env_version from KEYMAN_VERSION"
return "$env_version"
} else {
String version_md = file("$rootPath/../VERSION.md").text.trim()
return "$version_md"
}
}
def getVersionName = { ->
String env_version = System.getenv("KEYMAN_VERSION_WITH_TAG")
if (env_version != null) {
// If building from script, we have build number in KEYMAN_VERSION_WITH_TAG
println "Using build $env_version from KEYMAN_VERSION_WITH_TAG"
return "$env_version"
} else {
// Building probably from IDE, so let's use VERSION.md and TIER.md directly
// This is a close match with KEYMAN_VERSION_WITH_TAG, except that 'stable' tier
// is not normally included with KEYMAN_VERSION_WITH_TAG
String version_md = file("$rootPath/../VERSION.md").text.trim()
String tier_md = file("$rootPath/../TIER.md").text.trim()
println "Using build $version_md-$tier_md-local from project VERSION.md/TIER.md"
return "$version_md-$tier_md-local"
}
}
def getVersionEnvironment = { ->
String env_environment = System.getenv("KEYMAN_VERSION_ENVIRONMENT")
if (env_environment != null) {
// If building from script, we have build number in KEYMAN_VERSION_ENVIRONMENT
println "Using $env_environment from KEYMAN_VERSION_ENVIRONMENT"
return "$env_environment"
} else {
// Building probably from IDE, so use "local"
println "Using local environment"
return "local"
}
}
def getVersionGitTag = { ->
String env_git_tag = System.getenv("KEYMAN_VERSION_GIT_TAG")
if (env_git_tag != null) {
println "Using $env_git_tag from KEYMAN_VERSION_GIT_TAG"
return "$env_git_tag"
} else {
// Building probably from IDE
println "Using release@$KEYMAN_VERSION_NAME"
return "release@$KEYMAN_VERSION_NAME"
}
}
ext {
KEYMAN_VERSION_CODE=getVersionCode()
KEYMAN_VERSION_MD=getVersionMD()
KEYMAN_VERSION_NAME=getVersionName()
KEYMAN_VERSION_ENVIRONMENT=getVersionEnvironment()
KEYMAN_VERSION_TAG=System.getenv("KEYMAN_VERSION_TAG")
KEYMAN_VERSION_GIT_TAG=getVersionGitTag()
}
//println "version.gradle: KEYMAN_VERSION_TAG: " + KEYMAN_VERSION_TAG