on ec19422 help sign in
streamly/bin/build-lib.sh
236 lines 4.5 kB history raw
1# $1: message
2die () {
3 >&2 echo -e "Error: $1"
4 exit 1
5}
7# $1: command
8function run_verbose() {
9 echo "$*"
10 bash -c "$*"
13has_item () {
14 for i in $1
15 do
16 if test "$i" = "$2"
17 then
18 echo "$i"
19 break
20 fi
21 done
24#------------------------------------------------------------------------------
25# target groups
26#------------------------------------------------------------------------------
28test_only () {
29 if test -n "$RUNNING_TESTS"
30 then
31 echo $1
32 fi
35bench_only () {
36 if test -n "$RUNNING_BENCHMARKS"
37 then
38 echo $1
39 fi
42dev_build () {
43 if test -n "$RUNNING_DEVBUILD"
44 then
45 echo $1
46 fi
49# A group consisting of all known individual targets
50all_grp () {
51 { for i in $GROUP_TARGETS
52 do
53 for j in $(eval "echo \$$i")
54 do
55 echo $j
56 done
57 done
58 for i in $INDIVIDUAL_TARGETS
59 do
60 echo $i
61 done
62 } | sort | uniq
65# All groups
66all_target_groups () {
67 echo $GROUP_TARGETS
70# XXX pass as arg
71list_targets () {
72 echo "Individual targets:"
73 for i in $(all_grp)
74 do
75 echo "$i"
76 done
77 echo
80# XXX pass as arg
81list_target_groups () {
82 echo "All Targets: all_grp"
83 echo "Target groups:"
84 for i in $(all_target_groups)
85 do
86 echo -n "$i ["
87 eval "echo -n \$$i"
88 echo "]"
89 done
90 echo
93# XXX pass as arg
94set_targets() {
95 if test -z "$TARGETS"
96 then
97 echo $DEFAULT_TARGETS
98 else
99 for i in $(echo $TARGETS)
100 do
101 case $i in
102 *_grp) eval "echo -n \$${i}" ;;
103 *_cmp) eval "echo -n \$${i} $i" ;;
104 *) echo -n $i ;;
105 esac
106 echo -n " "
107 done
108 fi
111# We run the benchmarks in isolation in a separate process so that different
112# benchmarks do not interfere with other. To enable that we need to pass the
113# benchmark exe path to gauge as an argument. Unfortunately it cannot find its
114# own path currently.
116# The path is dependent on the architecture and cabal version.
118# $1: package name
119# $2: component
120# $3: target
121cabal_target_prog () {
122 local target_prog=`cabal_which $1 $2 $3`
123 if test -x "$target_prog"
124 then
125 echo $target_prog
126 else
127 return 1
128 fi
131set_common_vars () {
132 SLOW=0
133 QUICK_MODE=0
135 RUNNING_DEVBUILD=
137 TARGET_EXE_ARGS=
138 RTS_OPTIONS=
140 GHC_VERSION=$(ghc --numeric-version)
142 CABAL_BUILD_OPTIONS=""
143 CABAL_EXECUTABLE=cabal
145 # Use branch specific builds if git-cabal is present in PATH
146 BUILD_DIR=dist-newstyle
147 if test "$USE_GIT_CABAL" -eq 1
148 then
149 if which git-cabal 2>/dev/null
150 then
151 echo "Using git-cabal for branch specific builds"
152 CABAL_EXECUTABLE=git-cabal
153 BUILD_DIR=$(git-cabal show-builddir)
154 fi
155 fi
158# XXX cabal issue "cabal v2-exec which" cannot find benchmark/test executables
160# $1: builddir
161# $2: package name
162# $3: component ("" (lib), t (test), b (benchmark), x (executable))
163# $4: command to find
164cabal_which_builddir() {
165 local path=$(echo $1/build/*/ghc-${GHC_VERSION}/${2}-0.0.0/$3/$4/build/$4/$4)
166 test -f "$path" && echo $path
169# $1: package name
170# $2: component
171# $3: command to find
172cabal_which() {
173 cabal_which_builddir $BUILD_DIR $1 $2 $3
176# $1: build program
177# $2: package name
178# $3: component prefix
179# $4: targets
180run_build () {
181 local build_prog=$1
182 local package=$2
183 local component_prefix=$3
184 local COMPONENTS
185 local c
187 for c in $4
188 do
189 COMPONENTS+="$package:$component_prefix:$c "
190 done
191 run_verbose $build_prog $COMPONENTS || die "build failed"
194# $1: target name
195get_tix_file () {
196 echo $BUILD_DIR/build/$SYSTEM/ghc-${GHC_VERSION}/$PACKAGE_FULL_NAME/hpc/vanilla/tix/$1/$1.tix
199# $1: package name
200# $2: component
201# $3: target
202# $4: args generator func
203run_target () {
204 local package_name=$1
205 local component=$2
206 local target_name=$3
207 local extra_args=$4
209 local target_prog
210 target_prog=$(cabal_target_prog $package_name $component $target_name) || \
211 die "Cannot find executable for target $target_name"
213 echo "Running executable $target_name ..."
215 # Needed by bench-exec-one.sh
216 export BENCH_EXEC_PATH=$target_prog
217 mkdir -p $(dirname $(get_tix_file $target_name))
218 export HPCTIXFILE=$(get_tix_file $target_name)
220 run_verbose $target_prog $($extra_args $target_name $target_prog) \
221 || die "Target exe failed"
223 # hpc-coveralls fails if there is an empty dir and no .tix file generated
224 rmdir $(dirname $(get_tix_file $target_name)) 2>/dev/null || true
227# $1: package name
228# $2: component
229# $3: targets
230# $4: args generator func
231run_targets() {
232 for i in $3
233 do
234 run_target $1 $2 $i $4
235 done