build-larsoft.sh
Go to the documentation of this file.
1 #!/bin/bash
2 
3 # pull source code in ${working_dir}/source
4 # build in ${working_dir}/build
5 # copyback directory is ${working_dir}/copyBack
6 
7 usage()
8 {
9  cat 1>&2 <<EOF
10 Usage: $(basename ${0}) [-h]
11  env WORKSPACE=<workspace> LARVER=<larsoft version> QUAL=<qualifier> BUILDTYPE=<debug|prof> $(basename ${0})
12 
13 Options:
14 
15  -h This help.
16 
17 EOF
18 }
19 
20 have_label() {
21  for label in "${labels[@]}"; do
22  for wanted in "$@"; do
23  [[ "${label}" == "${wanted}" ]] && return 0
24  done
25  done
26  return 1
27 }
28 
29 
30 while getopts :h OPT; do
31  case ${OPT} in
32  h)
33  usage
34  exit 1
35  ;;
36  *)
37  usage
38  exit 1
39  esac
40 done
41 shift `expr $OPTIND - 1`
42 OPTIND=1
43 
44 working_dir="${WORKSPACE:-$(pwd)}"
45 version="${1:-${LARVER}}"
46 qual_set="${2:-${QUAL}}"
47 oIFS=${IFS}; IFS=:; quals=(${qual_set//-/:}); IFS=$oIFS; unset oIFS
48 build_type="${3:-${BUILDTYPE}}"
49 
50 labels=()
51 for onequal in "${quals[@]}"; do
52  if [[ "${onequal}" =~ ^([ec])([0-9]+)$ ]]; then
53  basequal=${onequal}
54  elif [[ "${onequal}" =~ ^(s)([1-9][0-9]+)$ ]]; then
55  squal=${onequal}
56  else
57  labels+=${onequal}
58  fi
59 done
60 
61 echo "basequal ${basequal} squal ${squal} labels ${labels}"
62 
63 case ${build_type} in
64  debug) ;;
65  prof) ;;
66  *)
67  usage
68  exit 1
69 esac
70 
71 # create copyBack so artifact copy does not fail on early exit
72 rm -rf "${working_dir}/copyBack"
73 mkdir -p "${working_dir}/copyBack" || exit 1
74 
75 # Find platform flavor.
76 OS=`uname`
77 if [ "${OS}" = "Linux" ]
78 then
79  id=`lsb_release -is`
80  if [ "${id}" = "Ubuntu" ]
81  then
82  flvr=u`lsb_release -r | sed -e 's/[[:space:]]//g' | cut -f2 -d":" | cut -f1 -d"."`
83  else
84  flvr=slf`lsb_release -r | sed -e 's/[[:space:]]//g' | cut -f2 -d":" | cut -f1 -d"."`
85  fi
86 elif [ "${OS}" = "Darwin" ]
87 then
88  flvr=d`uname -r | cut -f1 -d"."`
89  # set locale
90  echo
91  locale
92  echo
93  export LANG=C
94  export LC_ALL=$LANG
95  locale
96  echo
97 else
98  echo "ERROR: unrecognized operating system ${OS}"
99  exit 1
100 fi
101 
102 # Check supported builds.
103 if [[ `uname -s` == Darwin ]]; then
104  OSnum=`uname -r | cut -f1 -d"."`
105  xver=`xcodebuild -version | grep Xcode | cut -f2 -d" " | cut -f1 -d"."`
106  xcver=`xcodebuild -version | grep Xcode`
107  if { [[ ${basequal} =~ ^e(9$|[1-9][0-9]) ]] && \
108  [[ ${xver} < 7 ]] && \
109  [[ ${OSnum} > 13 ]]; }; then
110  # XCode too old on this platform.
111  echo "${basequal} build not supported on `uname -s`${OSnum} with ${xcver}"
112  echo "${basequal} build not supported on `uname -s`${OSnum} with ${xcver}" > \
113  "${working_dir}/copyBack/skipping_build"
114  exit 0
115  elif { [[ "$basequal" == e* ]] || \
116  { [[ "$basequal" == c* ]] && (( $OSnum < 15 )); }; }; then
117  if want_unsupported; then
118  echo "Building unsupported ${basequal} on `uname -s`${OSnum} due to \$CET_BUILD_UNSUPPORTED=${CET_BUILD_UNSUPPORTED}"
119  else
120  # Don't normally support GCC builds on MacOS.
121  msg="${basequal} build not supported on `uname -s`${OSnum} -- export CET_BUILD_UNSUPPORTED=1 to override."
122  echo "$msg"
123  echo "$msg" > "${working_dir}/copyBack/skipping_build"
124  exit 0
125  fi
126  fi
127  if have_label py2; then
128  msg="We are not building for Python2 on Darwin."
129  echo "${msg}"
130  echo "${msg}" > "${working_dir}/copyBack/skipping_build"
131  exit 0
132  fi
133 elif [[ "${flvr}" == slf6 ]]; then
134  if have_label py2; then
135  echo "Building for supported Python2 on SLF6"
136  else
137  if [[ "$basequal" != e17 ]] && [[ "$basequal" != c2 ]]; then
138  msg="Python3 builds not supported on SLF6."
139  echo "${msg}"
140  echo "${msg}" > "${working_dir}/copyBack/skipping_build"
141  exit 0
142  fi
143  fi
144 fi
145 
146 dotver=`echo ${version} | sed -e 's/_/./g' | sed -e 's/^v//'`
147 
148 echo "building the larsoft distribution for ${version} ${dotver} ${qual_set} ${build_type}"
149 echo "build flavor is ${flvr}"
150 echo ""
151 
152 qualdir=`echo ${qual_set} | sed -e 's%:%-%'`
153 
154 set -x
155 
156 blddir=${working_dir}/build
157 srcdir=${working_dir}/source
158 # start with clean directories
159 rm -rf ${blddir}
160 rm -rf ${srcdir}
161 # now make the dfirectories
162 mkdir -p ${srcdir} || exit 1
163 mkdir -p ${blddir} || exit 1
164 
165 buildFW="${working_dir}/artutilscripts/tools/buildFW"
166 
167 cd ${blddir} || exit 1
168 
169 if [ -z "${buildFW}" ]; then
170  curl --fail --silent --location --insecure -O http://scisoft.fnal.gov/scisoft/bundles/tools/buildFW || exit 1
171  chmod +x buildFW
172  buildFW="${blddir}/buildFW"
173 fi
174 
175 cd ${blddir} || exit 1
176 echo
177 echo "begin build"
178 echo
179 (( ${#labels[@]} > 0 )) && lopt=-l
180 ${buildFW} -t -b ${basequal} \
181  ${lopt} $(IFS=:; printf '%s' "${labels[*]}") \
182  ${blddir} ${build_type} lar_product_stack-${version} || \
183  { mv ${blddir}/*.log "${working_dir}/copyBack/"
184  exit 1
185  }
186 ${buildFW} -t -b ${basequal} -s ${squal} \
187  ${lopt} $(IFS=:; printf '%s' "${labels[*]}") \
188  ${blddir} ${build_type} larbase-${version} || \
189  { mv ${blddir}/*.log "${working_dir}/copyBack/"
190  exit 1
191  }
192 ${buildFW} -t -b ${basequal} -s ${squal} \
193  ${lopt} $(IFS=:; printf '%s' "${labels[*]}") \
194  ${blddir} ${build_type} larsoft-${version} || \
195  { mv ${blddir}/*.log "${working_dir}/copyBack/"
196  exit 1
197  }
198 # larsoftobj
199 objver=`ls larsoftobj-cfg* | cut -f3 -d"-" | sed -e 's/\./_/g'`
200 ${buildFW} -t -b ${basequal} \
201  ${lopt} $(IFS=:; printf '%s' "${labels[*]}") \
202  ${blddir} ${build_type} larsoftobj-${objver} || \
203  { mv ${blddir}/*.log "${working_dir}/copyBack/"
204  exit 1
205  }
206 # larwire
207 wirever=`grep larwirecell larsoft-cfg-${dotver} | cut -f5 -d" "`
208 wiredotver=`echo ${wirever} | sed -e 's/_/./g' | sed -e 's/^v//'`
209 have_wirecfg="yes"
210 cfgfile=http://scisoft.fnal.gov/scisoft/bundles/larwire/${wirever}/buildcfg/larwire-cfg-${wiredotver}
211 echo "looking for ${cfgfile}"
212 curl --fail --silent --location --insecure -O ${cfgfile} || have_wirecfg="no"
213 echo "have_wirecfg is ${have_wirecfg}"
214 if [[ ${have_wirecfg} == "yes" ]]; then
215  echo "building larwire ${wirever}"
216  ${buildFW} -t -b ${basequal} -s ${squal} \
217  ${lopt} $(IFS=:; printf '%s' "${labels[*]}") \
218  ${blddir} ${build_type} larwire-${wirever} || \
219  { mv ${blddir}/*.log "${working_dir}/copyBack/"
220  exit 1
221  }
222 else
223  echo "skipping larwire build"
224 fi
225 
226 echo
227 echo "move files"
228 echo
229 # get these out of the way
230 mv ${blddir}/*source* ${srcdir}/
231 mv ${blddir}/g*noarch* ${srcdir}/
232 mv ${blddir}/larsoft_data*.bz2 ${srcdir}/
233 #
234 mv ${blddir}/*.bz2 "${working_dir}/copyBack/"
235 mv ${blddir}/*.txt "${working_dir}/copyBack/"
236 rm -rf ${srcdir}
237 rm -rf ${blddir}
238 
239 exit 0