11#! /bin/bash
22
3+ # NB: define this function before set -x, so that we don't
4+ # pollute the log with a premature EXITED_USER_LAND ;)
5+ function cleanup {
6+ # Note that if you've exited user land, then CI will conclude that
7+ # any failure is the CI's fault. So we MUST only output this
8+ # string
9+ retcode=$?
10+ set +x
11+ if [ $retcode -eq 0 ]; then
12+ echo " EXITED_USER_LAND"
13+ fi
14+ }
15+
316set -ex
417
518source /etc/lsb-release
@@ -8,6 +21,50 @@ source /etc/lsb-release
821# condition: if 16.04 and conda, conda install pytorch and build
922# condition: if any and non-conda, simply build TC from scratch
1023
24+ # note: printf is used instead of echo to avoid backslash
25+ # processing and to properly handle values that begin with a '-'.
26+ echo " ENTERED_USER_LAND"
27+ log () { printf ' %s\n' " $* " ; }
28+ error () { log " ERROR: $* " >&2 ; }
29+ fatal () { error " $@ " ; exit 1; }
30+
31+ # appends a command to a trap
32+ #
33+ # - 1st arg: code to add
34+ # - remaining args: names of traps to modify
35+ #
36+ trap_add () {
37+ trap_add_cmd=$1 ; shift || fatal " ${FUNCNAME} usage error"
38+ for trap_add_name in " $@ " ; do
39+ trap -- " $(
40+ # helper fn to get existing trap command from output
41+ # of trap -p
42+ extract_trap_cmd () { printf ' %s\n' " $3 " ; }
43+ # print existing trap command with newline
44+ eval " extract_trap_cmd $( trap -p " ${trap_add_name} " ) "
45+ # print the new trap command
46+ printf ' %s\n' " ${trap_add_cmd} "
47+ ) " " ${trap_add_name} " \
48+ || fatal " unable to add to trap ${trap_add_name} "
49+ done
50+ }
51+ # set the trace attribute for the above function. this is
52+ # required to modify DEBUG or RETURN traps because functions don't
53+ # inherit them unless the trace attribute is set
54+ declare -f -t trap_add
55+
56+ trap_add cleanup EXIT
57+
58+ if which ccache > /dev/null; then
59+ # Report ccache stats for easier debugging
60+ ccache --zero-stats
61+ ccache --show-stats
62+ function ccache_epilogue() {
63+ ccache --show-stats
64+ }
65+ trap_add ccache_epilogue EXIT
66+ fi
67+
1168if [[ " $DISTRIB_RELEASE " == 14.04 ]]; then
1269 if [[ $( conda --version | wc -c) -ne 0 ]]; then
1370 echo " Building TC in conda env"
0 commit comments