10
10
# SHOW_EVERY : print progress/iteration header every N iterations (default: 100, 1 = every run, <=0 = disabled)
11
11
# LOG_STDERR : set to 1 to enable verbose stderr logging (HLS_TEST_LOG_STDERR & HLS_TEST_HARNESS_STDERR) (default: 1)
12
12
# NO_BUILD_ONCE : set to non-empty to skip the initial cabal build step
13
+ # RUN_MODE : choose 'build' (build once and exit), 'run' (skip upfront build and just run), or 'both' (default)
13
14
#
14
15
# Test selection:
15
16
# TEST_PATTERNS : comma-separated list of entries to run each iteration.
@@ -37,6 +38,7 @@ MAX_ITER="${MAX_ITER:-}"
37
38
SLEEP_SECS=" ${SLEEP_SECS:- 0} "
38
39
SHOW_EVERY=" ${SHOW_EVERY:- 1} "
39
40
LOG_STDERR=" ${LOG_STDERR:- 1} "
41
+ RUN_MODE=" ${RUN_MODE:- both} " # build | run | both
40
42
41
43
# Allow providing a positional max iteration: ./open-close-loop.sh 50
42
44
if [[ $# -ge 1 && -z " ${MAX_ITER} " ]]; then
@@ -96,10 +98,11 @@ if [[ ${#items[@]} -eq 0 ]]; then
96
98
exit 2
97
99
fi
98
100
99
- # Build required test binaries once upfront (unless NO_BUILD_ONCE is set)
100
- if [[ -z " ${NO_BUILD_ONCE :- } " ]] ; then
101
- # collect unique BIN names
101
+ # Helper to build required test binaries once
102
+ build_required_bins_once () {
103
+ # collect unique BIN names from global 'items'
102
104
declare -a bins_to_build=()
105
+ local it bin seen b
103
106
for it in " ${items[@]} " ; do
104
107
bin=" ${it%%::* } " ; seen=0
105
108
if (( ${# bins_to_build[@]} > 0 )) ; then
@@ -110,11 +113,40 @@ if [[ -z "${NO_BUILD_ONCE:-}" ]]; then
110
113
if (( ${# bins_to_build[@]} > 0 )) ; then
111
114
echo " [loop] Building test targets once upfront: ${bins_to_build[*]} " >&2
112
115
if ! cabal build " ${bins_to_build[@]} " >&2 ; then
113
- echo " [loop][error] Build failed. Cannot proceed with tests. " >&2
114
- exit 2
116
+ echo " [loop][error] Build failed." >&2
117
+ return 2
115
118
fi
116
- echo " [loop] Build succeeded. Proceeding with tests. " >&2
119
+ echo " [loop] Build succeeded." >&2
117
120
fi
121
+ return 0
122
+ }
123
+
124
+ # Honor RUN_MODE before any build/run
125
+ case " ${RUN_MODE} " in
126
+ build)
127
+ if ! build_required_bins_once; then exit 2; fi
128
+ echo " [loop] RUN_MODE=build completed. Exiting without running tests." >&2
129
+ exit 0
130
+ ;;
131
+ run)
132
+ echo " [loop] RUN_MODE=run: skipping upfront build, proceeding to run loop." >&2
133
+ ;;
134
+ both)
135
+ : # default behavior below
136
+ ;;
137
+ * )
138
+ echo " [loop][error] Invalid RUN_MODE='${RUN_MODE} '. Use one of: build | run | both." >&2
139
+ exit 2
140
+ ;;
141
+ esac
142
+
143
+ # Build required test binaries once upfront (unless NO_BUILD_ONCE is set or RUN_MODE=run)
144
+ if [[ -z " ${NO_BUILD_ONCE:- } " && " ${RUN_MODE} " != " run" ]]; then
145
+ if ! build_required_bins_once; then
146
+ echo " [loop][error] Cannot proceed with tests due to build failure." >&2
147
+ exit 2
148
+ fi
149
+ echo " [loop] Proceeding with tests." >&2
118
150
fi
119
151
120
152
# Resolve binary path by name (cache results)
0 commit comments