tasks 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 coverage | generate code coverage"
  11. echo "$0 performance | run the performance tests"
  12. echo "$0 final | find classes / structs which are not final"
  13. echo "$0 macro | find macros without CORE"
  14. echo "$0 include | find system includes in header files"
  15. echo "$0 time | check build time"
  16. exit 0
  17. }
  18. # TODO gcovr https://gcovr.com/en/5.0/guide.html
  19. task=$1
  20. if [ -z "$task" ]; then
  21. printHelpExit
  22. fi
  23. # tasks
  24. build=false
  25. test=false
  26. performance=false
  27. time=false
  28. install=false
  29. coverage=false
  30. # parsing
  31. if [ "$task" = "clean" ]; then
  32. rm -rf build install
  33. exit 0
  34. elif [ "$task" = "build" ]; then
  35. build=true
  36. elif [ "$task" = "install" ]; then
  37. build=true
  38. install=true
  39. elif [ "$task" = "coverage" ]; then
  40. build=true
  41. coverage=true
  42. test=true
  43. elif [ "$task" = "test" ]; then
  44. build=true
  45. test=true
  46. elif [ "$task" = "performance" ]; then
  47. build=true
  48. performance=true
  49. elif [ "$task" = "time" ]; then
  50. build=true
  51. time=true
  52. elif [ "$task" = "final" ]; then
  53. grep -r " class" src | grep -v -E 'final|enum|.git' || true
  54. grep -r " struct" src | grep -v -E 'final|enum|.git' || true
  55. exit 0
  56. elif [ "$task" = "macro" ]; then
  57. grep -r "#define" src | grep -v " CORE" || true
  58. exit 0
  59. elif [ "$task" = "include" ]; then
  60. grep -r "#include <" src | grep "\.hpp" || true
  61. exit 0
  62. else
  63. echo "unknown task"
  64. printHelpExit
  65. fi
  66. # task execution
  67. if $build; then
  68. if [ ! -e build ]; then
  69. cmake -B build -S . -G Ninja -DCMAKE_INSTALL_PREFIX=./install
  70. fi
  71. ninja -C build
  72. fi
  73. if $install; then
  74. ninja -C build install
  75. fi
  76. if $test; then
  77. cd build
  78. ./test || true
  79. cd ..
  80. fi
  81. if $performance; then
  82. cd build
  83. ./performance
  84. fi
  85. if $time; then
  86. lines=$(cat build/.ninja_log | grep "^[0-9]")
  87. startMillis=0
  88. endMillis=0
  89. name=""
  90. i=0
  91. output=""
  92. for arg in $lines; do
  93. if [ $i == 0 ]; then
  94. startMillis=$arg
  95. elif [ $i == 1 ]; then
  96. endMillis=$arg
  97. elif [ $i == 3 ]; then
  98. name=$arg
  99. diff=$(expr $endMillis - $startMillis)
  100. output="${output}\n$diff $name"
  101. fi
  102. i=$(expr $(expr $i + 1) % 5) && true
  103. done
  104. printf "$output" | sort -n
  105. fi
  106. if $coverage; then
  107. gcovr -r . build -e test -e performance
  108. fi