Simplify build flags setup with distribution profile
This commit is contained in:
@@ -8,8 +8,31 @@ interface BuildConfig {
|
||||
val includeDependencyInfo: Boolean
|
||||
}
|
||||
|
||||
val Project.Config: BuildConfig get() = object : BuildConfig {
|
||||
override val includeTelemetry: Boolean = project.hasProperty("include-telemetry")
|
||||
override val enableUpdater: Boolean = project.hasProperty("enable-updater")
|
||||
override val includeDependencyInfo: Boolean = project.hasProperty("include-dependency-info")
|
||||
private enum class Distribution {
|
||||
LOCAL,
|
||||
CI,
|
||||
GITHUB,
|
||||
FOSS,
|
||||
}
|
||||
|
||||
val Project.Config: BuildConfig get() = object : BuildConfig {
|
||||
private val distribution: Distribution = project.providers.gradleProperty("dist").orNull
|
||||
?.let { name ->
|
||||
Distribution.entries.firstOrNull { it.name.equals(name, ignoreCase = true) }
|
||||
?: error("Unknown -Pdist=$name, expected one of $distributionNames")
|
||||
}
|
||||
?: Distribution.LOCAL
|
||||
|
||||
override val includeTelemetry: Boolean = project.flag("include-telemetry")
|
||||
?: (distribution == Distribution.CI || distribution == Distribution.GITHUB)
|
||||
|
||||
override val enableUpdater: Boolean = project.flag("enable-updater")
|
||||
?: (distribution != Distribution.LOCAL)
|
||||
|
||||
override val includeDependencyInfo: Boolean = project.flag("include-dependency-info") ?: false
|
||||
}
|
||||
|
||||
private val distributionNames = Distribution.entries.joinToString { it.name.lowercase() }
|
||||
|
||||
private fun Project.flag(name: String): Boolean? = providers.gradleProperty(name).orNull
|
||||
?.let { it.isEmpty() || it.toBoolean() }
|
||||
|
||||
Reference in New Issue
Block a user