tasks 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #!/bin/bash
  2. set -e
  3. clear
  4. cd $(dirname $0)
  5. compiler="g++"
  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 performance | run the performance tests"
  18. echo "$0 final | find classes / structs which are not final"
  19. echo "$0 macro | find macros without CORE"
  20. echo "$0 include | find system includes"
  21. echo "$0 time | check build time"
  22. exit 0
  23. }
  24. task=$1
  25. if [ -z "$task" ]; then
  26. printHelpExit
  27. fi
  28. # task vars
  29. build_debug=false
  30. build_release=false
  31. test_debug=false
  32. test_release=false
  33. valgrind=""
  34. performance=false
  35. time=false
  36. install=false
  37. coverage=false
  38. export CMAKE_EXPORT_COMPILE_COMMANDS=true
  39. # parsing
  40. if [ "$task" = "clean" ]; then
  41. rm -rf build_debug build_release install
  42. elif [ "$task" = "build" ]; then
  43. type=$2
  44. if [ "$type" = "debug" ]; then
  45. build_debug=true
  46. elif [ "$type" = "release" ]; then
  47. build_release=true
  48. elif [ "$type" = "all" ]; then
  49. build_debug=true
  50. build_release=true
  51. else
  52. echo "Valid build types are: debug, release, all"
  53. printHelpExit
  54. fi
  55. elif [ "$task" = "install" ]; then
  56. build_release=true
  57. install=true
  58. elif [ "$task" = "coverage" ]; then
  59. build_debug=true
  60. test_debug=true
  61. coverage=true
  62. elif [ "$task" = "test" ]; then
  63. type=$2
  64. if [ "$type" = "debug" ]; then
  65. build_debug=true
  66. test_debug=true
  67. elif [ "$type" = "release" ]; then
  68. build_release=true
  69. test_release=true
  70. elif [ "$type" = "all" ]; then
  71. build_debug=true
  72. test_debug=true
  73. build_release=true
  74. test_release=true
  75. else
  76. echo "Valid test types are: debug, release, all"
  77. printHelpExit
  78. fi
  79. elif [ "$task" = "valgrind" ]; then
  80. type=$2
  81. if [ "$type" = "debug" ]; then
  82. build_debug=true
  83. test_debug=true
  84. elif [ "$type" = "release" ]; then
  85. build_release=true
  86. test_release=true
  87. elif [ "$type" = "all" ]; then
  88. build_debug=true
  89. test_debug=true
  90. build_release=true
  91. test_release=true
  92. else
  93. echo "Valid valgrind types are: debug, release, all"
  94. printHelpExit
  95. fi
  96. valgrind="valgrind"
  97. elif [ "$task" = "performance" ]; then
  98. build_release=true
  99. performance=true
  100. elif [ "$task" = "time" ]; then
  101. build_release=true
  102. time=true
  103. elif [ "$task" = "final" ]; then
  104. grep -r " class" src include | grep -v -E 'final|enum|.git' || true
  105. grep -r " struct" src include | grep -v -E 'final|enum|.git' || true
  106. exit 0
  107. elif [ "$task" = "macro" ]; then
  108. grep -r "#define" src include | grep -v " CORE" || true
  109. exit 0
  110. elif [ "$task" = "include" ]; then
  111. echo "System includes in header files:"
  112. grep -r "#include <" src include | grep "\.hpp" || true
  113. echo "-------------------------------------------------"
  114. echo "System includes in source files:"
  115. grep -r "#include <" src include | grep "\.cpp" || true
  116. exit 0
  117. else
  118. echo "unknown task"
  119. printHelpExit
  120. fi
  121. # task execution
  122. buildProfile() {
  123. folder=$1
  124. shift 1
  125. if [ ! -e "$folder" ]; then
  126. cmake -B "$folder" -S . -G Ninja -DCMAKE_CXX_COMPILER=${compiler} -DCMAKE_INSTALL_PREFIX=./install $@
  127. fi
  128. ninja -C "$folder"
  129. }
  130. if $build_debug; then
  131. buildProfile build_debug -DCMAKE_BUILD_TYPE=Debug
  132. fi
  133. if $build_release; then
  134. buildProfile build_release -DCMAKE_BUILD_TYPE=Release
  135. fi
  136. if $install; then
  137. ninja -C build_release install
  138. fi
  139. if $test_debug; then
  140. cd build_debug
  141. $valgrind ./test light $valgrind || true
  142. cd ..
  143. fi
  144. if $test_release; then
  145. cd build_release
  146. $valgrind ./test light $valgrind || true
  147. cd ..
  148. fi
  149. if $performance; then
  150. cd build_release
  151. ./performance
  152. cd ..
  153. fi
  154. if $time; then
  155. lines=$(cat build_release/.ninja_log | grep "^[0-9]")
  156. startMillis=0
  157. endMillis=0
  158. name=""
  159. i=0
  160. output=""
  161. for arg in $lines; do
  162. if [ $i == 0 ]; then
  163. startMillis=$arg
  164. elif [ $i == 1 ]; then
  165. endMillis=$arg
  166. elif [ $i == 3 ]; then
  167. name=$arg
  168. diff=$(expr $endMillis - $startMillis)
  169. output="${output}\n$diff $name"
  170. fi
  171. i=$(expr $(expr $i + 1) % 5) && true
  172. done
  173. printf "$output" | sort -n
  174. fi
  175. if $coverage; then
  176. gcovr -r . build_debug -e test -e performance \
  177. --exclude-lines-by-pattern ".*CoverageIgnore.*"
  178. fi