build-garana.sh
Go to the documentation of this file.
1 #!/bin/bash
2 
3 echo inside garana build script
4 
5 #parameters
6 PROJECT_NAME=garana
7 
8 PROJECT_SOURCE_GIT_PREFIX=${PROJECT_SOURCE_GIT_PREFIX:-'https://github.com/DUNE'}
9 PRODUCTS=${PRODUCTS:-'/cvmfs/larsoft.opensciencegrid.org/products/root'}
10 
11 ROOT_VERSION=${ROOT_VERSION:-"v6_22_06"}
12 
13 #main script
14 PRODUCTS=$(for d in $(echo $PRODUCTS | tr ":" " "); do [[ -d $d ]] && echo -n "$d:"; done)
15 PRODUCTS=${PRODUCTS::-1}
16 export PRODUCTS
17 
18 PROJECT_SOURCE_GIT=${PROJECT_SOURCE_GIT:-${PROJECT_SOURCE_GIT_PREFIX}/${PROJECT_NAME}$( [[ ${PROJECT_SOURCE_GIT_PREFIX} =~ github ]] && echo ".git")}
19 
20 usage() {
21  cat 1>&2 <<EOF
22 Usage: $(basename ${0}) [-h]
23  $(basename ${0}) <branchtag> <qual_set> <buildtype>
24  WORKSPACE=<workspace> BRANCHTAG=<develop|master|vN_NN_NN> QUAL=<qualifiers> BUILDTYPE=<debug|prof> $(basename ${0})
25 EOF
26 }
27 
28 echo params set
29 
30 while getopts :h OPT; do
31  case ${OPT} in
32  h)
33  usage
34  exit 1
35  ;;
36  *)
37  usage
38  exit 1
39  esac
40 done
41 shift $(expr $OPTIND - 1)
42 OPTIND=1
43 
44 
45 working_dir="${WORKSPACE:-$(pwd)}"
46 branchtag="${1:-${BRANCHTAG}}"
47 qual_set="${2:-${QUAL}}"
48 build_type="${3:-${BUILDTYPE}}"
49 
50 IFS=':' read -r -a quals <<< "$qual_set"
51 
52 for onequal in "${quals[@]}"; do
53  case ${onequal} in
54  e[679]|e1[0-9]|c[0-9])
55  basequal=${onequal}
56  ;;
57  debug|prof)
58  build_type=${onequal}
59  ;;
60  *)
61  echo "ERROR: unsupported build qualifier \"${onequal}\""
62  usage
63  exit 1
64  esac
65 done
66 
67 
68 qual_set="${basequal}"
69 [[ ! -z "${pyqual+x}" ]] && qual_set="${qual_set}:${pyqual}"
70 qual_set="${qual_set}:${squal}"
71 
72 manifest_qual_set="${squal}:${basequal}"
73 [[ ! -z "${pyqual+x}" ]] && manifest_qual_set="${manifest_qual_set}:${pyqual}"
74 
75 case ${build_type} in
76  debug) build_type_flag="-d" ;;
77  prof) build_type_flag="-p" ;;
78  *)
79  echo "ERROR: build type must be debug or prof"
80  usage
81  exit 1
82 esac
83 
84 echo quals set
85 
86 # Find platform flavor.
87 OS=$(uname)
88 if [ "${OS}" = "Linux" ]
89 then
90  id=$(lsb_release -is)
91  if [ "${id}" = "Ubuntu" ]
92  then
93  flvr=u$(lsb_release -r | sed -e 's/[[:space:]]//g' | cut -f2 -d":" | cut -f1 -d".")
94  else
95  flvr=slf$(lsb_release -r | sed -e 's/[[:space:]]//g' | cut -f2 -d":" | cut -f1 -d".")
96  fi
97 else
98  echo "ERROR: unrecognized operating system ${OS}"
99  exit 1
100 fi
101 
102 
103 echo "build variables"
104 echo " working_dir=${working_dir}"
105 echo " branchtag=${branchtag}"
106 echo " qual_set=${qual_set}"
107 echo " build_type=${build_type}"
108 echo " flvr=${flvr}"
109 
110 
111 #set -x
112 
113 product_name=${PROJECT_NAME//-/_}
114 
115 src_dir=${working_dir}/source
116 build_dir=${working_dir}/build
117 products_dir=${working_dir}/products
118 copyback_dir=${working_dir}/copyBack
119 
120 
121 
122 # start with clean directories
123 rm -rf ${build_dir}
124 rm -rf ${src_dir}
125 rm -rf ${copyback_dir}
126 # now make the dfirectories
127 mkdir -p ${src_dir} || exit 1
128 mkdir -p ${build_dir} || exit 1
129 mkdir -p ${copyback_dir} || exit 1
130 
131 
132 
133 echo
134 echo "checkout source"
135 echo
136 cd ${src_dir} || exit 1
137 git clone ${PROJECT_SOURCE_GIT} ${product_name}
138 cd ${product_name} || exit 1
139 git checkout ${branchtag}
140 
141 
142 
143 echo
144 echo "pull products from scisoft"
145 echo
146 #unset PRODUCTS
147 [[ ! -d ${products_dir} ]] && mkdir -p ${products_dir}
148 cd ${products_dir} || exit 1
149 curl --fail --silent --location --insecure -O http://scisoft.fnal.gov/scisoft/bundles/tools/pullProducts || exit 1
150 curl --fail --silent --location --insecure -O http://scisoft.fnal.gov/scisoft/bundles/tools/pullPackage || exit 1
151 chmod +x pullProducts pullPackage
152 ./pullProducts ${products_dir} ${flvr} root-${root_version} ${manifest_qual_set//:/-} ${build_type} 2>&1 |tee ${products_dir}/pullproducts.log
153 
154 ./pullPackage ${products_dir} sl7 python-v3_7_2 2>&1 |tee -a ${products_dir}/pullProducts.log
155 
156 echo
157 echo "generate manifest using product_deps and pull products from scisoft"
158 echo
159 #unset PRODUCTS
160 source ${products_dir}/setup || exit 1
161 
162 
163 setup python v3_7_2
164 [[ -d ${python3env_dir} ]] && rm -rf ${python3env_dir}
165 python3 -m venv ${python3env_dir}
166 source ${python3env_dir}/bin/activate
167 pip install --upgrade pip
168 pip install pandas
169 
170 local_manifest=${product_name}-current-Linux64bit+3.10-2.17-${manifest_qual_set//:/-}-${build_type}_MANIFEST.txt
171 
172 python3 ${src_dir}/${product_name}/for-jenkins/generate-manifest.py \
173  -p ${src_dir}/${product_name}/ups/product_deps \
174  -m ${products_dir}/${local_manifest} \
175  -q ${qual_set}:${build_type}
176 
177 #sed -i '/windriver/d' ${products_dir}/${local_manifest}
178 
179 cd ${products_dir} || exit 1
180 
181 ./pullProducts -l ${products_dir} ${flvr} ${product_name}-current ${manifest_qual_set//:/-} ${build_type} 2>&1 |tee -a ${products_dir}/pullproducts.log
182 
183 
184 table_qual_set="+${qual_set//:/+:}+:${build_type}"
185 export products_dir
186 
187 cat ${products_dir}/garana/*/ups/garana.table | \
188  sed -n '/+e19:+prof/,/^$/p' | \
189  sed 's/setupRequired(/.\/pullPackage ${products_dir} sl7 /g' | \
190  sed 's/)//g;s/+//g;s/^[ \t]*//;s/[ \t]*$//;/^\s*$/d;s/:/-/g;s/-q//g;s/\(.*\)-/\1 /'| \
191  sort -u | \
192  sed 's/ v/-v/g' | bash
193 
194 unsetup_all
195 
196 echo
197 product_version=$(cat ${src_dir}/${product_name}/ups/product_deps | grep -E "^parent.*${product_name}.*v.*"| grep -Eo "v[0-9]_[0-9]{2}_[0-9]{2}.*")
198 echo "building the ${product_name} distribution for ${product_version} ${qual_set} ${build_type}"
199 echo
200 [[ -d ${build_dir} ]] && rm -rf ${build_dir}
201 [[ ! -d ${build_dir} ]] && mkdir -p ${build_dir}
202 cd ${build_dir} || exit 1
203 source ${products_dir}/setup || exit 1
204 source ${src_dir}/${product_name}/ups/setup_for_development ${build_type_flag} ${qual_set//:/ }
205 export MRB_QUALS="${qual_set}:${build_type}"
206 previnstall_dir=${products_dir}/${product_name}/${product_version}
207 [[ -d ${previnstall_dir} ]] && rm -rf ${previnstall_dir}{,version}
208 
209 buildtool -I "${products_dir}" -pi -j$(nproc) 2>&1 | tee ${build_dir}/build-${product_name}.log || \
210  { mv ${build_dir}/*.log ${copyback_dir}/
211  exit 1
212  }
213 
214 buildtool -t -j$(nproc) 2>&1 | tee ${build_dir}/test-${product_name}.log || \
215  { mv ${build_dir}/*.log ${copyback_dir}/
216  exit 1
217  }
218 
219 echo
220 echo "move files"
221 echo
222 mv ${build_dir}/{*.bz2,*.log} ${copyback_dir}/
223 mv ${products_dir}/*.log ${copyback_dir}/
224 
225 
226 
227 echo
228 echo "cleanup"
229 echo
230 rm -rf "${build_dir}"
231 rm -rf "${src_dir}"
232 
233 exit 0