build.gradle.kts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright (c) 2008-2022 the Urho3D project
  2. // License: MIT
  3. import org.gradle.internal.io.NullOutputStream
  4. import java.io.ByteArrayOutputStream
  5. buildscript {
  6. extra["kotlinVersion"] = "1.4.10"
  7. val kotlinVersion: String by extra
  8. repositories {
  9. google()
  10. mavenCentral()
  11. }
  12. dependencies {
  13. classpath("com.android.tools.build:gradle:4.2.0+")
  14. classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
  15. }
  16. }
  17. plugins {
  18. id("com.jfrog.bintray") version "1.8.5" apply false
  19. }
  20. val kotlinVersion: String by ext
  21. allprojects {
  22. group = "io.urho3d"
  23. version = determineVersion()
  24. description = """
  25. Urho3D is a free lightweight, cross-platform 2D and 3D game engine implemented in C++ and
  26. released under the MIT license. Greatly inspired by OGRE and Horde3D.
  27. """.trimIndent().replace('\n', ' ')
  28. repositories {
  29. google()
  30. mavenCentral()
  31. }
  32. buildscript {
  33. ext {
  34. set("kotlinVersion", kotlinVersion)
  35. set("ndkSideBySideVersion", "21.3.6528147")
  36. set("cmakeVersion", "3.17.3+")
  37. set("buildStagingDir", ".cxx")
  38. }
  39. }
  40. }
  41. tasks {
  42. wrapper {
  43. distributionType = Wrapper.DistributionType.ALL
  44. }
  45. "prepareKotlinBuildScriptModel" {
  46. listOf("Debug", "Release").forEach {
  47. dependsOn(":android:urho3d-lib:generateJsonModel$it")
  48. }
  49. }
  50. register<Delete>("clean") {
  51. // Clean the build artifacts generated by the Gradle build system only, but keep the buildDir
  52. rootProject.buildDir.listFiles { _, name -> name == "intermediates" || name == "kotlin" }?.let {
  53. delete = it.toSet()
  54. }
  55. }
  56. register<Delete>("cleanAll") {
  57. dependsOn("clean")
  58. }
  59. register("aarVersion") {
  60. doLast {
  61. println("AAR version: ${determineVersion()}")
  62. }
  63. }
  64. }
  65. /**
  66. * Find the most recent tag that is reachable from a commit and use that to set the Gradle's project version.
  67. *
  68. * e.g. commit described as "1.7-664-g34b1" will be mapped to "1.8-SNAPSHOT", (development snapshot for next version)
  69. * tag "1.8" will be mapped to "1.8" as is (point release version), so does tag "1.8-RC" (release candidate)
  70. */
  71. fun determineVersion(): String {
  72. // If it is explicitly specified then use the specified version instead
  73. System.getenv("GRADLE_PROJECT_VERSION")?.let { return it }
  74. val desc = describeCommit()
  75. return Regex("^(.+?)-\\d").find(desc)?.destructured?.component1()?.let { "${bumpSemVer(it, 1)}-SNAPSHOT" } ?: desc
  76. }
  77. /**
  78. * Find the most recent tag that is reachable from a commit.
  79. */
  80. fun describeCommit(sha: String? = null) = ByteArrayOutputStream().also {
  81. exec {
  82. commandLine = listOf("git", "describe", "--tags", sha ?: "--dirty")
  83. standardOutput = it
  84. errorOutput = NullOutputStream.INSTANCE
  85. isIgnoreExitValue = true // In case no GIT command line tool or not a GIT repository
  86. }
  87. }.toString().trim().let { if (it.isBlank()) "Unversioned" else it }
  88. /**
  89. * Bump the semantic versioning on the specified index, 0 for major version, 1 for minor version, and so on.
  90. */
  91. fun bumpSemVer(version: String, index: Int) = version
  92. .split('.')
  93. .mapIndexed { i: Int, s: String ->
  94. when {
  95. i < index -> s
  96. i == index -> if (s.contains('-')) s else (s.toInt() + 1).toString()
  97. else -> "0"
  98. }
  99. }
  100. .joinToString(".")