@@ -11,25 +11,47 @@ set -eo pipefail
1111# only on nor do they set the requisite build parameters. Make sure you do
1212# that *before* running this script.
1313
14+ # Cleanup old ctcache entries to keep cache size under limit
15+ cleanup_ctcache () {
16+ local cache_dir=$1
17+ local max_size_mb=$2
18+ local cache_size_mb
19+
20+ cache_size_mb=$( du -sm " ${cache_dir} " 2> /dev/null | cut -f1)
21+ if [ " ${cache_size_mb} " -gt " ${max_size_mb} " ]; then
22+ echo " Cache size ${cache_size_mb} MB exceeds limit ${max_size_mb} MB, cleaning old entries..."
23+ # Remove files older than 7 days, or if still too large, oldest 20% of files
24+ find " ${cache_dir} " -type f -mtime +7 -delete 2> /dev/null || true
25+ cache_size_mb=$( du -sm " ${cache_dir} " 2> /dev/null | cut -f1)
26+ if [ " ${cache_size_mb} " -gt " ${max_size_mb} " ]; then
27+ local file_count remove_count
28+ file_count=$( find " ${cache_dir} " -type f | wc -l)
29+ remove_count=$(( file_count / 5 ))
30+ find " ${cache_dir} " -type f -printf ' %T+ %p\0' | sort -z | head -z -n " ${remove_count} " | cut -z -d' ' -f2- | xargs -0 rm -f 2> /dev/null || true
31+ echo " Attempted to remove ${remove_count} oldest cache entries"
32+ fi
33+ echo " Cache size after cleanup: $( du -sh " ${cache_dir} " 2> /dev/null | cut -f1) "
34+ fi
35+ }
36+
1437# Verify clang-tidy is available
15- if ! command -v clang-tidy > /dev/null 2>&1 ; then
38+ CLANG_TIDY_BIN=$( command -v clang-tidy)
39+ if [ -z " ${CLANG_TIDY_BIN} " ]; then
1640 echo " Error: clang-tidy not found in PATH"
1741 exit 1
1842fi
1943
2044# Setup ctcache for clang-tidy result caching
21- export CTCACHE_DIR=" /cache/ctcache"
2245export CTCACHE_SAVE_OUTPUT=1
23- CTCACHE_CLANG_TIDY=$( which clang-tidy)
24- export CTCACHE_CLANG_TIDY
46+ export CTCACHE_CLANG_TIDY=" ${CLANG_TIDY_BIN} "
2547mkdir -p " ${CTCACHE_DIR} "
2648
27- CLANG_TIDY_CACHE=" /usr/local/bin/ clang-tidy-cache"
49+ CLANG_TIDY_CACHE=$( command -v clang-tidy-cache)
2850CLANG_TIDY_CACHE_PY=" /usr/local/bin/src/ctcache/clang_tidy_cache.py"
2951
3052# Verify ctcache is installed
31- if [ ! -x " ${CLANG_TIDY_CACHE} " ]; then
32- echo " Error: ctcache binary not found at ${CLANG_TIDY_CACHE} "
53+ if [ -z " ${CLANG_TIDY_CACHE} " ]; then
54+ echo " Error: clang-tidy-cache not found in PATH "
3355 exit 1
3456fi
3557if [ ! -f " ${CLANG_TIDY_CACHE_PY} " ]; then
@@ -54,21 +76,7 @@ du -sh "${CTCACHE_DIR}" 2>/dev/null || echo "Cache directory not found"
5476python3 " ${CLANG_TIDY_CACHE_PY} " --show-stats 2>&1 || true
5577
5678# Limit cache size (ctcache has no built-in size management)
57- CTCACHE_MAXSIZE_MB=50
58- CACHE_SIZE_MB=$( du -sm " ${CTCACHE_DIR} " 2> /dev/null | cut -f1)
59- if [ " ${CACHE_SIZE_MB} " -gt " ${CTCACHE_MAXSIZE_MB} " ]; then
60- echo " Cache size ${CACHE_SIZE_MB} MB exceeds limit ${CTCACHE_MAXSIZE_MB} MB, cleaning old entries..."
61- # Remove files older than 7 days, or if still too large, oldest 20% of files
62- find " ${CTCACHE_DIR} " -type f -mtime +7 -delete 2> /dev/null || true
63- CACHE_SIZE_MB=$( du -sm " ${CTCACHE_DIR} " 2> /dev/null | cut -f1)
64- if [ " ${CACHE_SIZE_MB} " -gt " ${CTCACHE_MAXSIZE_MB} " ]; then
65- FILE_COUNT=$( find " ${CTCACHE_DIR} " -type f | wc -l)
66- REMOVE_COUNT=$(( FILE_COUNT / 5 ))
67- find " ${CTCACHE_DIR} " -type f -printf ' %T+ %p\0' | sort -z | head -z -n " ${REMOVE_COUNT} " | cut -z -d' ' -f2- | xargs -0 rm -f 2> /dev/null || true
68- echo " Attempted to remove ${REMOVE_COUNT} oldest cache entries"
69- fi
70- echo " Cache size after cleanup: $( du -sh " ${CTCACHE_DIR} " 2> /dev/null | cut -f1) "
71- fi
79+ cleanup_ctcache " ${CTCACHE_DIR} " " ${CTCACHE_MAXSIZE_MB} "
7280echo " =========================="
7381
7482cd " ${BASE_ROOT_DIR} /build-ci/dashcore-${BUILD_TARGET} "
0 commit comments