Configure ccache for a greater hit ratio (#40724)
* Configure ccache
* Restyled by whitespace
* Enhance script
* Add missing env variables
* Test
---------
Co-authored-by: Restyled.io <commits@restyled.io>
diff --git a/scripts/helpers/ccache-prefix-cpp.sh b/scripts/helpers/ccache-prefix-cpp.sh
new file mode 100755
index 0000000..89e395c
--- /dev/null
+++ b/scripts/helpers/ccache-prefix-cpp.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+# Add -P flag to get rid of #line directives which break caching
+args=()
+for arg in "$@"; do
+ args+=("$arg")
+ [[ "$arg" == "-E" ]] && args+=("-P")
+done
+
+exec "${args[@]}"
diff --git a/scripts/setup/bootstrap.sh b/scripts/setup/bootstrap.sh
index da4bc4c..ed0f3ba 100644
--- a/scripts/setup/bootstrap.sh
+++ b/scripts/setup/bootstrap.sh
@@ -204,6 +204,13 @@
. "$_CHIP_ROOT/scripts/helpers/zsh-completion.zsh"
fi
+# Set ccache environment variables
+export CCACHE_NOHASHDIR=1
+export CCACHE_PREFIX_CPP="$_CHIP_ROOT/scripts/helpers/ccache-prefix-cpp.sh"
+export CCACHE_BASEDIR="$_CHIP_ROOT"
+export CCACHE_SLOPPINESS=time_macros
+export CCACHE_COMPILERCHECK=content
+
unset -f _bootstrap_or_activate
unset -f _install_additional_pip_requirements