Skip to content

Commit 28577db

Browse files
UdjinM6claude
andcommitted
refactor: improve ctcache configuration maintainability
- Move CTCACHE_DIR and CTCACHE_MAXSIZE_MB to ci/test/00_setup_env.sh - Use command -v instead of hardcoded paths for clang-tidy and clang-tidy-cache - Store clang-tidy location in CLANG_TIDY_BIN variable for reuse - Extract cache cleanup logic into cleanup_ctcache() function - Convert CTCACHE_COMMIT to ARG variable in Dockerfile 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 7ef44b6 commit 28577db

File tree

4 files changed

+35
-23
lines changed

4 files changed

+35
-23
lines changed

.github/workflows/build-src.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ jobs:
126126
- name: Run linters
127127
if: inputs.build-target == 'linux64_multiprocess'
128128
run: |
129+
CACHE_DIR="/cache"
129130
export BUILD_TARGET="${{ inputs.build-target }}"
130131
source ./ci/dash/matrix.sh
131132
./ci/dash/lint-tidy.sh

ci/dash/lint-tidy.sh

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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
1842
fi
1943

2044
# Setup ctcache for clang-tidy result caching
21-
export CTCACHE_DIR="/cache/ctcache"
2245
export CTCACHE_SAVE_OUTPUT=1
23-
CTCACHE_CLANG_TIDY=$(which clang-tidy)
24-
export CTCACHE_CLANG_TIDY
46+
export CTCACHE_CLANG_TIDY="${CLANG_TIDY_BIN}"
2547
mkdir -p "${CTCACHE_DIR}"
2648

27-
CLANG_TIDY_CACHE="/usr/local/bin/clang-tidy-cache"
49+
CLANG_TIDY_CACHE=$(command -v clang-tidy-cache)
2850
CLANG_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
3456
fi
3557
if [ ! -f "${CLANG_TIDY_CACHE_PY}" ]; then
@@ -54,21 +76,7 @@ du -sh "${CTCACHE_DIR}" 2>/dev/null || echo "Cache directory not found"
5476
python3 "${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}"
7280
echo "=========================="
7381

7482
cd "${BASE_ROOT_DIR}/build-ci/dashcore-${BUILD_TARGET}"

ci/test/00_setup_env.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ export CCACHE_COMPRESS=${CCACHE_COMPRESS:-1}
6161
# The cache dir.
6262
# This folder exists on the ci host and ci guest. Changes are propagated back and forth.
6363
export CCACHE_DIR=${CCACHE_DIR:-$CACHE_DIR/ccache}
64+
# ctcache (clang-tidy cache) configuration
65+
export CTCACHE_DIR=${CTCACHE_DIR:-$CACHE_DIR/ctcache}
66+
export CTCACHE_MAXSIZE_MB=${CTCACHE_MAXSIZE_MB:-50}
6467
# The depends dir.
6568
# This folder exists on the ci host and ci guest. Changes are propagated back and forth.
6669
export DEPENDS_DIR=${DEPENDS_DIR:-$BASE_ROOT_DIR/depends}

contrib/containers/ci/ci.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ RUN set -ex; \
6767

6868
# Install ctcache for clang-tidy result caching
6969
# Pin to specific commit to ensure patch applies correctly
70+
ARG CTCACHE_COMMIT=e33c063ca6e52b48bcefbc45d46d8c150ffa81ca
7071
RUN set -ex; \
71-
CTCACHE_COMMIT="e33c063ca6e52b48bcefbc45d46d8c150ffa81ca"; \
7272
mkdir -p /usr/local/bin/src/ctcache; \
7373
curl -fsSL "https://raw.githubusercontent.com/matus-chochlik/ctcache/${CTCACHE_COMMIT}/src/ctcache/clang_tidy_cache.py" \
7474
-o /usr/local/bin/src/ctcache/clang_tidy_cache.py; \

0 commit comments

Comments
 (0)