build.gradle.kts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // Copyright (c) 2008-2020 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. import org.gradle.internal.io.NullOutputStream
  23. import java.io.ByteArrayOutputStream
  24. buildscript {
  25. extra["kotlinVersion"] = "1.4.10"
  26. val kotlinVersion: String by extra
  27. repositories {
  28. google()
  29. jcenter()
  30. }
  31. dependencies {
  32. classpath("com.android.tools.build:gradle:4.0.2")
  33. classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
  34. }
  35. }
  36. plugins {
  37. id("com.jfrog.bintray") version "1.8.5" apply false
  38. }
  39. val kotlinVersion: String by ext
  40. allprojects {
  41. group = "io.urho3d"
  42. version = determineVersion()
  43. description = """
  44. Urho3D is a free lightweight, cross-platform 2D and 3D game engine implemented in C++ and
  45. released under the MIT license. Greatly inspired by OGRE and Horde3D.
  46. """.trimIndent().replace('\n', ' ')
  47. repositories {
  48. google()
  49. jcenter()
  50. }
  51. buildscript {
  52. ext {
  53. set("kotlinVersion", kotlinVersion)
  54. set("ndkSideBySideVersion", "21.3.6528147")
  55. set("cmakeVersion", "3.17.3+")
  56. set("buildStagingDir", ".cxx")
  57. }
  58. }
  59. }
  60. tasks {
  61. wrapper {
  62. distributionType = Wrapper.DistributionType.ALL
  63. }
  64. "prepareKotlinBuildScriptModel" {
  65. listOf("Debug", "Release").forEach {
  66. dependsOn(":android:urho3d-lib:generateJsonModel$it")
  67. }
  68. }
  69. register<Delete>("clean") {
  70. // Clean the build artifacts generated by the Gradle build system only, but keep the buildDir
  71. rootProject.buildDir.listFiles { _, name -> name == "intermediates" || name == "kotlin" }?.let {
  72. delete = it.toSet()
  73. }
  74. }
  75. register<Delete>("cleanAll") {
  76. dependsOn("clean")
  77. }
  78. register("aarVersion") {
  79. doLast {
  80. println("AAR version: ${determineVersion()}")
  81. }
  82. }
  83. }
  84. /**
  85. * Find the most recent tag that is reachable from a commit and use that to set the Gradle's project version.
  86. *
  87. * e.g. commit described as "1.7-664-g34b1" will be mapped to "1.8-SNAPSHOT", (development snapshot for next version)
  88. * tag "1.8" will be mapped to "1.8" as is (point release version), so does tag "1.8-RC" (release candidate)
  89. */
  90. fun determineVersion(): String {
  91. // If it is explicitly specified then use the specified version instead
  92. System.getenv("GRADLE_PROJECT_VERSION")?.let { return it }
  93. val desc = describeCommit()
  94. return Regex("^(.+?)-\\d").find(desc)?.destructured?.component1()?.let { "${bumpSemVer(it, 1)}-SNAPSHOT" } ?: desc
  95. }
  96. /**
  97. * Find the most recent tag that is reachable from a commit.
  98. */
  99. fun describeCommit(sha: String? = null) = ByteArrayOutputStream().also {
  100. exec {
  101. commandLine = listOf("git", "describe", "--tags", sha ?: "--dirty")
  102. standardOutput = it
  103. errorOutput = NullOutputStream.INSTANCE
  104. isIgnoreExitValue = true // In case no GIT command line tool or not a GIT repository
  105. }
  106. }.toString().trim().let { if (it.isBlank()) "Unversioned" else it }
  107. /**
  108. * Bump the semantic versioning on the specified index, 0 for major version, 1 for minor version, and so on.
  109. */
  110. fun bumpSemVer(version: String, index: Int) = version
  111. .split('.')
  112. .mapIndexed { i: Int, s: String ->
  113. when {
  114. i < index -> s
  115. i == index -> if (s.contains('-')) s else (s.toInt() + 1).toString()
  116. else -> "0"
  117. }
  118. }
  119. .joinToString(".")