tasks 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #!/bin/bash
  2. set -e
  3. clear
  4. cd $(dirname $0)
  5. compiler="gcc"
  6. if [ -e compiler ]; then
  7. compiler=$(cat compiler)
  8. echo "compiling with $compiler"
  9. fi
  10. printHelpExit() {
  11. echo "$0 clean | remove build results"
  12. echo "$0 build <type> | build everything"
  13. echo "$0 install | move build results into the install folder"
  14. echo "$0 test <type> | run the tests"
  15. echo "$0 valgrind <type> | run the tests with valgrind"
  16. echo "$0 coverage | generate code coverage"
  17. echo "$0 time | check build time"
  18. exit 0
  19. }
  20. task=$1
  21. if [ -z "$task" ]; then
  22. printHelpExit
  23. fi
  24. # task vars
  25. build_debug=false
  26. build_profile=false
  27. build_release=false
  28. test_debug=false
  29. test_release=false
  30. valgrind=""
  31. time=false
  32. install=false
  33. coverage=false
  34. testArgs="test"
  35. export CMAKE_EXPORT_COMPILE_COMMANDS=true
  36. # parsing
  37. if [ "$task" = "clean" ]; then
  38. rm -rf build_debug build_profile build_release install
  39. elif [ "$task" = "build" ]; then
  40. type=$2
  41. if [ "$type" = "debug" ]; then
  42. build_debug=true
  43. elif [ "$type" = "release" ]; then
  44. build_release=true
  45. elif [ "$type" = "all" ]; then
  46. build_debug=true
  47. build_release=true
  48. else
  49. echo "Valid build types are: debug, release, all"
  50. printHelpExit
  51. fi
  52. elif [ "$task" = "install" ]; then
  53. build_release=true
  54. install=true
  55. elif [ "$task" = "coverage" ]; then
  56. build_debug=true
  57. test_debug=true
  58. coverage=true
  59. elif [ "$task" = "test" ]; then
  60. type=$2
  61. if [ "$type" = "debug" ]; then
  62. build_debug=true
  63. test_debug=true
  64. elif [ "$type" = "release" ]; then
  65. build_release=true
  66. test_release=true
  67. elif [ "$type" = "window" ]; then
  68. build_debug=true
  69. test_debug=true
  70. testArgs="window"
  71. elif [ "$type" = "all" ]; then
  72. build_debug=true
  73. test_debug=true
  74. build_release=true
  75. test_release=true
  76. else
  77. echo "Valid test types are: debug, release, window, all"
  78. printHelpExit
  79. fi
  80. elif [ "$task" = "valgrind" ]; then
  81. type=$2
  82. if [ "$type" = "debug" ]; then
  83. build_debug=true
  84. test_debug=true
  85. elif [ "$type" = "release" ]; then
  86. build_release=true
  87. test_release=true
  88. elif [ "$type" = "window" ]; then
  89. build_debug=true
  90. test_debug=true
  91. testArgs="window"
  92. elif [ "$type" = "all" ]; then
  93. build_debug=true
  94. test_debug=true
  95. build_release=true
  96. test_release=true
  97. else
  98. echo "Valid valgrind types are: debug, release, window, all"
  99. printHelpExit
  100. fi
  101. valgrind="valgrind \
  102. --leak-check=full \
  103. --show-leak-kinds=all \
  104. --suppressions=../valgrind.supp
  105. "
  106. elif [ "$task" = "time" ]; then
  107. build_release=true
  108. time=true
  109. else
  110. echo "unknown task"
  111. printHelpExit
  112. fi
  113. # task execution
  114. buildProfile() {
  115. folder=$1
  116. shift 1
  117. if [ ! -e "$folder" ]; then
  118. cmake -B "$folder" -S . -G Ninja -DCMAKE_C_COMPILER=${compiler} -DCMAKE_INSTALL_PREFIX=../install $@
  119. fi
  120. ninja -C "$folder"
  121. }
  122. if $build_debug; then
  123. buildProfile build_debug -DCMAKE_BUILD_TYPE=Debug
  124. fi
  125. if $build_profile; then
  126. buildProfile build_profile -DCMAKE_BUILD_TYPE=RelWithDebInfo
  127. fi
  128. if $build_release; then
  129. buildProfile build_release -DCMAKE_BUILD_TYPE=Release
  130. fi
  131. if $install; then
  132. ninja -C build_release install
  133. fi
  134. function runTests() {
  135. LLVM_PROFILE_FILE="default.profraw" $valgrind ./test ../test/resources $testArgs || true
  136. }
  137. if $test_debug; then
  138. cd build_debug
  139. runTests
  140. cd ..
  141. fi
  142. if $test_release; then
  143. cd build_release
  144. runTests
  145. cd ..
  146. fi
  147. if $time; then
  148. lines=$(cat build_release/.ninja_log | grep "^[0-9]")
  149. startMillis=0
  150. endMillis=0
  151. name=""
  152. i=0
  153. output=""
  154. for arg in $lines; do
  155. if [ $i == 0 ]; then
  156. startMillis=$arg
  157. elif [ $i == 1 ]; then
  158. endMillis=$arg
  159. elif [ $i == 3 ]; then
  160. name=$arg
  161. diff=$(expr $endMillis - $startMillis)
  162. output="${output}\n$diff $name"
  163. fi
  164. i=$(expr $(expr $i + 1) % 5) && true
  165. done
  166. printf "$output" | sort -n
  167. fi
  168. if $coverage; then
  169. if [ $compiler = "gcc" ]; then
  170. gcovr -r . build_debug -e test -e performance \
  171. --exclude-lines-by-pattern ".*CoverageIgnore.*"
  172. else
  173. files=$(find build_debug -name *.profraw)
  174. llvm-profdata-17 merge -sparse $files -o build_debug/default.profdata
  175. llvm-cov-17 show ./build_debug/test -instr-profile=build_debug/default.profdata --ignore-filename-regex="(test/)|(WindowManager.c)" -line-coverage-lt=100
  176. fi
  177. fi