ci_generate.nim 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. ##[
  2. avoid code duplication in CI pipelines.
  3. For now, this is only used for openbsd + freebsd, but there is a lot of other code
  4. duplication that could be removed.
  5. ## usage
  6. edit this file as needed and then re-generate via:
  7. ```
  8. nim r tools/ci_generate.nim
  9. ```
  10. ]##
  11. import std/[strformat, os]
  12. const doNotEdit = "DO NO EDIT DIRECTLY! auto-generated by `nim r tools/ci_generate.nim`"
  13. proc genCiBsd(header: string, batch: int, num: int): string =
  14. result = fmt"""
  15. ## {doNotEdit}
  16. {header}
  17. sources:
  18. - https://github.com/nim-lang/Nim
  19. environment:
  20. NIM_TESTAMENT_BATCH: "{batch}_{num}"
  21. CC: /usr/bin/clang
  22. tasks:
  23. - setup: |
  24. set -e
  25. cd Nim
  26. . ci/funs.sh && nimBuildCsourcesIfNeeded
  27. $nim_csources c --skipUserCfg --skipParentCfg koch
  28. echo 'export PATH=$HOME/Nim/bin:$PATH' >> $HOME/.buildenv
  29. - test: |
  30. set -e
  31. cd Nim
  32. if ! ./koch runCI; then
  33. nim r tools/ci_testresults.nim
  34. exit 1
  35. fi
  36. triggers:
  37. - action: email
  38. condition: failure
  39. to: Andreas Rumpf <rumpf_a@web.de>
  40. """
  41. proc genBuildExtras(echoRun, koch, nim: string): string =
  42. result = fmt"""
  43. {echoRun} {nim} c --skipUserCfg --skipParentCfg --hints:off koch
  44. {echoRun} {koch} boot -d:release --skipUserCfg --skipParentCfg --hints:off
  45. {echoRun} {koch} tools --skipUserCfg --skipParentCfg --hints:off
  46. """
  47. proc genWindowsScript(buildAll: bool): string =
  48. result = fmt"""
  49. @echo off
  50. rem {doNotEdit}
  51. rem Build development version of the compiler; can be rerun safely
  52. rem bare bones version of ci/funs.sh adapted for windows.
  53. rem Read in some common shared variables (shared with other tools),
  54. rem see https://stackoverflow.com/questions/3068929/how-to-read-file-contents-into-a-variable-in-a-batch-file
  55. for /f "delims== tokens=1,2" %%G in (config/build_config.txt) do set %%G=%%H
  56. SET nim_csources=bin\nim_csources_%nim_csourcesHash%.exe
  57. echo "building from csources: %nim_csources%"
  58. if not exist %nim_csourcesDir% (
  59. git clone -q --depth 1 %nim_csourcesUrl% %nim_csourcesDir%
  60. )
  61. if not exist %nim_csources% (
  62. cd %nim_csourcesDir%
  63. git checkout %nim_csourcesHash%
  64. echo "%PROCESSOR_ARCHITECTURE%"
  65. if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
  66. SET ARCH=64
  67. )
  68. CALL build.bat
  69. cd ..
  70. copy /y bin\nim.exe %nim_csources%
  71. )
  72. """
  73. if buildAll:
  74. result.add genBuildExtras("", "koch", r"bin\nim.exe")
  75. proc genPosixScript(): string =
  76. result = fmt"""
  77. #! /bin/sh
  78. rem {doNotEdit}
  79. # build development version of the compiler; can be rerun safely.
  80. # arguments can be passed, e.g.:
  81. # CC=gcc ucpu=amd64 uos=darwin
  82. set -u # error on undefined variables
  83. set -e # exit on first error
  84. . ci/funs.sh
  85. nimBuildCsourcesIfNeeded "$@"
  86. {genBuildExtras("echo_run", "./koch", "bin/nim")}
  87. """
  88. proc main()=
  89. let dir = ".builds"
  90. # not too large to be resource friendly, refs bug #17107
  91. let num = 2
  92. # if you reduce this, make sure to remove files that shouldn't be generated,
  93. # or better, do the cleanup logic here e.g.: `rm .builds/openbsd_*`
  94. let headerFreebsd = """
  95. # see https://man.sr.ht/builds.sr.ht/compatibility.md#freebsd
  96. image: freebsd/latest
  97. packages:
  98. - databases/sqlite3
  99. - devel/boehm-gc-threaded
  100. - devel/pcre
  101. - devel/sdl20
  102. - devel/sfml
  103. - www/node
  104. - devel/gmake
  105. """
  106. let headerOpenbsd = """
  107. image: openbsd/latest
  108. packages:
  109. - gmake
  110. - sqlite3
  111. - node
  112. - boehm-gc
  113. - pcre
  114. - sfml
  115. - sdl2
  116. - libffi
  117. """
  118. for i in 0..<num:
  119. writeFile(dir / fmt"openbsd_{i}.yml", genCiBsd(headerOpenbsd, i, num))
  120. writeFile(dir / "freebsd.yml", genCiBsd(headerFreebsd, 0, 1))
  121. writeFile("build_all.sh", genPosixScript())
  122. writeFile("build_all.bat", genWindowsScript(buildAll = true))
  123. writeFile("ci/build_autogen.bat", genWindowsScript(buildAll = false))
  124. when isMainModule:
  125. main()