on f2b2aa4 help sign in
streamly/bin/build-lib.sh
246 lines 4.8 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 CABAL_BUILD_OPTIONS=""
141 CABAL_EXECUTABLE=cabal
143 # Use branch specific builds if git-cabal is present in PATH
144 BUILD_DIR=dist-newstyle
145 if test "$USE_GIT_CABAL" -eq 1
146 then
147 if which git-cabal 2>/dev/null
148 then
149 echo "Using git-cabal for branch specific builds"
150 CABAL_EXECUTABLE=git-cabal
151 BUILD_DIR=$(git-cabal show-builddir)
152 fi
153 fi
156# To be called after parsing CLI arguments
157set_derived_vars () {
158 if test -n "$CABAL_WITH_COMPILER"
159 then
160 CABAL_BUILD_OPTIONS+=" --with-compiler $CABAL_WITH_COMPILER"
161 else
162 CABAL_WITH_COMPILER=ghc
163 fi
165 GHC_VERSION=$($CABAL_WITH_COMPILER --numeric-version)
168# XXX cabal issue "cabal v2-exec which" cannot find benchmark/test executables
170# $1: builddir
171# $2: package name
172# $3: component ("" (lib), t (test), b (benchmark), x (executable))
173# $4: command to find
174cabal_which_builddir() {
175 local path=$(echo $1/build/*/ghc-${GHC_VERSION}/${2}-0.0.0/$3/$4/build/$4/$4)
176 test -f "$path" && echo $path
179# $1: package name
180# $2: component
181# $3: command to find
182cabal_which() {
183 cabal_which_builddir $BUILD_DIR $1 $2 $3
186# $1: build program
187# $2: package name
188# $3: component prefix
189# $4: targets
190run_build () {
191 local build_prog=$1
192 local package=$2
193 local component_prefix=$3
194 local COMPONENTS
195 local c
197 for c in $4
198 do
199 COMPONENTS+="$package:$component_prefix:$c "
200 done
201 run_verbose $build_prog $COMPONENTS || die "build failed"
204# $1: target name
205get_tix_file () {
206 echo $BUILD_DIR/build/$SYSTEM/ghc-${GHC_VERSION}/$PACKAGE_FULL_NAME/hpc/vanilla/tix/$1/$1.tix
209# $1: package name
210# $2: component
211# $3: target
212# $4: args generator func
213run_target () {
214 local package_name=$1
215 local component=$2
216 local target_name=$3
217 local extra_args=$4
219 local target_prog
220 target_prog=$(cabal_target_prog $package_name $component $target_name) || \
221 die "Cannot find executable for target $target_name"
223 echo "Running executable $target_name ..."
225 # Needed by bench-exec-one.sh
226 export BENCH_EXEC_PATH=$target_prog
227 mkdir -p $(dirname $(get_tix_file $target_name))
228 export HPCTIXFILE=$(get_tix_file $target_name)
230 run_verbose $target_prog $($extra_args $target_name $target_prog) \
231 || die "Target exe failed"
233 # hpc-coveralls fails if there is an empty dir and no .tix file generated
234 rmdir $(dirname $(get_tix_file $target_name)) 2>/dev/null || true
237# $1: package name
238# $2: component
239# $3: targets
240# $4: args generator func
241run_targets() {
242 for i in $3
243 do
244 run_target $1 $2 $i $4
245 done