|
4 | 4 | set -ex
|
5 | 5 | SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
6 | 6 |
|
| 7 | +# Courtesy of pytorch/.jenkins/pytorch/common_utils.sh |
| 8 | +# |
| 9 | +# - 1st arg: code to add |
| 10 | +# - remaining args: names of traps to modify |
| 11 | +# |
| 12 | +trap_add() { |
| 13 | + trap_add_cmd=$1; shift || fatal "${FUNCNAME[0]} usage error" |
| 14 | + for trap_add_name in "$@"; do |
| 15 | + trap -- "$( |
| 16 | + # helper fn to get existing trap command from output |
| 17 | + # of trap -p |
| 18 | + extract_trap_cmd() { printf '%s\n' "$3"; } |
| 19 | + # print existing trap command with newline |
| 20 | + eval "extract_trap_cmd $(trap -p "${trap_add_name}")" |
| 21 | + # print the new trap command |
| 22 | + printf '%s\n' "${trap_add_cmd}" |
| 23 | + )" "${trap_add_name}" \ |
| 24 | + || fatal "unable to add to trap ${trap_add_name}" |
| 25 | + done |
| 26 | +} |
| 27 | +# set the trace attribute for the above function. this is |
| 28 | +# required to modify DEBUG or RETURN traps because functions don't |
| 29 | +# inherit them unless the trace attribute is set |
| 30 | +declare -f -t trap_add |
| 31 | + |
| 32 | +# Initialize sccache |
| 33 | +if [[ -n "$SCCACHE_BUCKET" ]] && which sccache > /dev/null; then |
| 34 | + # Save sccache logs to file |
| 35 | + sccache --stop-server > /dev/null 2>&1 || true |
| 36 | + rm -f ~/sccache_error.log || true |
| 37 | + |
| 38 | + export SCCACHE_IDLE_TIMEOUT=1200 |
| 39 | + export SCCACHE_ERROR_LOG=~/sccache_error.log |
| 40 | + export RUST_LOG=sccache::server=error |
| 41 | + |
| 42 | + # Report sccache stats for easier debugging |
| 43 | + sccache --zero-stats |
| 44 | + function sccache_epilogue() { |
| 45 | + sccache --show-stats |
| 46 | + sccache --stop-server || true |
| 47 | + } |
| 48 | + |
| 49 | + trap_add sccache_epilogue EXIT |
| 50 | +else |
| 51 | + # Not using sscache if it's not setup properly |
| 52 | + rm -f /opt/cache/bin/cc |
| 53 | + rm -f /opt/cache/bin/c++ |
| 54 | + rm -f /opt/cache/bin/clang |
| 55 | + rm -f /opt/cache/bin/clang++ |
| 56 | + rm -f /opt/cache/bin/gcc |
| 57 | + rm -f /opt/cache/bin/g++ |
| 58 | + |
| 59 | + unset CMAKE_CUDA_COMPILER_LAUNCHER |
| 60 | +fi |
7 | 61 |
|
8 | 62 | # Require only one python installation
|
9 | 63 | if [[ -z "$DESIRED_PYTHON" ]]; then
|
|
0 commit comments