build.sh (12229B)
1 #!/bin/bash 2 3 # Run all the different permutations of all the tests and other things 4 # This helps ensure that nothing gets broken. 5 6 _tests() { 7 local vet="" # TODO: make it off 8 local gover=$( ${gocmd} version | cut -f 3 -d ' ' ) 9 [[ $( ${gocmd} version ) == *"gccgo"* ]] && zcover=0 10 [[ $( ${gocmd} version ) == *"gollvm"* ]] && zcover=0 11 case $gover in 12 go1.[7-9]*|go1.1[0-9]*|go2.*|devel*) true ;; 13 *) return 1 14 esac 15 # note that codecgen requires fastpath, so you cannot do "codecgen codec.notfastpath" 16 # we test the following permutations wnich all execute different code paths as below. 17 echo "TestCodecSuite: (fastpath/unsafe), (!fastpath/unsafe), (fastpath/!unsafe), (!fastpath/!unsafe), (codecgen/unsafe)" 18 local echo=1 19 local nc=2 # count 20 local cpus="1,$(nproc)" 21 # if using the race detector, then set nc to 22 if [[ " ${zargs[@]} " =~ "-race" ]]; then 23 cpus="$(nproc)" 24 fi 25 local a=( "" "codec.notfastpath" "codec.safe" "codec.notfastpath codec.safe" "codecgen" ) 26 local b=() 27 local c=() 28 for i in "${a[@]}" 29 do 30 local i2=${i:-default} 31 [[ "$zwait" == "1" ]] && echo ">>>> TAGS: 'alltests $i'; RUN: 'TestCodecSuite'" 32 [[ "$zcover" == "1" ]] && c=( -coverprofile "${i2// /-}.cov.out" ) 33 true && 34 ${gocmd} vet -printfuncs "errorf" "$@" && 35 if [[ "$echo" == 1 ]]; then set -o xtrace; fi && 36 ${gocmd} test ${zargs[*]} ${ztestargs[*]} -vet "$vet" -tags "alltests $i" -count $nc -cpu $cpus -run "TestCodecSuite" "${c[@]}" "$@" & 37 if [[ "$echo" == 1 ]]; then set +o xtrace; fi 38 b+=("${i2// /-}.cov.out") 39 [[ "$zwait" == "1" ]] && wait 40 41 # if [[ "$?" != 0 ]]; then return 1; fi 42 done 43 if [[ "$zextra" == "1" ]]; then 44 [[ "$zwait" == "1" ]] && echo ">>>> TAGS: 'codec.notfastpath x'; RUN: 'Test.*X$'" 45 [[ "$zcover" == "1" ]] && c=( -coverprofile "x.cov.out" ) 46 ${gocmd} test ${zargs[*]} ${ztestargs[*]} -vet "$vet" -tags "codec.notfastpath x" -count $nc -run 'Test.*X$' "${c[@]}" & 47 b+=("x.cov.out") 48 [[ "$zwait" == "1" ]] && wait 49 fi 50 wait 51 # go tool cover is not supported for gccgo, gollvm, other non-standard go compilers 52 [[ "$zcover" == "1" ]] && 53 command -v gocovmerge && 54 gocovmerge "${b[@]}" > __merge.cov.out && 55 ${gocmd} tool cover -html=__merge.cov.out 56 } 57 58 # is a generation needed? 59 _ng() { 60 local a="$1" 61 if [[ ! -e "$a" ]]; then echo 1; return; fi 62 for i in `ls -1 *.go.tmpl gen.go values_test.go` 63 do 64 if [[ "$a" -ot "$i" ]]; then echo 1; return; fi 65 done 66 } 67 68 _prependbt() { 69 cat > ${2} <<EOF 70 // +build generated 71 72 EOF 73 cat ${1} >> ${2} 74 rm -f ${1} 75 } 76 77 # _build generates fast-path.go and gen-helper.go. 78 _build() { 79 if ! [[ "${zforce}" || $(_ng "fast-path.generated.go") || $(_ng "gen-helper.generated.go") || $(_ng "gen.generated.go") ]]; then return 0; fi 80 81 if [ "${zbak}" ]; then 82 _zts=`date '+%m%d%Y_%H%M%S'` 83 _gg=".generated.go" 84 [ -e "gen-helper${_gg}" ] && mv gen-helper${_gg} gen-helper${_gg}__${_zts}.bak 85 [ -e "fast-path${_gg}" ] && mv fast-path${_gg} fast-path${_gg}__${_zts}.bak 86 [ -e "gen${_gg}" ] && mv gen${_gg} gen${_gg}__${_zts}.bak 87 fi 88 rm -f gen-helper.generated.go fast-path.generated.go gen.generated.go \ 89 *safe.generated.go *_generated_test.go *.generated_ffjson_expose.go 90 91 cat > gen.generated.go <<EOF 92 // +build codecgen.exec 93 94 // Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. 95 // Use of this source code is governed by a MIT license found in the LICENSE file. 96 97 package codec 98 99 // DO NOT EDIT. THIS FILE IS AUTO-GENERATED FROM gen-dec-(map|array).go.tmpl 100 101 const genDecMapTmpl = \` 102 EOF 103 cat >> gen.generated.go < gen-dec-map.go.tmpl 104 cat >> gen.generated.go <<EOF 105 \` 106 107 const genDecListTmpl = \` 108 EOF 109 cat >> gen.generated.go < gen-dec-array.go.tmpl 110 cat >> gen.generated.go <<EOF 111 \` 112 113 const genEncChanTmpl = \` 114 EOF 115 cat >> gen.generated.go < gen-enc-chan.go.tmpl 116 cat >> gen.generated.go <<EOF 117 \` 118 EOF 119 cat > gen-from-tmpl.codec.generated.go <<EOF 120 package codec 121 func GenRunTmpl2Go(in, out string) { genRunTmpl2Go(in, out) } 122 func GenRunSortTmpl2Go(in, out string) { genRunSortTmpl2Go(in, out) } 123 EOF 124 125 # stub xxxRv and xxxRvSlice creation, before you create it 126 cat > gen-from-tmpl.sort-slice-stubs.generated.go <<EOF 127 // +build codecgen.sort_slice 128 129 package codec 130 131 import "reflect" 132 import "time" 133 134 EOF 135 136 for i in string bool uint64 int64 float64 bytes time; do 137 local i2=$i 138 case $i in 139 'time' ) i2="time.Time";; 140 'bytes' ) i2="[]byte";; 141 esac 142 143 cat >> gen-from-tmpl.sort-slice-stubs.generated.go <<EOF 144 type ${i}Rv struct { v ${i2}; r reflect.Value } 145 146 type ${i}RvSlice []${i}Rv 147 148 func (${i}RvSlice) Len() int { return 0 } 149 func (${i}RvSlice) Less(i, j int) bool { return false } 150 func (${i}RvSlice) Swap(i, j int) {} 151 152 type ${i}Intf struct { v ${i2}; i interface{} } 153 154 type ${i}IntfSlice []${i}Intf 155 156 func (${i}IntfSlice) Len() int { return 0 } 157 func (${i}IntfSlice) Less(i, j int) bool { return false } 158 func (${i}IntfSlice) Swap(i, j int) {} 159 160 EOF 161 done 162 163 sed -e 's+// __DO_NOT_REMOVE__NEEDED_FOR_REPLACING__IMPORT_PATH__FOR_CODEC_BENCH__+import . "github.com/ugorji/go/codec"+' \ 164 shared_test.go > bench/shared_test.go 165 166 # explicitly return 0 if this passes, else return 1 167 local btags="codec.notfastpath codec.safe codecgen.exec" 168 rm -f sort-slice.generated.go fast-path.generated.go gen-helper.generated.go mammoth_generated_test.go mammoth2_generated_test.go 169 170 cat > gen-from-tmpl.sort-slice.generated.go <<EOF 171 // +build ignore 172 173 package main 174 175 import "${zpkg}" 176 177 func main() { 178 codec.GenRunSortTmpl2Go("sort-slice.go.tmpl", "sort-slice.generated.go") 179 } 180 EOF 181 182 ${gocmd} run -tags "$btags codecgen.sort_slice" gen-from-tmpl.sort-slice.generated.go || return 1 183 rm -f gen-from-tmpl.sort-slice.generated.go 184 185 cat > gen-from-tmpl.generated.go <<EOF 186 // +build ignore 187 188 package main 189 190 import "${zpkg}" 191 192 func main() { 193 codec.GenRunTmpl2Go("fast-path.go.tmpl", "fast-path.generated.go") 194 codec.GenRunTmpl2Go("gen-helper.go.tmpl", "gen-helper.generated.go") 195 codec.GenRunTmpl2Go("mammoth-test.go.tmpl", "mammoth_generated_test.go") 196 codec.GenRunTmpl2Go("mammoth2-test.go.tmpl", "mammoth2_generated_test.go") 197 } 198 EOF 199 200 ${gocmd} run -tags "$btags" gen-from-tmpl.generated.go || return 1 201 rm -f gen-from-tmpl.generated.go 202 203 rm -f gen-from-tmpl.*generated.go 204 return 0 205 } 206 207 _codegenerators() { 208 local c5="_generated_test.go" 209 local c7="$PWD/codecgen" 210 local c8="$c7/__codecgen" 211 local c9="codecgen-scratch.go" 212 213 if ! [[ $zforce || $(_ng "values_codecgen${c5}") ]]; then return 0; fi 214 215 # Note: ensure you run the codecgen for this codebase/directory i.e. ./codecgen/codecgen 216 true && 217 echo "codecgen ... " && 218 if [[ $zforce || ! -f "$c8" || "$c7/gen.go" -nt "$c8" ]]; then 219 echo "rebuilding codecgen ... " && ( cd codecgen && ${gocmd} build -o $c8 ${zargs[*]} . ) 220 fi && 221 $c8 -rt 'codecgen' -t 'codecgen generated' -o "values_codecgen${c5}" -d 19780 "$zfin" "$zfin2" && 222 cp mammoth2_generated_test.go $c9 && 223 $c8 -t 'codecgen,!codec.notfastpath,!codec.notmammoth generated,!codec.notfastpath,!codec.notmammoth' -o "mammoth2_codecgen${c5}" -d 19781 "mammoth2_generated_test.go" && 224 rm -f $c9 && 225 echo "generators done!" 226 } 227 228 _prebuild() { 229 echo "prebuild: zforce: $zforce" 230 local d="$PWD" 231 local zfin="test_values.generated.go" 232 local zfin2="test_values_flex.generated.go" 233 local zpkg="github.com/ugorji/go/codec" 234 local returncode=1 235 236 # zpkg=${d##*/src/} 237 # zgobase=${d%%/src/*} 238 # rm -f *_generated_test.go 239 rm -f codecgen-*.go && 240 _build && 241 cp $d/values_test.go $d/$zfin && 242 cp $d/values_flex_test.go $d/$zfin2 && 243 _codegenerators && 244 if [[ "$(type -t _codegenerators_external )" = "function" ]]; then _codegenerators_external ; fi && 245 if [[ $zforce ]]; then ${gocmd} install ${zargs[*]} .; fi && 246 returncode=0 && 247 echo "prebuild done successfully" 248 rm -f $d/$zfin $d/$zfin2 249 return $returncode 250 # unset zfin zfin2 zpkg 251 } 252 253 _make() { 254 local makeforce=${zforce} 255 zforce=1 256 (cd codecgen && ${gocmd} install ${zargs[*]} .) && _prebuild && ${gocmd} install ${zargs[*]} . 257 zforce=${makeforce} 258 } 259 260 _clean() { 261 rm -f \ 262 gen-from-tmpl.*generated.go \ 263 codecgen-*.go \ 264 test_values.generated.go test_values_flex.generated.go 265 } 266 267 _release() { 268 local reply 269 read -p "Pre-release validation takes a few minutes and MUST be run from within GOPATH/src. Confirm y/n? " -n 1 -r reply 270 echo 271 if [[ ! $reply =~ ^[Yy]$ ]]; then return 1; fi 272 273 # expects GOROOT, GOROOT_BOOTSTRAP to have been set. 274 if [[ -z "${GOROOT// }" || -z "${GOROOT_BOOTSTRAP// }" ]]; then return 1; fi 275 # (cd $GOROOT && git checkout -f master && git pull && git reset --hard) 276 (cd $GOROOT && git pull) 277 local f=`pwd`/make.release.out 278 cat > $f <<EOF 279 ========== `date` =========== 280 EOF 281 # # go 1.6 and below kept giving memory errors on Mac OS X during SDK build or go run execution, 282 # # that is fine, as we only explicitly test the last 3 releases and tip (2 years). 283 local makeforce=${zforce} 284 zforce=1 285 for i in 1.10 1.11 1.12 master 286 do 287 echo "*********** $i ***********" >>$f 288 if [[ "$i" != "master" ]]; then i="release-branch.go$i"; fi 289 (false || 290 (echo "===== BUILDING GO SDK for branch: $i ... =====" && 291 cd $GOROOT && 292 git checkout -f $i && git reset --hard && git clean -f . && 293 cd src && ./make.bash >>$f 2>&1 && sleep 1 ) ) && 294 echo "===== GO SDK BUILD DONE =====" && 295 _prebuild && 296 echo "===== PREBUILD DONE with exit: $? =====" && 297 _tests "$@" 298 if [[ "$?" != 0 ]]; then return 1; fi 299 done 300 zforce=${makeforce} 301 echo "++++++++ RELEASE TEST SUITES ALL PASSED ++++++++" 302 } 303 304 _usage() { 305 # hidden args: 306 # -pf [p=prebuild (f=force)] 307 308 cat <<EOF 309 primary usage: $0 310 -t[esow] -> t=tests [e=extra, s=short, o=cover, w=wait] 311 -[md] -> [m=make, d=race detector] 312 -[n l i] -> [n=inlining diagnostics, l=mid-stack inlining, i=check inlining for path (path)] 313 -v -> v=verbose 314 EOF 315 if [[ "$(type -t _usage_run)" = "function" ]]; then _usage_run ; fi 316 } 317 318 _main() { 319 if [[ -z "$1" ]]; then _usage; return 1; fi 320 local x # determines the main action to run in this build 321 local zforce # force 322 local zcover # generate cover profile and show in browser when done 323 local zwait # run tests in sequence, not parallel ie wait for one to finish before starting another 324 local zextra # means run extra (python based tests, etc) during testing 325 326 local ztestargs=() 327 local zargs=() 328 local zverbose=() 329 local zbenchflags="" 330 331 local gocmd=${MYGOCMD:-go} 332 333 OPTIND=1 334 while getopts ":cetmnrgpfvldsowkxyzi" flag 335 do 336 case "x$flag" in 337 'xo') zcover=1 ;; 338 'xe') zextra=1 ;; 339 'xw') zwait=1 ;; 340 'xf') zforce=1 ;; 341 'xs') ztestargs+=("-short") ;; 342 'xv') zverbose+=(1) ;; 343 'xl') zargs+=("-gcflags"); zargs+=("-l=4") ;; 344 'xn') zargs+=("-gcflags"); zargs+=("-m=2") ;; 345 'xd') zargs+=("-race") ;; 346 # 'xi') x='i'; zbenchflags=${OPTARG} ;; 347 x\?) _usage; return 1 ;; 348 *) x=$flag ;; 349 esac 350 done 351 shift $((OPTIND-1)) 352 # echo ">>>> _main: extra args: $@" 353 case "x$x" in 354 'xt') _tests "$@" ;; 355 'xm') _make "$@" ;; 356 'xr') _release "$@" ;; 357 'xg') _go ;; 358 'xp') _prebuild "$@" ;; 359 'xc') _clean "$@" ;; 360 'xx') _analyze_checks "$@" ;; 361 'xy') _analyze_debug_types "$@" ;; 362 'xz') _analyze_do_inlining_and_more "$@" ;; 363 'xk') _go_compiler_validation_suite ;; 364 'xi') _check_inlining_one "$@" ;; 365 esac 366 # unset zforce zargs zbenchflags 367 } 368 369 [ "." = `dirname $0` ] && _main "$@" 370