tasks 4.5 KB

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