tasks 2.0 KB

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