]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
chore: Add build-ccache-with-itself script
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 22 Jul 2025 12:43:25 +0000 (14:43 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 22 Jul 2025 12:43:25 +0000 (14:43 +0200)
This script can be used to verify that ccache is able to cache a build
of itself.

Example usage:

    COMMAND=/source/misc/build-ccache-with-itself misc/build-in-docker debian-12

dockerfiles/fedora-42/Dockerfile
misc/build-ccache-with-itself [new file with mode: 0755]

index 48bd0a806b37b01f178847e326113da8b16a93d8..d041572f44b1bdc438deb026ac3c2417d099eda5 100644 (file)
@@ -2,6 +2,7 @@ ARG BASE_IMAGE=fedora:42
 FROM ${BASE_IMAGE} AS build
 
 RUN dnf install -y \
+        awk \
         blake3-devel \
         ccache \
         clang \
diff --git a/misc/build-ccache-with-itself b/misc/build-ccache-with-itself
new file mode 100755 (executable)
index 0000000..949bb97
--- /dev/null
@@ -0,0 +1,52 @@
+#!/bin/bash
+#
+# Example usage:
+#
+# COMMAND=/source/misc/build-ccache-with-itself misc/build-in-docker debian-12
+
+set -eu
+
+# Set default values.
+: ${BUILDDIR:=build}
+: ${CCACHE_LOC:=..}
+: ${CMAKE_PARAMS:=}
+: ${EXTRA_CMAKE_BUILD_FLAGS:=}
+: ${JOBS:=$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 2)}
+: ${VERBOSE:=}
+
+if [ -n "${VERBOSE}" ]; then
+    set -x
+fi
+
+build_ccache() {
+    mkdir -p "${BUILDDIR}"
+    cmake ${CMAKE_PARAMS} -S "${CCACHE_LOC}" -B "${BUILDDIR}"
+    cmake --build "${BUILDDIR}" ${EXTRA_CMAKE_BUILD_FLAGS} -- -j "${JOBS}"
+}
+
+# Bootstrap
+build_ccache
+cmake --install "${BUILDDIR}"
+rm -rf "${BUILDDIR}"
+
+export CCACHE_DIR=/tmp/ccache
+export CMAKE_PARAMS="${CMAKE_PARAMS} -D CMAKE_C_COMPILER_LAUNCHER=/usr/local/bin/ccache -D CMAKE_CXX_COMPILER_LAUNCHER=/usr/local/bin/ccache"
+rm -f /usr/local/bin/gcc /usr/local/bin/g++
+
+# Build with empty cache
+build_ccache
+ccache -sv
+
+# Rebuild with warm cache
+export CCACHE_STATSLOG="$PWD/stats.log"
+rm -rf "${BUILDDIR}"
+build_ccache
+ccache -sv
+
+echo
+echo "Cache misses:"
+awk '/^cache_miss$/ { print substr(previous, 3) } { previous = $0 }' "${CCACHE_STATSLOG}"
+
+echo
+echo "Rebuild statistics:"
+ccache --show-log-stats -v