build-larbase.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 while getopts :h OPT; do
30  case ${OPT} in
31  h)
32  usage
33  exit 1
34  ;;
35  *)
36  usage
37  exit 1
38  esac
39 done
40 shift `expr $OPTIND - 1`
41 OPTIND=1
42 
43 working_dir="${WORKSPACE:-$(pwd)}"
44 version="${1:-${LARVER}}"
45 qual_set="${2:-${QUAL}}"
46 build_type="${3:-${BUILDTYPE}}"
47 
48 oIFS=${IFS}; IFS=:; quals=(${qual_set//-/:}); IFS=$oIFS; unset oIFS
49 labels=()
50 for onequal in "${quals[@]}"; do
51  if [[ "${onequal}" =~ ^([ec])([0-9]+)$ ]]; then
52  basequal=${onequal}
53  elif [[ "${onequal}" =~ ^(s)([1-9][0-9]+)$ ]]; then
54  squal=${onequal}
55  else
56  labels+=${onequal}
57  fi
58 done
59 
60 echo "basequal ${basequal} squal ${squal} labels ${labels}"
61 
62 case ${build_type} in
63  debug) ;;
64  prof) ;;
65  *)
66  usage
67  exit 1
68 esac
69 
70 # create copyBack so artifact copy does not fail on early exit
71 rm -rf "${working_dir}/copyBack"
72 mkdir -p "${working_dir}/copyBack" || exit 1
73 
74 # Find platform flavor.
75 OS=`uname`
76 if [ "${OS}" = "Linux" ]
77 then
78  id=`lsb_release -is`
79  if [ "${id}" = "Ubuntu" ]
80  then
81  flvr=u`lsb_release -r | sed -e 's/[[:space:]]//g' | cut -f2 -d":" | cut -f1 -d"."`
82  else
83  flvr=slf`lsb_release -r | sed -e 's/[[:space:]]//g' | cut -f2 -d":" | cut -f1 -d"."`
84  fi
85 elif [ "${OS}" = "Darwin" ]
86 then
87  flvr=d`uname -r | cut -f1 -d"."`
88  # set locale
89  echo
90  locale
91  echo
92  export LANG=C
93  export LC_ALL=$LANG
94  locale
95  echo
96 else
97  echo "ERROR: unrecognized operating system ${OS}"
98  exit 1
99 fi
100 
101 # Check supported builds.
102 if [[ `uname -s` == Darwin ]]; then
103  OSnum=`uname -r | cut -f1 -d"."`
104  xver=`xcodebuild -version | grep Xcode | cut -f2 -d" " | cut -f1 -d"."`
105  xcver=`xcodebuild -version | grep Xcode`
106  if { [[ ${basequal} =~ ^e(9$|[1-9][0-9]) ]] && \
107  [[ ${xver} < 7 ]] && \
108  [[ ${OSnum} > 13 ]]; }; then
109  # XCode too old on this platform.
110  echo "${basequal} build not supported on `uname -s`${OSnum} with ${xcver}"
111  echo "${basequal} build not supported on `uname -s`${OSnum} with ${xcver}" > \
112  "${working_dir}/copyBack/skipping_build"
113  exit 0
114  elif { [[ "$basequal" == e* ]] || \
115  { [[ "$basequal" == c* ]] && (( $OSnum < 15 )); }; }; then
116  if want_unsupported; then
117  echo "Building unsupported ${basequal} on `uname -s`${OSnum} due to \$CET_BUILD_UNSUPPORTED=${CET_BUILD_UNSUPPORTED}"
118  else
119  # Don't normally support GCC builds on MacOS.
120  msg="${basequal} build not supported on `uname -s`${OSnum} -- export CET_BUILD_UNSUPPORTED=1 to override."
121  echo "$msg"
122  echo "$msg" > "${working_dir}/copyBack/skipping_build"
123  exit 0
124  fi
125  fi
126  if have_label py2; then
127  msg="We are not building for Python2 on Darwin."
128  echo "${msg}"
129  echo "${msg}" > "${working_dir}/copyBack/skipping_build"
130  exit 0
131  fi
132 elif [[ "${flvr}" == slf6 ]]; then
133  msg="We are not building on SLF6."
134  echo "${msg}"
135  echo "${msg}" > "${working_dir}/copyBack/skipping_build"
136  exit 0
137 fi
138 
139 dotver=`echo ${version} | sed -e 's/_/./g' | sed -e 's/^v//'`
140 
141 echo "building the larbase distribution for ${version} ${dotver} ${qual_set} ${build_type}"
142 
143 echo "build flavor is ${flvr}"
144 echo ""
145 
146 qualdir=`echo ${qual_set} | sed -e 's%:%-%'`
147 
148 set -x
149 
150 blddir=${working_dir}/build
151 srcdir=${working_dir}/source
152 # start with clean directories
153 rm -rf ${blddir}
154 rm -rf ${srcdir}
155 # now make the dfirectories
156 mkdir -p ${srcdir} || exit 1
157 mkdir -p ${blddir} || exit 1
158 
159 buildFW="${working_dir}/artutilscripts/tools/buildFW"
160 
161 cd ${blddir} || exit 1
162 
163 if [ -z "${buildFW}" ]; then
164  curl --fail --silent --location --insecure -O http://scisoft.fnal.gov/scisoft/bundles/tools/buildFW || exit 1
165  chmod +x buildFW
166  buildFW="${blddir}/buildFW"
167 fi
168 
169 cd ${blddir} || exit 1
170 echo
171 echo "begin build"
172 echo
173 (( ${#labels[@]} > 0 )) && lopt=-l
174 ${buildFW} -t -b ${basequal} \
175  ${lopt} $(IFS=:; printf '%s' "${labels[*]}") \
176  ${blddir} ${build_type} lar_product_stack-${version} || \
177  { mv ${blddir}/*.log "${working_dir}/copyBack/"
178  exit 1
179  }
180 ${buildFW} -t -b ${basequal} -s ${squal} \
181  ${lopt} $(IFS=:; printf '%s' "${labels[*]}") \
182  ${blddir} ${build_type} larbase-${version} || \
183  { mv ${blddir}/*.log "${working_dir}/copyBack/"
184  exit 1
185  }
186 
187 echo
188 echo "move files"
189 echo
190 # get these out of the way
191 mv ${blddir}/*source* ${srcdir}/
192 mv ${blddir}/g*noarch* ${srcdir}/
193 mv ${blddir}/larsoft_data*.bz2 ${srcdir}/
194 #
195 mv ${blddir}/*.bz2 "${working_dir}/copyBack/"
196 mv ${blddir}/*.txt "${working_dir}/copyBack/"
197 rm -rf ${srcdir}
198 rm -rf ${blddir}
199 
200 exit 0