Repository navigation
Expand file tree
/
Copy pathbatch_task.sh
More file actions
executable file
·85 lines (67 loc) · 2.11 KB
/
Copy pathbatch_task.sh
File metadata and controls
executable file
·85 lines (67 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
set -euo pipefail
# Make sure the script is executed from the project root
if [[ ! -f "batch_task.sh" ]]; then
echo "Error: This script must be run from the qihe-benchmark root directory."
exit 1
fi
# --- Helper Functions ---
# List all available project targets by looking at the tasks/ directory
list_all_targets() {
find tasks -maxdepth 1 -type f -name "*.sh" -exec basename {} .sh \;
}
# Show usage information for the script
show_help() {
local task_name=${1:-"<task_name>"}
echo "Usage:"
echo " $0 $task_name -a Execute '$task_name' for all targets"
echo " $0 $task_name [target1 target2 ...] Execute '$task_name' for specific targets"
echo " $0 $task_name -h|--help Show this help message"
echo ""
echo "Available targets:"
for target in $(list_all_targets); do
echo " $target"
done
exit 0
}
# --- Main Logic ---
main() {
if [[ $# -eq 0 ]]; then
show_help
exit 1
fi
local TASK_NAME="$1"
shift
if [[ $# -eq 0 ]]; then
show_help "$TASK_NAME"
exit 1
fi
# Handle help flag
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
show_help "$TASK_NAME"
fi
# Handle 'all' flag
if [[ "$1" == "-a" ]]; then
echo "Executing task '$TASK_NAME' for all targets..."
PROJECTS=($(list_all_targets))
else
PROJECTS=("$@")
fi
for project in "${PROJECTS[@]}"; do
task_script="tasks/${project}.sh"
if [[ ! -f "$task_script" ]]; then
echo "Warning: Task script for project '$project' not found at '$task_script'. Skipping."
continue
fi
# Define build and loc functions as no-ops to avoid errors if not defined in the sourced script
build() { echo "Warning: Task 'build' not defined for project '$project'. Skipping."; }
loc() { echo "Warning: Task 'loc' not defined for project '$project'. Skipping."; }
# Source the script to make its functions available
source "$task_script"
echo "→ Executing task '$TASK_NAME' for project '$project'..."
# Execute the task
"$TASK_NAME"
done
echo "Batch task '$TASK_NAME' finished for all specified projects."
}
main "$@"