tasks 3.0 KB

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