tasks 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 | build everything"
  8. echo "$0 install | move build results into the install folder"
  9. echo "$0 test | run the tests"
  10. echo "$0 valgrind | 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. # TODO gcovr https://gcovr.com/en/5.0/guide.html
  20. task=$1
  21. if [ -z "$task" ]; then
  22. printHelpExit
  23. fi
  24. # tasks
  25. build=false
  26. test=false
  27. valgrind=false
  28. performance=false
  29. time=false
  30. install=false
  31. coverage=false
  32. profile=$(cat profile)
  33. # parsing
  34. if [ "$task" = "clean" ]; then
  35. rm -rf build install
  36. exit 0
  37. elif [ "$task" = "build" ]; then
  38. build=true
  39. elif [ "$task" = "install" ]; then
  40. build=true
  41. install=true
  42. elif [ "$task" = "coverage" ]; then
  43. build=true
  44. coverage=true
  45. test=true
  46. elif [ "$task" = "test" ]; then
  47. build=true
  48. test=true
  49. elif [ "$task" = "valgrind" ]; then
  50. build=true
  51. valgrind=true
  52. elif [ "$task" = "performance" ]; then
  53. build=true
  54. performance=true
  55. elif [ "$task" = "time" ]; then
  56. build=true
  57. time=true
  58. elif [ "$task" = "final" ]; then
  59. grep -r " class" src include | grep -v -E 'final|enum|.git' || true
  60. grep -r " struct" src include | grep -v -E 'final|enum|.git' || true
  61. exit 0
  62. elif [ "$task" = "macro" ]; then
  63. grep -r "#define" src include | grep -v " CORE" || true
  64. exit 0
  65. elif [ "$task" = "include" ]; then
  66. echo "System includes in header files:"
  67. grep -r "#include <" src include | grep "\.hpp" || true
  68. echo "-------------------------------------------------"
  69. echo "System includes in source files:"
  70. grep -r "#include <" src include | grep "\.cpp" || true
  71. exit 0
  72. else
  73. echo "unknown task"
  74. printHelpExit
  75. fi
  76. # task execution
  77. if $build; then
  78. if [ ! -e build ]; then
  79. cmake -B build -S . -G Ninja -DCMAKE_INSTALL_PREFIX=./install \
  80. -DCMAKE_BUILD_TYPE=$profile
  81. fi
  82. ninja -C build
  83. fi
  84. if $install; then
  85. ninja -C build install
  86. fi
  87. if $test; then
  88. cd build
  89. ./test light || true
  90. cd ..
  91. fi
  92. if $valgrind; then
  93. cd build
  94. valgrind ./test light valgrind || true
  95. cd ..
  96. fi
  97. if $performance; then
  98. cd build
  99. ./performance
  100. fi
  101. if $time; then
  102. lines=$(cat build/.ninja_log | grep "^[0-9]")
  103. startMillis=0
  104. endMillis=0
  105. name=""
  106. i=0
  107. output=""
  108. for arg in $lines; do
  109. if [ $i == 0 ]; then
  110. startMillis=$arg
  111. elif [ $i == 1 ]; then
  112. endMillis=$arg
  113. elif [ $i == 3 ]; then
  114. name=$arg
  115. diff=$(expr $endMillis - $startMillis)
  116. output="${output}\n$diff $name"
  117. fi
  118. i=$(expr $(expr $i + 1) % 5) && true
  119. done
  120. printf "$output" | sort -n
  121. fi
  122. if $coverage; then
  123. gcovr -r . build -e test -e performance
  124. fi