build_larcv.sh
Go to the documentation of this file.
1 #!/bin/bash
2 
3 #------------------------------------------------------------------
4 #
5 # Name: build_larcv.sh
6 #
7 # Purpose: Build debug and prof flavors of larcv and larlite on Jenkins.
8 #
9 # Created: 4-Aug-2017 H. Greenlee
10 #
11 #------------------------------------------------------------------
12 
13 echo "larcv ups version: $LARCV_VERSION"
14 echo "larcv git tag: $LARCV_TAG"
15 echo "larlite ups version: $LARLITE_VERSION"
16 echo "larlite git tag: $LARLITE_TAG"
17 echo "qualifier: $QUAL"
18 echo "build type: $BUILDTYPE"
19 echo "workspace: $WORKSPACE"
20 
21 # Get number of cores to use.
22 
23 if [ `uname` = Darwin ]; then
24  #ncores=`sysctl -n hw.ncpu`
25  #ncores=$(( $ncores / 4 ))
26  ncores=1
27 else
28  ncores=`cat /proc/cpuinfo 2>/dev/null | grep -c -e '^processor'`
29 fi
30 if [ $ncores -lt 1 ]; then
31  ncores=1
32 fi
33 echo "Building using $ncores cores."
34 
35 # Environment setup, uses /grid/fermiapp or cvmfs.
36 
37 if [ -f /grid/fermiapp/products/uboone/setup_uboone.sh ]; then
38  source /grid/fermiapp/products/uboone/setup_uboone.sh || exit 1
39 elif [ -f /cvmfs/uboone.opensciencegrid.org/products/setup_uboone.sh ]; then
40  if [ -x /cvmfs/grid.cern.ch/util/cvmfs-uptodate ]; then
41  /cvmfs/grid.cern.ch/util/cvmfs-uptodate /cvmfs/uboone.opensciencegrid.org/products
42  fi
43  source /cvmfs/uboone.opensciencegrid.org/products/setup_uboone.sh || exit 1
44 else
45  echo "No setup file found."
46  exit 1
47 fi
48 
49 # Use system git on macos.
50 
51 if ! uname | grep -q Darwin; then
52  setup git || exit 1
53 fi
54 
55 # Set up working area.
56 
57 set -x
58 rm -rf $WORKSPACE/temp || exit 1
59 mkdir -p $WORKSPACE/temp || exit 1
60 mkdir -p $WORKSPACE/copyBack || exit 1
61 rm -f $WORKSPACE/copyBack/* || exit 1
62 cd $WORKSPACE/temp || exit 1
63 export HOME_DIR=`pwd`
64 
65 # Check for supported combination of base qualifier and OS.
66 if [[ `uname -s` == Darwin ]] && [[ $QUAL == e* ]]; then
67  echo "${QUAL} build not supported on `uname -s`"
68  echo "${QUAL} build not supported on `uname -s`" > $WORKSPACE/copyBack/skipping_build
69  exit 0
70 fi
71 
72 set +x
73 
74 # Make an installation directory with relocatable dbconfig file.
75 
76 mkdir -p ${HOME_DIR}/install/.upsfiles
77 cat <<EOF > ${HOME_DIR}/install/.upsfiles/dbconfig
78 FILE = DBCONFIG
79 AUTHORIZED_NODES = *
80 VERSION_SUBDIR = 1
81 PROD_DIR_PREFIX = \${UPS_THIS_DB}
82 UPD_USERCODE_DIR = \${UPS_THIS_DB}/.updfiles
83 EOF
84 
85 # Make source area and check out sources.
86 
87 mkdir -p ${HOME_DIR}/srcs
88 cd ${HOME_DIR}/srcs
89 
90 # Check out larcv.
91 
92 git clone https://github.com/LArbys/LArCV
93 #git clone https://github.com/hgreenlee/LArCV
94 cd LArCV
95 git checkout $LARCV_TAG
96 rm -rf .git
97 cd ..
98 
99 # Check out larlite.
100 
101 git clone https://github.com/larlight/larlite
102 #git clone https://github.com/hgreenlee/larlite
103 cd larlite
104 git checkout $LARLITE_TAG
105 rm -rf .git
106 cd ..
107 
108 # Set up the correct version of gcc.
109 
110 gcc_version=`ups depend -M ${HOME_DIR}/srcs/LArCV/ups -m larcv.table -q ${QUAL}:${BUILDTYPE} larcv | sed -n 's/^.*__\(gcc .*\)$/\1/p'`
111 gcc_version2=`ups depend -M ${HOME_DIR}/srcs/larlite/ups -m larlite.table -q ${QUAL}:${BUILDTYPE} larlite | sed -n 's/^.*__\(gcc .*\)$/\1/p'`
112 if [ "$gcc_version" != "$gcc_version2" ]; then
113  echo "Gcc versions do not match."
114  echo $gcc_version
115  echo $gcc_version2
116  exit 1
117 fi
118 setup $gcc_version
119 
120 # Set up the correct version of root.
121 
122 root_version=`ups depend -M ${HOME_DIR}/srcs/LArCV/ups -m larcv.table -q ${QUAL}:${BUILDTYPE} larcv | sed -n 's/^.*__\(root .*\)$/\1/p'`
123 root_version2=`ups depend -M ${HOME_DIR}/srcs/larlite/ups -m larlite.table -q ${QUAL}:${BUILDTYPE} larlite | sed -n 's/^.*__\(root .*\)$/\1/p'`
124 if [ "$root_version" != "$root_version2" ]; then
125  echo "Root versions do not match."
126  echo $root_version
127  echo $root_version2
128  exit 1
129 fi
130 setup $root_version
131 
132 # Build larlite first.
133 
134 cd ${HOME_DIR}/srcs/larlite
135 source config/setup.sh || exit 1
136 export LARLITE_CXX=g++ # Use g++ instead of clang.
137 make -j$ncores || exit 1
138 
139 # Assemble larlite ups product.
140 
141 install_dir=${HOME_DIR}/install/larlite/$LARLITE_VERSION
142 subdir=`get-directory-name subdir ${QUAL}:${BUILDTYPE}`
143 flavor_dir=${install_dir}/$subdir
144 mkdir -p $flavor_dir
145 cp -r . $flavor_dir
146 cp -r ups $install_dir
147 
148 # Declare larlite ups product in temporary products area.
149 
150 if uname | grep -q Darwin; then
151  flavor=`ups flavor -2`
152 else
153  flavor=`ups flavor -4`
154 fi
155 ups declare -z ${HOME_DIR}/install -r larlite/$LARLITE_VERSION -m larlite.table -f $flavor -q ${QUAL}:${BUILDTYPE} -U ups larlite $LARLITE_VERSION
156 
157 # Make distribution tarball
158 
159 cd ${HOME_DIR}/install
160 dot_version=`echo $LARLITE_VERSION | sed -e 's/_/\./g' | sed -e 's/^v//'`
161 subdir=`echo $subdir | sed -e 's/\./-/g'`
162 #qual=`echo $CETPKG_QUAL | sed -e 's/:/-/g'`
163 tarballname=larlite-${dot_version}-${subdir}.tar.bz2
164 echo "Making ${tarballname}"
165 tar cjf ${HOME_DIR}/${tarballname} larlite
166 
167 # Next build larcv.
168 
169 cd ${HOME_DIR}/srcs/LArCV
170 source configure.sh || exit 1
171 export LARCV_CXX=g++ # Use g++ instead of clang.
172 make -j$ncores || exit 1
173 
174 # Assemble larcv ups product.
175 
176 install_dir=${HOME_DIR}/install/larcv/$LARCV_VERSION
177 subdir=`get-directory-name subdir ${QUAL}:${BUILDTYPE}`
178 flavor_dir=${install_dir}/$subdir
179 mkdir -p $flavor_dir
180 cp -r . $flavor_dir
181 cp -r ups $install_dir
182 
183 # Declare larcv ups product in temporary products area.
184 
185 if uname | grep -q Darwin; then
186  flavor=`ups flavor -2`
187 else
188  flavor=`ups flavor -4`
189 fi
190 ups declare -z ${HOME_DIR}/install -r larcv/$LARCV_VERSION -m larcv.table -f $flavor -q ${QUAL}:${BUILDTYPE} -U ups larcv $LARCV_VERSION
191 
192 # Make distribution tarball
193 
194 cd ${HOME_DIR}/install
195 dot_version=`echo $LARCV_VERSION | sed -e 's/_/\./g' | sed -e 's/^v//'`
196 subdir=`echo $subdir | sed -e 's/\./-/g'`
197 #qual=`echo $CETPKG_QUAL | sed -e 's/:/-/g'`
198 tarballname=larcv-${dot_version}-${subdir}.tar.bz2
199 echo "Making ${tarballname}"
200 tar cjf ${HOME_DIR}/${tarballname} larcv
201 
202 # Save artifacts.
203 
204 mv ${HOME_DIR}/*.bz2 $WORKSPACE/copyBack/ || exit 1
205 ls -l $WORKSPACE/copyBack/
206 cd $WORKSPACE || exit 1
207 #rm -rf $WORKSPACE/temp || exit 1
208 set +x
209 
210 exit 0