tasks 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. profile=$(cat profile)
  31. # parsing
  32. if [ "$task" = "clean" ]; then
  33. rm -rf build install
  34. exit 0
  35. elif [ "$task" = "build" ]; then
  36. build=true
  37. elif [ "$task" = "install" ]; then
  38. build=true
  39. install=true
  40. elif [ "$task" = "coverage" ]; then
  41. build=true
  42. coverage=true
  43. test=true
  44. elif [ "$task" = "test" ]; then
  45. build=true
  46. test=true
  47. elif [ "$task" = "performance" ]; then
  48. build=true
  49. performance=true
  50. elif [ "$task" = "time" ]; then
  51. build=true
  52. time=true
  53. elif [ "$task" = "final" ]; then
  54. grep -r " class" src include | grep -v -E 'final|enum|.git' || true
  55. grep -r " struct" src include | grep -v -E 'final|enum|.git' || true
  56. exit 0
  57. elif [ "$task" = "macro" ]; then
  58. grep -r "#define" src include | grep -v " CORE" || true
  59. exit 0
  60. elif [ "$task" = "include" ]; then
  61. grep -r "#include <" src include | grep "\.hpp" || true
  62. exit 0
  63. else
  64. echo "unknown task"
  65. printHelpExit
  66. fi
  67. # task execution
  68. if $build; then
  69. if [ ! -e build ]; then
  70. cmake -B build -S . -G Ninja -DCMAKE_INSTALL_PREFIX=./install \
  71. -DCMAKE_BUILD_TYPE=$profile
  72. fi
  73. ninja -C build
  74. fi
  75. if $install; then
  76. ninja -C build install
  77. fi
  78. if $test; then
  79. cd build
  80. ./test || true
  81. cd ..
  82. fi
  83. if $performance; then
  84. cd build
  85. ./performance
  86. fi
  87. if $time; then
  88. lines=$(cat build/.ninja_log | grep "^[0-9]")
  89. startMillis=0
  90. endMillis=0
  91. name=""
  92. i=0
  93. output=""
  94. for arg in $lines; do
  95. if [ $i == 0 ]; then
  96. startMillis=$arg
  97. elif [ $i == 1 ]; then
  98. endMillis=$arg
  99. elif [ $i == 3 ]; then
  100. name=$arg
  101. diff=$(expr $endMillis - $startMillis)
  102. output="${output}\n$diff $name"
  103. fi
  104. i=$(expr $(expr $i + 1) % 5) && true
  105. done
  106. printf "$output" | sort -n
  107. fi
  108. if $coverage; then
  109. gcovr -r . build -e test -e performance
  110. fi