build-edep-sim.sh
Go to the documentation of this file.
1 #!/bin/bash
2 
3 # build edep-sim
4 # input variables:
5 # EDEPSIMVERSION -- matches tag name in Clark McGrew's github
6 # VERSIONSUFFIX -- to append to the github tag to make our tag
7 # QUAL -- compiler, e.g. e17, e19, e20, c2, c7
8 # BUILDTYPE -- debug or prof
9 # GEANT4VERSION -- tag for setting up GEANT4
10 # ROOTVERSION -- tag for setting up ROOT
11 # WORKSPACE -- from Jenkins
12 # COMPILERQUAL_LIST -- list of all the compiler qualifiers (space separated)
13 # EXTRAROOTQUALIFIERS -- to fully specify ROOT. Needs a colon at the beginning so it can be
14 # added to an existing qualifier string. e.g. ":p383"
15 
16 PRODUCT_NAME=edepsim
17 
18 # designed to work on Jenkins
19 
20 # for checking out from Clark McGrew's github repo
21 
22 echo "edep-sim github version: $EDEPSIMVERSION"
23 
24 echo "version suffix: $VERSIONSUFFIX"
25 
26 echo "GEANT4 version: $GEANT4VERSION"
27 
28 echo "ROOT version: $ROOTVERSION"
29 
30 # -- the base qualifier is only the compiler version qualifier: e.g. "e15"
31 
32 echo "base qualifiers (compiler): $QUAL"
33 
34 echo "extra root qualifiers: $EXTRAROOTQUALFIERS"
35 echo "these need a colon before but not after"
36 
37 # note -- this script knows about the correspondence between compiler qualifiers and compiler versions.
38 # there is another if-block later on with the same information (apologies for the duplication). If a new compiler
39 # version is added here, it must also be added where CV is set.
40 
41 COMPILERVERS=unknown
42 COMPILERCOMMAND=unknown
43 CCOMPILER=unknown
44 if [ $QUAL = e14 ]; then
45  COMPILERVERS="gcc v6_3_0"
46  COMPILERCOMMAND=g++
47  CCOMPILER=gcc
48 elif [ $QUAL = e15 ]; then
49  COMPILERVERS="gcc v6_4_0"
50  COMPILERCOMMAND=g++
51  CCOMPILER=gcc
52 elif [ $QUAL = e17 ]; then
53  COMPILERVERS="gcc v7_3_0"
54  COMPILERCOMMAND=g++
55  CCOMPILER=gcc
56 elif [ $QUAL = c2 ]; then
57  COMPILERVERS="clang v5_0_1"
58  COMPILERCOMMAND=clang++
59  CCOMPILER=clang
60 elif [ $QUAL = e19 ]; then
61  COMPILERVERS="gcc v8_2_0"
62  COMPILERCOMMAND=g++
63  CCOMPILER=gcc
64 elif [ $QUAL = e20 ]; then
65  COMPILERVERS="gcc v9_3_0"
66  COMPILERCOMMAND=g++
67  CCOMPILER=gcc
68 elif [ $QUAL = c7 ]; then
69  COMPILERVERS="clang v7_0_0"
70  COMPILERCOMMAND=clang++
71  CCOMPILER=clang
72 fi
73 
74 echo "Compiler and version string: " $COMPILERVERS
75 echo "C++ Compiler command: " $COMPILERCOMMAND
76 echo "C Compiler command: " $CCOMPILER
77 
78 echo "COMPILERQUAL_LIST: " $COMPILERQUAL_LIST
79 
80 if [ "$COMPILERVERS" = unknown ]; then
81  echo "unknown compiler flag: $QUAL"
82  exit 1
83 fi
84 
85 # -- prof or debug
86 
87 echo "build type: $BUILDTYPE"
88 echo "workspace: $WORKSPACE"
89 
90 # Environment setup; look in CVMFS first
91 
92 if [ -f /cvmfs/dune.opensciencegrid.org/products/dune/setup_dune.sh ]; then
93  source /cvmfs/dune.opensciencegrid.org/products/dune/setup_dune.sh || exit 1
94 elif [ -f /grid/fermiapp/products/dune/setup_dune_fermiapp.sh ]; then
95  source /grid/fermiapp/products/dune/setup_dune_fermiapp.sh || exit 1
96 else
97  echo "No setup file found."
98  exit 1
99 fi
100 
101 setup -B cetbuildtools v7_15_01 || exit 1
102 setup -B root ${ROOTVERSION} -q ${QUAL}${EXTRAROOTQUALIFIERS}:${BUILDTYPE} || exit 1
103 setup -B geant4 ${GEANT4VERSION} -q ${QUAL}:${BUILDTYPE} || exit 1
104 
105 # Use system git on macos, and the one in ups for linux
106 
107 if ! uname | grep -q Darwin; then
108  setup git || exit 1
109 fi
110 
111 rm -rf $WORKSPACE/temp || exit 1
112 mkdir -p $WORKSPACE/temp || exit 1
113 mkdir -p $WORKSPACE/copyBack || exit 1
114 rm -f $WORKSPACE/copyBack/* || exit 1
115 cd $WORKSPACE/temp || exit 1
116 CURDIR=`pwd`
117 
118 # change all dots to underscores, and capital V's to little v's in the version string
119 # add our own suffix as the compiler version moves more rapidly than the product version
120 
121 VERSION=v`echo ${EDEPSIMVERSION} | sed -e "s/\./_/g"`${VERSIONSUFFIX}
122 
123 LINDAR=linux
124 FLAVOR=`ups flavor -4`
125 if [ `uname` = Darwin ]; then
126  FLAVOR=`ups flavor -2`
127  LINDAR=darwin
128 fi
129 
130 touch ${PRODUCT_NAME} || exit 1
131 rm -rf ${PRODUCT_NAME} || exit 1
132 touch inputdir || exit 1
133 rm -rf inputdir || exit 1
134 mkdir -p ${PRODUCT_NAME}/${VERSION}/source || exit 1
135 mkdir ${PRODUCT_NAME}/${VERSION}/include || exit 1
136 mkdir ${PRODUCT_NAME}/${VERSION}/ups || exit 1
137 mkdir ${PRODUCT_NAME}/${VERSION}/share || exit 1
138 
139 # in the table, add ROOT and GEANT4 required setups
140 
141 TABLEFILENAME=${PRODUCT_NAME}/${VERSION}/ups/${PRODUCT_NAME}.table
142 touch ${TABLEFILENAME} || exit 1
143 rm -f ${TABLEFILENAME} || exit 1
144 cat > ${TABLEFILENAME} <<EOF
145 File=Table
146 Product=edepsim
147 
148 #*************************************************
149 # Starting Group definition
150 Group:
151 
152 EOF
153 
154 for CQ in $COMPILERQUAL_LIST; do
155  touch tablefrag.txt || exit 1
156  rm -f tablefrag.txt || exit 1
157  cat > tablefrag.txt <<'EOF'
158 
159 Flavor=ANY
160 Qualifiers=QUALIFIER_REPLACE_STRING:debug
161 
162  Action=DefineFQ
163  envSet (EDEPSIM_FQ_DIR, ${UPS_PROD_DIR}/${UPS_PROD_FLAVOR}-QUALIFIER_REPLACE_STRING-debug)
164 
165  Action = ExtraSetup
166  setupRequired( COMPILERVERS_REPLACE_STRING )
167  setupRequired( geant4 GEANT4VERS_REPLACE_STRING -q QUALIFIER_REPLACE_STRING:debug )
168  setupRequired( root ROOTVERS_REPLACE_STRING -q QUALIFIER_REPLACE_STRINGROOTEXTRAQUALS_RS:debug )
169 
170 Flavor=ANY
171 Qualifiers=QUALIFIER_REPLACE_STRING:prof
172 
173  Action=DefineFQ
174  envSet (EDEPSIM_FQ_DIR, ${UPS_PROD_DIR}/${UPS_PROD_FLAVOR}-QUALIFIER_REPLACE_STRING-prof)
175 
176  Action = ExtraSetup
177  setupRequired( COMPILERVERS_REPLACE_STRING )
178  setupRequired( geant4 GEANT4VERS_REPLACE_STRING -q QUALIFIER_REPLACE_STRING:prof )
179  setupRequired( root ROOTVERS_REPLACE_STRING -q QUALIFIER_REPLACE_STRINGROOTEXTRAQUALS_RS:prof )
180 
181 EOF
182 
183 CV=unknown
184 if [ $CQ = e14 ]; then
185  CV="gcc v6_3_0"
186 elif [ $CQ = e15 ]; then
187  CV="gcc v6_4_0"
188 elif [ $CQ = e17 ]; then
189  CV="gcc v7_3_0"
190 elif [ $CQ = c2 ]; then
191  CV="clang v5_0_1"
192 elif [ $CQ = e19 ]; then
193  CV="gcc v8_2_0"
194 elif [ $CQ = e20 ]; then
195  CV="gcc v9_3_0"
196 elif [ $CQ = c7 ]; then
197  CV="clang v7_0_0"
198 fi
199 if [ "$CV" = unknown ]; then
200  echo "unknown compiler flag in COMPILERQUAL_LIST : $CQ"
201  exit 1
202 fi
203 
204 sed -e "s/QUALIFIER_REPLACE_STRING/${CQ}/g" < tablefrag.txt \
205  | sed -e "s/COMPILERVERS_REPLACE_STRING/${CV}/g" \
206  | sed -e "s/GEANT4VERS_REPLACE_STRING/${GEANT4VERSION}/g" \
207  | sed -e "s/ROOTVERS_REPLACE_STRING/${ROOTVERSION}/g" \
208  | sed -e "s/ROOTEXTRAQUALS_RS/${EXTRAROOTQUALIFIERS}/g" \
209  >> ${TABLEFILENAME} || exit 1
210 rm -f tablefrag.txt || exit 1
211 
212 done
213 
214 cat >> ${TABLEFILENAME} <<'EOF'
215 Common:
216  Action=setup
217  setupenv()
218  proddir()
219  ExeActionRequired(DefineFQ)
220  envSet(EDEPSIM_DIR, ${UPS_PROD_DIR})
221  envSet(EDEPSIM_ROOT, ${UPS_PROD_DIR})
222  envSet(EDEPSIM_VERSION, ${UPS_PROD_VERSION})
223  envSet(EDEPSIM_INC, ${EDEPSIM_DIR}/include)
224  envSet(EDEPSIM_SHARE, ${EDEPSIM_DIR}/share)
225  envSet(EDEPSIM_LIB, ${EDEPSIM_FQ_DIR}/lib)
226  # add the lib directory to LD_LIBRARY_PATH
227  if ( test `uname` = "Darwin" )
228  envPrepend(DYLD_LIBRARY_PATH, ${EDEPSIM_FQ_DIR}/lib)
229  else()
230  envPrepend(LD_LIBRARY_PATH, ${EDEPSIM_FQ_DIR}/lib)
231  endif ( test `uname` = "Darwin" )
232  # add the bin directory to the path if it exists
233  if ( sh -c 'for dd in bin;do [ -d ${EDEPSIM_FQ_DIR}/$dd ] && exit;done;exit 1' )
234  pathPrepend(PATH, ${EDEPSIM_FQ_DIR}/bin )
235  else ()
236  execute( true, NO_UPS_ENV )
237  endif ( sh -c 'for dd in bin;do [ -d ${EDEPSIM_FQ_DIR}/$dd ] && exit;done;exit 1' )
238  # useful variables
239  pathPrepend(ROOT_INCLUDE_PATH, ${EDEPSIM_DIR}/include/EDepSim )
240 # envPrepend(CMAKE_PREFIX_PATH, ${EDEPSIM_DIR} ) figure out what to do here
241 # envPrepend(PKG_CONFIG_PATH, ${EDEPSIM_DIR} )
242  # requirements
243  exeActionRequired(ExtraSetup)
244 End:
245 # End Group definition
246 #*************************************************
247 
248 EOF
249 
250 mkdir installdir || exit 1
251 mkdir builddir || exit 1
252 mkdir inputdir || exit 1
253 cd inputdir
254 git clone https://github.com/DUNE/edep-sim.git || exit 1
255 cd edep-sim || exit 1
256 git checkout tags/${EDEPSIMVERSION} || exit 1
257 
258 # copy all the source to the install directory
259 
260 cp -R -L * ${CURDIR}/${PRODUCT_NAME}/${VERSION}/source || exit 1
261 
262 DIRNAME=${CURDIR}/${PRODUCT_NAME}/${VERSION}/${FLAVOR}-${QUAL}-${BUILDTYPE}
263 mkdir -p ${DIRNAME} || exit 1
264 rm -rf ${DIRNAME}/* || exit 1
265 mkdir ${DIRNAME}/bin || exit 1
266 mkdir ${DIRNAME}/lib || exit 1
267 mkdir ${DIRNAME}/share || exit 1
268 mkdir ${DIRNAME}/include || exit 1
269 
270 cd ${CURDIR}/builddir
271 
272 CFLAGS="-O3"
273 if [ $BUILDTYPE = "debug" ]; then
274 CFLAGS="-O0"
275 fi
276 echo "Compiler flags: " $CFLAGS
277 
278 cmake -DCMAKE_C_COMPILER=${CCOMPILER} -DCMAKE_C_FLAGS=${CFLAGS} -DCMAKE_CXX_COMPILER=${COMPILERCOMMAND} -DCMAKE_CXX_FLAGS=${CFLAGS} -DCMAKE_INSTALL_PREFIX=${CURDIR}/installdir ${CURDIR}/inputdir/edep-sim
279 
280 make -j4 || exit 1
281 # make doc || exit 1
282 make install || exit 1
283 
284 cd ${CURDIR} || exit 1
285 cp -r installdir/lib/* ${DIRNAME}/lib
286 cp -r installdir/bin/* ${DIRNAME}/bin
287 cp -r installdir/share/* ${DIRNAME}/../share
288 cp -r installdir/include/* ${DIRNAME}/../include
289 # duplicate in the flavored versions in case cmake files assume include is flavored.
290 cp -r installdir/share/* ${DIRNAME}/share
291 cp -r installdir/include/* ${DIRNAME}/include
292 
293 # for testing the tarball, remove so we keep .upsfiles as is when
294 # unwinding into a real products area
295 
296 mkdir .upsfiles || exit 1
297 cat <<EOF > .upsfiles/dbconfig
298 FILE = DBCONFIG
299 AUTHORIZED_NODES = *
300 VERSION_SUBDIR = 1
301 PROD_DIR_PREFIX = \${UPS_THIS_DB}
302 UPD_USERCODE_DIR = \${UPS_THIS_DB}/.updfiles
303 EOF
304 
305 ups declare ${PRODUCT_NAME} ${VERSION} -f ${FLAVOR} -m ${PRODUCT_NAME}.table -z `pwd` -r ./${PRODUCT_NAME}/${VERSION} -q ${BUILDTYPE}:${QUAL}:${SIMDQUALIFIER} || exit 1
306 
307 rm -rf .upsfiles || exit 1
308 
309 # clean up
310 rm -rf ${CURDIR}/inputdir || exit 1
311 
312 cd ${CURDIR} || exit 1
313 
314 ls -la
315 
316 VERSIONDOTS=`echo ${VERSION} | sed -e "s/_/./g"`
317 SUBDIR=`get-directory-name subdir | sed -e "s/\./-/g"`
318 
319 # use SUBDIR instead of FLAVOR
320 
321 FULLNAME=${PRODUCT_NAME}-${VERSIONDOTS}-${SUBDIR}-${QUAL}-${BUILDTYPE}
322 
323 # strip off the first "v" in the version number
324 
325 FULLNAMESTRIPPED=`echo $FULLNAME | sed -e "s/${PRODUCT_NAME}-v/${PRODUCT_NAME}-/"`
326 
327 rm -rf installdir || exit 1
328 rm -rf builddir || exit 1
329 
330 tar -cjf $WORKSPACE/copyBack/${FULLNAMESTRIPPED}.tar.bz2 . || exit 1
331 
332 ls -l $WORKSPACE/copyBack/
333 cd $WORKSPACE || exit 1
334 rm -rf $WORKSPACE/temp || exit 1
335 
336 exit 0