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