generate-build-native.ws.kts 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright 2019-2022 Mamoe Technologies and contributors.
  3. *
  4. * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
  5. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  6. *
  7. * https://github.com/mamoe/mirai/blob/dev/LICENSE
  8. */
  9. val env = "\${{ env.gradleArgs }}"
  10. val isUbunutu = "\${{ env.isUbuntu == 'true' }}"
  11. val isWindows = "\${{ env.isWindows == 'true' }}"
  12. val isMac = "\${{ env.isMac == 'true' }}"
  13. val template = """
  14. - if: CONDITION
  15. name: "Compile mirai-core-api for macosArm64"
  16. run: ./gradlew :mirai-core-api:compileKotlinMacosArm64 :mirai-core-api:compileTestKotlinMacosArm64 $env
  17. - if: CONDITION
  18. name: "Link mirai-core-api for macosArm64"
  19. run: ./gradlew mirai-core-api:linkDebugTestMacosArm64 $env
  20. - if: CONDITION
  21. name: "Test mirai-core-api for macosArm64"
  22. run: ./gradlew :mirai-core-api:macosArm64Test $env
  23. """.trimIndent()
  24. val output = buildString {
  25. val title = "############# GENERATED FROM generate-build-native.ws.kts #############"
  26. appendLine("#".repeat(title.length))
  27. appendLine(title)
  28. appendLine("#".repeat(title.length))
  29. appendLine()
  30. listOf("mirai-core-utils", "mirai-core-api", "mirai-core").forEach { moduleName ->
  31. appendLine(
  32. """
  33. - name: "Commonize mirai-core-api"
  34. run: ./gradlew :mirai-core-api:commonize $env
  35. """.trimIndent().replace("mirai-core-api", moduleName)
  36. )
  37. appendLine()
  38. }
  39. listOf("mirai-core-utils", "mirai-core-api", "mirai-core").forEach { moduleName ->
  40. appendLine("# $moduleName")
  41. appendLine()
  42. appendLine(
  43. """
  44. - name: "Compile mirai-core-api for common"
  45. run: ./gradlew :mirai-core-api:compileCommonMainKotlinMetadata $env
  46. - name: "Compile mirai-core-api for native"
  47. run: ./gradlew :mirai-core-api:compileNativeMainKotlinMetadata $env
  48. - name: "Compile mirai-core-api for unix-like"
  49. run: ./gradlew :mirai-core-api:compileUnixMainKotlinMetadata $env
  50. """.trimIndent().replace("mirai-core-api", moduleName)
  51. )
  52. appendLine()
  53. listOf("macosX64" to isMac, "mingwX64" to isWindows, "linuxX64" to isUbunutu).forEach { (target, condition) ->
  54. appendLine(useTemplate(moduleName, target, condition))
  55. appendLine()
  56. appendLine()
  57. }
  58. appendLine()
  59. }
  60. this.trimEnd().let { c -> clear().appendLine(c) } // remove trailing empty lines
  61. appendLine()
  62. appendLine("#".repeat(title.length))
  63. }
  64. println(output.prependIndent(" ".repeat(6)))
  65. fun useTemplate(moduleName: String, target: String, condition: String) = template
  66. .replace("mirai-core-api", moduleName)
  67. .replace("macosArm64", target)
  68. .replace("MacosArm64", target.replaceFirstChar { it.uppercaseChar() })
  69. .replace("CONDITION", condition)
  70. // Link release artifacts to save memory
  71. .replace("linkDebugTestMingwX64", "linkReleaseTestMingwX64")