@@ -0,0 +1,207 @@
1+# $1: message
2+die () {
3+ >&2 echo -e "Error: $1"
4+ exit 1
5+}
6+
7+# $1: command
8+function run_verbose() {
9+ echo "$*"
10+ bash -c "$*"
11+}
12+
13+has_item () {
14+ for i in $1
15+ do
16+ if test "$i" = "$2"
17+ then
18+ echo "$i"
19+ break
20+ fi
21+ done
22+}
23+
24+#------------------------------------------------------------------------------
25+# target groups
26+#------------------------------------------------------------------------------
27+
28+test_only () {
29+ if test -n "$RUNNING_TESTS"
30+ then
31+ echo $1
32+ fi
33+}
34+
35+bench_only () {
36+ if test -n "$RUNNING_BENCHMARKS"
37+ then
38+ echo $1
39+ fi
40+}
41+
42+dev_build () {
43+ if test -n "$RUNNING_DEVBUILD"
44+ then
45+ echo $1
46+ fi
47+}
48+
49+# A group consisting of all known individual targets
50+all_grp () {
51+ { for i in $GROUP_TARGETS
52+ do
53+ eval "echo \$$i"
54+ done
55+ echo $INDIVIDUAL_TARGETS
56+ } | sort | uniq
57+}
58+
59+# All groups including all_grp
60+all_target_groups () {
61+ echo all_grp
62+ echo $GROUP_TARGETS
63+}
64+
65+# XXX pass as arg
66+list_targets () {
67+ echo "Individual targets:"
68+ for i in $(all_grp)
69+ do
70+ echo "$i"
71+ done
72+ echo
73+}
74+
75+# XXX pass as arg
76+list_target_groups () {
77+ echo "Target groups:"
78+ for i in $(all_target_groups)
79+ do
80+ echo -n "$i ["
81+ eval "echo -n \$$i"
82+ echo "]"
83+ done
84+ echo
85+}
86+
87+# XXX pass as arg
88+set_targets() {
89+ if test -z "$TARGETS"
90+ then
91+ echo $DEFAULT_TARGETS
92+ else
93+ for i in $(echo $TARGETS)
94+ do
95+ case $i in
96+ *_grp) eval "echo -n \$${i}" ;;
97+ *_cmp) eval "echo -n \$${i} $i" ;;
98+ *) echo -n $i ;;
99+ esac
100+ echo -n " "
101+ done
102+ fi
103+}
104+
105+# We run the benchmarks in isolation in a separate process so that different
106+# benchmarks do not interfere with other. To enable that we need to pass the
107+# benchmark exe path to gauge as an argument. Unfortunately it cannot find its
108+# own path currently.
109+
110+# The path is dependent on the architecture and cabal version.
111+
112+# $1: package name
113+# $2: target
114+cabal_target_prog () {
115+ local target_prog=`$WHICH_COMMAND $1 $2`
116+ if test -x "$target_prog"
117+ then
118+ echo $target_prog
119+ else
120+ return 1
121+ fi
122+}
123+
124+set_common_vars () {
125+ SLOW=0
126+ QUICK_MODE=0
127+
128+ RUNNING_TESTS=
129+ RUNNING_BENCHMARKS=
130+ RUNNING_DEVBUILD=
131+
132+ TARGET_EXE_ARGS=
133+ RTS_OPTIONS=
134+
135+ GHC_VERSION=$(ghc --numeric-version)
136+
137+ CABAL_BUILD_OPTIONS=""
138+ CABAL_EXECUTABLE=cabal
139+
140+ # Use branch specific builds if git-cabal is present in PATH
141+ BUILD_DIR=dist-newstyle
142+ if which git-cabal 2>/dev/null
143+ then
144+ echo "Using git-cabal for branch specific builds"
145+ CABAL_EXECUTABLE=git-cabal
146+ BUILD_DIR=$(git-cabal show-builddir)
147+ fi
148+}
149+
150+# XXX cabal issue "cabal v2-exec which" cannot find benchmark/test executables
151+
152+# $1: builddir
153+# $2: package name
154+# $3: command to find
155+cabal_which_builddir() {
156+ find $1 -type f -path "*${GHC_VERSION}/${2}*/$3" 2>/dev/null
157+}
158+
159+# $1: package name
160+# $2: command to find
161+cabal_which() {
162+ cabal_which_builddir $BUILD_DIR $1 $2
163+}
164+
165+# $1: build program
166+# $2: package name
167+# $3: component prefix
168+# $4: targets
169+run_build () {
170+ local build_prog=$1
171+ local package=$2
172+ local component_prefix=$3
173+ local COMPONENTS
174+ local c
175+
176+ for c in $4
177+ do
178+ COMPONENTS+="$package:$component_prefix:$c "
179+ done
180+ run_verbose $build_prog $COMPONENTS || die "build failed"
181+}
182+
183+# $1: package name
184+# $2: target
185+run_target () {
186+ local package_name=$1
187+ local target_name=$2
188+ local target_exe=$target_name
189+ local target_prog
190+ target_prog=$(cabal_target_prog $package_name $target_exe) || \
191+ die "Cannot find executable for target $target_name"
192+
193+ echo "Running executable $target_name ..."
194+ TARGET_EXE_EXTRA_ARGS="$RTS_OPTIONS"
195+
196+ run_verbose $target_prog $TARGET_EXE_EXTRA_ARGS $TARGET_EXE_ARGS \
197+ || die "Target exe failed"
198+}
199+
200+# $1: package name
201+# $2: targets
202+run_targets() {
203+ for i in $2
204+ do
205+ run_target $1 $i
206+ done
207+}