buildDUNE.sh
Go to the documentation of this file.
1 #!/bin/bash
2 
3 # build dunetpc
4 # use mrb
5 # designed to work on Jenkins
6 
7 echo "dunetpc version: $DUNE"
8 echo "base qualifiers: $QUAL"
9 QUAL=`echo ${QUAL} | sed -e "s/-/:/g"`
10 echo "modified base qualifiers: $QUAL"
11 echo "build type: $BUILDTYPE"
12 echo "workspace: $WORKSPACE"
13 
14 # Don't do ifdh build on macos.
15 
16 #if uname | grep -q Darwin; then
17 # if ! echo $QUAL | grep -q noifdh; then
18 # echo "Ifdh build requested on macos. Quitting."
19 # exit
20 # fi
21 #fi
22 
23 # Get number of cores to use.
24 
25 if [ `uname` = Darwin ]; then
26  #ncores=`sysctl -n hw.ncpu`
27  #ncores=$(( $ncores / 4 ))
28  ncores=4
29 else
30  ncores=`cat /proc/cpuinfo 2>/dev/null | grep -c -e '^processor'`
31 fi
32 if [ $ncores -lt 1 ]; then
33  ncores=1
34 fi
35 echo "Building using $ncores cores."
36 
37 # Environment setup. Just use cvmfs. larsoft builds are not supported on /grid/fermiapp anymore
38 
39 echo "ls /cvmfs/dune.opensciencegrid.org/products/dune/"
40 ls /cvmfs/dune.opensciencegrid.org/products/dune/
41 echo
42 
43 if [ `uname` = Darwin -a -f /grid/fermiapp/products/dune/setup_dune_fermiapp.sh ]; then
44  source /grid/fermiapp/products/dune/setup_dune_fermiapp.sh || exit 1
45 elif [ -f /cvmfs/dune.opensciencegrid.org/products/dune/setup_dune.sh ]; then
46  if [ -x /cvmfs/grid.cern.ch/util/cvmfs-uptodate ]; then
47  /cvmfs/grid.cern.ch/util/cvmfs-uptodate /cvmfs/dune.opensciencegrid.org/products
48  fi
49  source /cvmfs/dune.opensciencegrid.org/products/dune/setup_dune.sh || exit 1
50 else
51  echo "No setup file found."
52  exit 1
53 fi
54 
55 # Use git out of ups except use the system git on macos
56 
57 if ! uname | grep -q Darwin; then
58  setup git || exit 1
59 fi
60 
61 # skip around a version of mrb that does not work on macOS
62 
63 if [ `uname` = Darwin ]; then
64  if [[ x`which mrb | grep v1_17_02` != x ]]; then
65  unsetup mrb || exit 1
66  setup mrb v1_16_02 || exit 1
67  fi
68 fi
69 
70 setup gitflow || exit 1
71 export MRB_PROJECT=dune
72 echo "Mrb path:"
73 which mrb
74 
75 # make the timeouts longer and accept low-speed transfers
76 
77 export GIT_HTTP_LOW_SPEED_LIMIT=1000
78 export GIT_HTTP_LOW_SPEED_TIME=600
79 
80 #dla set -x
81 rm -rf $WORKSPACE/temp || exit 1
82 mkdir -p $WORKSPACE/temp || exit 1
83 mkdir -p $WORKSPACE/copyBack || exit 1
84 rm -f $WORKSPACE/copyBack/* || exit 1
85 cd $WORKSPACE/temp || exit 1
86 mrb newDev -v $DUNE -q $QUAL:$BUILDTYPE || exit 1
87 
88 #dla set +x
89 source localProducts*/setup || exit 1
90 
91 # some shenanigans so we can use getopt v1_1_6
92 if [ `uname` = Darwin ]; then
93 # cd $MRB_INSTALL
94 # curl --fail --silent --location --insecure -O http://scisoft.fnal.gov/scisoft/packages/getopt/v1_1_6/getopt-1.1.6-d13-x86_64.tar.bz2 || \
95 # { cat 1>&2 <<EOF
96 #ERROR: pull of http://scisoft.fnal.gov/scisoft/packages/getopt/v1_1_6/getopt-1.1.6-d13-x86_64.tar.bz2 failed
97 #EOF
98 # exit 1
99 # }
100 # tar xf getopt-1.1.6-d13-x86_64.tar.bz2 || exit 1
101  setup getopt v1_1_6 || exit 1
102 # which getopt
103 fi
104 
105 #dla set -x
106 cd $MRB_SOURCE || exit 1
107 # make sure we get a read-only copy
108 # put some retry logic here instead
109 
110 maxtries=20
111 ntries=0
112 until [ $ntries -ge $maxtries ]
113 do
114  date
115  mrb g -r -t $DUNE dunetpc && break
116  ntries=$[$ntries+1]
117  sleep 60
118 done
119 if [ $ntries = $maxtries ]; then
120  echo "Could not clone dunetpc using mrb g. Quitting."
121  exit 1
122 fi
123 
124 ## Extract duneutil version from dunetpc product_deps
125 #duneutil_version=`grep duneutil $MRB_SOURCE/dunetpc/ups/product_deps | grep -v qualifier | awk '{print $2}'`
126 #echo "duneutil version: $duneutil_version"
127 #mrb g -r -t $duneutil_version duneutil || exit 1
128 
129 
130 cd $MRB_BUILDDIR || exit 1
131 mrbsetenv || exit 1
132 mrb b -j$ncores || exit 1
133 mrb mp -n dune -- -j$ncores || exit 1
134 
135 
136 # Extract flavor.
137 
138 flvr=''
139 if uname | grep -q Darwin; then
140  flvr=`ups flavor -2`
141 else
142  flvr=`ups flavor -4`
143 fi
144 
145 
146 manifest=`ls dune-*_MANIFEST.txt`
147 
148 # add flavor and qualifier to the dunetpc line
149 
150 dtline=`grep dunetpc $manifest`
151 dtmodline="${dtline} -f ${flvr} -q ${QUAL}:${BUILDTYPE}"
152 rm ${manifest}
153 echo $dtmodline > ${manifest}
154 
155 # add dune_pardata to the manifest
156 
157 dune_pardata_version=`grep dune_pardata $MRB_SOURCE/dunetpc/ups/product_deps | grep -v qualifier | awk '{print $2}'`
158 dune_pardata_dot_version=`echo ${dune_pardata_version} | sed -e 's/_/./g' | sed -e 's/^v//'`
159 echo "dune_pardata ${dune_pardata_version} dune_pardata-${dune_pardata_dot_version}-noarch.tar.bz2 -f NULL" >> $manifest
160 
161 # get platform
162 OS=$(uname)
163 case $OS in
164  Linux)
165  PLATFORM=$(uname -r | grep -o "el[0-9]"|sed s'/el/slf/')
166  ;;
167  Darwin)
168  PLATFORM=$(uname -r | awk -F. '{print "d"$1}')
169  ;;
170 esac
171 
172 cd $MRB_SOURCE || exit 1
173 
174 # find our set qualifier from artdaq_core's qualifier
175 
176 SQUAL=`ups active | grep artdaq_core | tr : '\n' | grep ^s | awk '{print $1}'`
177 echo "Set qualifier from artdaq_core: $SQUAL"
178 
179 DQTMP=${QUAL}-${SQUAL}
180 DASHQUAL=`echo ${DQTMP} | sed -e "s/:/-/g" | sed -e "s/-/-nu-/"`
181 DASHQUAL2=`echo ${QUAL} | sed -e "s/:/-/g"`
182 
183 fci=`expr index "$QUAL" :`
184 let "fct = $fci - 1"
185 COMPILER=$QUAL
186 if [[ $fci != 0 ]]; then
187  COMPILER=${QUAL:0:$fct}
188 fi
189 echo "Compiler is: $COMPILER"
190 
191 cd $MRB_BUILDDIR
192 
193 # add dune_raw_data to the manifest
194 
195 dune_raw_data_version=`ups active | grep dune_raw_data | awk '{print $2}'`
196 echo "dune_raw_data version: $dune_raw_data_version"
197 dune_raw_data_flavor=`ups active | grep dune_raw_data | awk '{print $4}'`
198 echo "dune_raw_data flavor: $dune_raw_data_flavor"
199 dune_raw_data_quals=`ups active | grep dune_raw_data | awk '{print $6}'`
200 echo "dune_raw_data quals: $dune_raw_data_quals"
201 dune_raw_data_dot_version=`echo ${dune_raw_data_version} | sed -e 's/_/./g' | sed -e 's/^v//'`
202 echo "dune_raw_data ${dune_raw_data_version} dune_raw_data-${dune_raw_data_dot_version}-${PLATFORM}-x86_64-${DASHQUAL}-${BUILDTYPE}.tar.bz2 -f ${dune_raw_data_flavor} -q ${dune_raw_data_quals}" >> $manifest
203 
204 
205 # add dunepdsprce to the manifest
206 
207 dunepdsprce_version=`ups active | grep dunepdsprce | awk '{print $2}'`
208 echo "dunepdsprce version: $dunepdsprce_version"
209 dunepdsprce_flavor=`ups active | grep dunepdsprce | awk '{print $4}'`
210 echo "dunepdsprce flavor: $dunepdsprce_flavor"
211 dunepdsprce_quals=`ups active | grep dunepdsprce | awk '{print $6}'`
212 echo "dunepdsprce quals: $dunepdsprce_quals"
213 dunepdsprce_dot_version=`echo ${dunepdsprce_version} | sed -e 's/_/./g' | sed -e 's/^v//'`
214 echo "dunepdsprce ${dunepdsprce_version} dunepdsprce-${dunepdsprce_dot_version}-${PLATFORM}-x86_64-${COMPILER}-gen-${BUILDTYPE}.tar.bz2 -f ${dunepdsprce_flavor} -q ${dunepdsprce_quals}" >> $manifest
215 
216 # add dune_oslibs to the manifest
217 
218 dune_oslibs_version=`ups active | grep dune_oslibs | awk '{print $2}'`
219 echo "dune_oslibs version: $dune_oslibs_version"
220 dune_oslibs_flavor=`ups active | grep dune_oslibs | awk '{print $4}'`
221 echo "dune_oslibs flavor: $dune_oslibs_flavor"
222 dune_oslibs_dot_version=`echo ${dune_oslibs_version} | sed -e 's/_/./g' | sed -e 's/^v//'`
223 echo "dune_oslibs ${dune_oslibs_version} dune_oslibs-${dune_oslibs_dot_version}-${PLATFORM}-x86_64.tar.bz2 -f ${dune_oslibs_flavor}" >> $manifest
224 
225 # add dunedetdataformats to the manifest
226 
227 dunedetdataformats_version=`ups active | grep dunedetdataformats | awk '{print $2}'`
228 echo "dunedetdataformats version: $dunedetdataformats_version"
229 dunedetdataformats_flavor=`ups active | grep dunedetdataformats | awk '{print $4}'`
230 echo "dunedetdataformats flavor: $dunedetdataformats_flavor"
231 dunedetdataformats_dot_version=`echo ${dunedetdataformats_version} | sed -e 's/_/./g' | sed -e 's/^v//'`
232 echo "dunedetdataformats ${dunedetdataformats_version} dunedetdataformats-${dunedetdataformats_dot_version}-noarch.tar.bz2 -f ${dunedetdataformats_flavor}" >> $manifest
233 
234 # add dunedaqdataformats to the manifest
235 
236 dunedaqdataformats_version=`ups active | grep dunedaqdataformats | awk '{print $2}'`
237 echo "dunedaqdataformats version: $dunedaqdataformats_version"
238 dunedaqdataformats_flavor=`ups active | grep dunedaqdataformats | awk '{print $4}'`
239 echo "dunedaqdataformats flavor: $dunedaqdataformats_flavor"
240 dunedaqdataformats_dot_version=`echo ${dunedaqdataformats_version} | sed -e 's/_/./g' | sed -e 's/^v//'`
241 echo "dunedaqdataformats ${dunedaqdataformats_version} dunedaqdataformats-${dunedaqdataformats_dot_version}-noarch.tar.bz2 -f ${dunedaqdataformats_flavor}" >> $manifest
242 
243 
244 # Extract larsoft version from product_deps.
245 
246 larsoft_version=`grep larsoft $MRB_SOURCE/dunetpc/ups/product_deps | grep -v qualifier | awk '{print $2}'`
247 larsoft_dot_version=`echo ${larsoft_version} | sed -e 's/_/./g' | sed -e 's/^v//'`
248 
249 # Construct name of larsoft manifest.
250 
251 larsoft_manifest=larsoft-${larsoft_dot_version}-${flvr}-${SQUAL}-${DASHQUAL2}-${BUILDTYPE}_MANIFEST.txt
252 echo "Larsoft manifest:"
253 echo $larsoft_manifest
254 echo
255 
256 # Fetch laraoft manifest from scisoft and append to dunetpc manifest.
257 
258 echo "curl --fail --silent --location --insecure http://scisoft.fnal.gov/scisoft/bundles/larsoft/${larsoft_version}/manifest/${larsoft_manifest} >> $manifest || exit 1"
259 
260 curl --fail --silent --location --insecure http://scisoft.fnal.gov/scisoft/bundles/larsoft/${larsoft_version}/manifest/${larsoft_manifest} >> $manifest || exit 1
261 
262 echo "Done with the curl command."
263 
264 # Special handling of noifdh builds goes here.
265 
266 if echo $QUAL | grep -q noifdh; then
267 
268  if uname | grep -q Darwin; then
269 
270  # If this is a macos build, then rename the manifest to remove noifdh qualifier in the name
271 
272  noifdh_manifest=`echo $manifest | sed 's/-noifdh//'`
273  mv $manifest $noifdh_manifest
274 
275  else
276 
277  # Otherwise (for slf builds), delete the manifest entirely.
278 
279  rm -f $manifest
280 
281  fi
282 fi
283 
284 # edit the manifest's artdaq_core version
285 
286 # version of artdaq_core with underscores
287 ARDC_UVERSION=`ups active | grep artdaq_core | awk '{print $2}'`
288 
289 # version of artdaq_core with dots
290 ARDC_DVERSION=`echo $ARDC_UVERSION | sed -e 's/_/./g' | sed -e 's/^v//'`
291 
292 # we're assuming the qualifiers match up between what we want and what we have for artdaq_core
293 # replace artdaq_core line in manifest with our new version
294 
295 if [ `grep artdaq_core $manifest | wc -l` = 0 ]; then
296  echo "LArSoft manifest lacks an artdaq_core line"
297  exit 1
298 fi
299 
300 ARDCLINE=`grep artdaq_core $manifest | head -1`
301 ARDCOLDVER=`echo $ARDCLINE | awk '{print $2}'`
302 ARDCOLDVERD=`echo $ARDCOLDVER | sed -e 's/_/\\\./g' | sed -e 's/^v//'`
303 ARDCNEWLINE=`echo $ARDCLINE | sed -e "s/${ARDCOLDVER}/${ARDC_UVERSION}/g" | sed -e "s/${ARDCOLDVERD}/${ARDC_DVERSION}/g"`
304 
305 echo "Replacing artdaq_core line the manifest:"
306 echo $ARDCLINE
307 echo "with this one:"
308 echo $ARDCNEWLINE
309 echo "and deleting others."
310 
311 touch newmanifest.txt || exit 1
312 rm newmanifest.txt || exit 1
313 grep -v artdaq_core $manifest > newmanifest.txt || exit 1
314 echo $ARDCNEWLINE >> newmanifest.txt
315 mv newmanifest.txt $manifest || exit 1
316 
317 # Save artifacts.
318 
319 echo "Moving tarballs to copyBack"
320 
321 mv *.bz2 $WORKSPACE/copyBack/ || exit 1
322 
323 echo "Moving manifest to copyBack"
324 
325 manifest=dune-*_MANIFEST.txt
326 if [ -f $manifest ]; then
327  mv $manifest $WORKSPACE/copyBack/ || exit 1
328 fi
329 #cp $MRB_BUILDDIR/dunetpc/releaseDB/*.html $WORKSPACE/copyBack/
330 ls -l $WORKSPACE/copyBack/
331 cd $WORKSPACE || exit 1
332 rm -rf $WORKSPACE/temp || exit 1
333 #dla set +x
334 
335 exit 0