Przeglądaj źródła

Various shellscript improvements

Kajetan Johannes Hammerle 2 miesięcy temu
rodzic
commit
4223c9761c
1 zmienionych plików z 12 dodań i 12 usunięć
  1. 12 12
      tasks

+ 12 - 12
tasks

@@ -1,7 +1,7 @@
 #!/bin/bash
 set -e
 clear
-cd $(dirname $0)
+cd "$(dirname "$0")"
 
 compiler="gcc"
 if [ -e compiler ]; then
@@ -126,7 +126,7 @@ buildProfile() {
     folder=$1
     shift 1
     if [ ! -e "$folder" ]; then
-        cmake -B "$folder" -S . -G Ninja -DCMAKE_C_COMPILER=${compiler} -DCMAKE_INSTALL_PREFIX=../install $@
+        cmake -B "$folder" -S . -G Ninja -DCMAKE_C_COMPILER="${compiler}" -DCMAKE_INSTALL_PREFIX=../install "$@"
     fi
     ninja -C "$folder"
 }
@@ -174,8 +174,8 @@ if $performance; then
     if $stats; then
         user=$(whoami)
         sudo perf record ./performance
-        sudo chown $user:$user perf.data
-        sudo chown $user:$user default.profraw
+        sudo chown "$user:$user" perf.data
+        sudo chown "$user:$user" default.profraw
         perf report
     else
         ./performance
@@ -183,7 +183,7 @@ if $performance; then
     cd ..
 fi
 if $time; then
-    lines=$(cat build_release/.ninja_log | grep "^[0-9]")
+    lines=$(grep "^[0-9]" "build_release/.ninja_log")
 
     startMillis=0
     endMillis=0
@@ -197,12 +197,12 @@ if $time; then
             endMillis=$arg
         elif [ $i == 3 ]; then
             name=$arg
-            diff=$(expr $endMillis - $startMillis)
+	    diff=$((endMillis - startMillis))
             output="${output}\n$diff $name"
         fi
-        i=$(expr $(expr $i + 1) % 5) && true
+	i=$(($((i + 1)) % 5))
     done
-    printf "$output" | sort -n
+    echo -e "$output" | sort -n
 fi
 
 generateCoverageFunctions() {
@@ -210,18 +210,18 @@ generateCoverageFunctions() {
     ignore=$(cat ./ignoredCoverageFunctions)
     list=$(nm ./build_debug/libcore.a -j | grep "^[a-zA-Z]")
     for file in $ignore; do
-	list=$(echo "$list" | grep -v $file)
+	list=$(echo "$list" | grep -v "$file")
     done
     echo "$list" | sed 's/^/allowlist_fun:/g' > build_debug/coverageFunctions
 }
 
 if $coverage; then
-    if [ $compiler = "gcc" ]; then
+    if [ "$compiler" = "gcc" ]; then
         gcovr -r . build_debug -e test -e performance \
             --exclude-lines-by-pattern ".*CoverageIgnore.*"
     else
-        files=$(find build_debug -name *.profraw)
-        llvm-profdata-17 merge -sparse $files -o build_debug/default.profdata
+	mapfile -t files < <(find build_debug -name "*.profraw")
+        llvm-profdata-17 merge -sparse "${files[@]}" -o build_debug/default.profdata
 	generateCoverageFunctions
 	llvm-cov-17 show ./build_debug/test -instr-profile=build_debug/default.profdata --ignore-filename-regex="test/" -line-coverage-lt=100 --name-allowlist=build_debug/coverageFunctions
     fi