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