1#!/bin/bash 2# Required environment variables: 3# $BUILD_ENVIRONMENT (should be set by your Docker image) 4 5if [[ "$BUILD_ENVIRONMENT" != *win-* ]]; then 6 # Save the absolute path in case later we chdir (as occurs in the gpu perf test) 7 script_dir="$( cd "$(dirname "${BASH_SOURCE[0]}")" || exit ; pwd -P )" 8 9 if which sccache > /dev/null; then 10 # Save sccache logs to file 11 sccache --stop-server > /dev/null 2>&1 || true 12 rm -f ~/sccache_error.log || true 13 14 function sccache_epilogue() { 15 echo "::group::Sccache Compilation Log" 16 echo '=================== sccache compilation log ===================' 17 python "$script_dir/print_sccache_log.py" ~/sccache_error.log 2>/dev/null || true 18 echo '=========== If your build fails, please take a look at the log above for possible reasons ===========' 19 sccache --show-stats 20 sccache --stop-server || true 21 echo "::endgroup::" 22 } 23 24 # Register the function here so that the error log can be printed even when 25 # sccache fails to start, i.e. timeout error 26 trap_add sccache_epilogue EXIT 27 28 if [[ -n "${SKIP_SCCACHE_INITIALIZATION:-}" ]]; then 29 # sccache --start-server seems to hang forever on self hosted runners for GHA 30 # so let's just go ahead and skip the --start-server altogether since it seems 31 # as though sccache still gets used even when the sscache server isn't started 32 # explicitly 33 echo "Skipping sccache server initialization, setting environment variables" 34 export SCCACHE_IDLE_TIMEOUT=0 35 export SCCACHE_ERROR_LOG=~/sccache_error.log 36 export RUST_LOG=sccache::server=error 37 elif [[ "${BUILD_ENVIRONMENT}" == *rocm* ]]; then 38 SCCACHE_ERROR_LOG=~/sccache_error.log SCCACHE_IDLE_TIMEOUT=0 sccache --start-server 39 else 40 # increasing SCCACHE_IDLE_TIMEOUT so that extension_backend_test.cpp can build after this PR: 41 # https://github.com/pytorch/pytorch/pull/16645 42 SCCACHE_ERROR_LOG=~/sccache_error.log SCCACHE_IDLE_TIMEOUT=0 RUST_LOG=sccache::server=error sccache --start-server 43 fi 44 45 # Report sccache stats for easier debugging. It's ok if this commands 46 # timeouts and fails on MacOS 47 sccache --zero-stats || true 48 fi 49 50 if which ccache > /dev/null; then 51 # Report ccache stats for easier debugging 52 ccache --zero-stats 53 ccache --show-stats 54 function ccache_epilogue() { 55 ccache --show-stats 56 } 57 trap_add ccache_epilogue EXIT 58 fi 59fi 60