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_test_release=true
  45. build_release=true
  46. else
  47. echo "Valid build types are: debug, release, all"
  48. printHelpExit
  49. fi
  50. elif [ "$task" = "install" ]; then
  51. build_release=true
  52. install=true
  53. elif [ "$task" = "coverage" ]; then
  54. build_debug=true
  55. test_debug=true
  56. coverage=true
  57. elif [ "$task" = "test" ]; then
  58. type=$2
  59. if [ "$type" = "debug" ]; then
  60. build_debug=true
  61. test_debug=true
  62. elif [ "$type" = "release" ]; then
  63. build_test_release=true
  64. test_release=true
  65. elif [ "$type" = "all" ]; then
  66. build_debug=true
  67. test_debug=true
  68. build_test_release=true
  69. test_release=true
  70. else
  71. echo "Valid test types are: debug, release, all"
  72. printHelpExit
  73. fi
  74. elif [ "$task" = "valgrind" ]; then
  75. type=$2
  76. if [ "$type" = "debug" ]; then
  77. build_debug=true
  78. test_debug=true
  79. elif [ "$type" = "release" ]; then
  80. build_test_release=true
  81. test_release=true
  82. elif [ "$type" = "all" ]; then
  83. build_debug=true
  84. test_debug=true
  85. build_test_release=true
  86. test_release=true
  87. else
  88. echo "Valid valgrind types are: debug, release, all"
  89. printHelpExit
  90. fi
  91. valgrind="valgrind"
  92. elif [ "$task" = "performance" ]; then
  93. build_release=true
  94. performance=true
  95. elif [ "$task" = "time" ]; then
  96. build_release=true
  97. time=true
  98. elif [ "$task" = "final" ]; then
  99. grep -r " class" src include | grep -v -E 'final|enum|.git' || true
  100. grep -r " struct" src include | grep -v -E 'final|enum|.git' || true
  101. exit 0
  102. elif [ "$task" = "macro" ]; then
  103. grep -r "#define" src include | grep -v " CORE" || true
  104. exit 0
  105. elif [ "$task" = "include" ]; then
  106. echo "System includes in header files:"
  107. grep -r "#include <" src include | grep "\.hpp" || true
  108. echo "-------------------------------------------------"
  109. echo "System includes in source files:"
  110. grep -r "#include <" src include | grep "\.cpp" || true
  111. exit 0
  112. else
  113. echo "unknown task"
  114. printHelpExit
  115. fi
  116. # task execution
  117. buildProfile() {
  118. folder=$1
  119. shift 1
  120. if [ ! -e "$folder" ]; then
  121. cmake -B "$folder" -S . -G Ninja -DCMAKE_INSTALL_PREFIX=./install $@
  122. fi
  123. ninja -C "$folder"
  124. }
  125. if $build_debug; then
  126. buildProfile build_debug -DCMAKE_BUILD_TYPE=Debug
  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. if $test_debug; then
  135. cd build_debug
  136. $valgrind ./test light $valgrind || true
  137. cd ..
  138. fi
  139. if $test_release; then
  140. cd build_release
  141. $valgrind ./test light $valgrind || true
  142. cd ..
  143. fi
  144. if $performance; then
  145. cd build_release
  146. ./performance
  147. cd ..
  148. fi
  149. if $time; then
  150. lines=$(cat build_release/.ninja_log | grep "^[0-9]")
  151. startMillis=0
  152. endMillis=0
  153. name=""
  154. i=0
  155. output=""
  156. for arg in $lines; do
  157. if [ $i == 0 ]; then
  158. startMillis=$arg
  159. elif [ $i == 1 ]; then
  160. endMillis=$arg
  161. elif [ $i == 3 ]; then
  162. name=$arg
  163. diff=$(expr $endMillis - $startMillis)
  164. output="${output}\n$diff $name"
  165. fi
  166. i=$(expr $(expr $i + 1) % 5) && true
  167. done
  168. printf "$output" | sort -n
  169. fi
  170. if $coverage; then
  171. gcovr -r . build_debug -e test -e performance
  172. fi