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