tasks 2.3 KB

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