Skip to content

Commit bcb6669

Browse files
minaripenguinMrick343
authored andcommitted
envsetup.sh: Setup and enable ccache
Signed-off-by: minaripenguin <[email protected]> Signed-off-by: Pranav Vashi <[email protected]>
1 parent 10e0dd3 commit bcb6669

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

envsetup.sh

+16-9
Original file line numberDiff line numberDiff line change
@@ -2129,18 +2129,25 @@ source_vendorsetup
21292129
addcompletions
21302130

21312131
# check and set ccache path on envsetup
2132-
if [ -z ${CCACHE_EXEC} ]; then
2133-
ccache_path=$(which ccache)
2134-
if [ ! -z "$ccache_path" ]; then
2132+
if [ -z "${CCACHE_EXEC}" ]; then
2133+
if command -v ccache &>/dev/null; then
21352134
export USE_CCACHE=1
2136-
export CCACHE_EXEC="$ccache_path"
2137-
if [ -z ${CCACHE_DIR} ]; then
2138-
export CCACHE_DIR=${HOME}/.ccache
2135+
export CCACHE_EXEC=$(command -v ccache)
2136+
[ -z "${CCACHE_DIR}" ] && export CCACHE_DIR="$HOME/.ccache"
2137+
echo "ccache directory found, CCACHE_DIR set to: $CCACHE_DIR" >&2
2138+
CCACHE_MAXSIZE="${CCACHE_MAXSIZE:-40G}"
2139+
DIRECT_MODE="${DIRECT_MODE:-false}"
2140+
$CCACHE_EXEC -o compression=true -o direct_mode="${DIRECT_MODE}" -M "${CCACHE_MAXSIZE}" \
2141+
&& echo "ccache enabled, CCACHE_EXEC set to: $CCACHE_EXEC, CCACHE_MAXSIZE set to: $CCACHE_MAXSIZE, direct_mode set to: $DIRECT_MODE" >&2 \
2142+
|| echo "Warning: Could not set cache size limit. Please check ccache configuration." >&2
2143+
CURRENT_CCACHE_SIZE=$(du -sh "$CCACHE_DIR" 2>/dev/null | cut -f1)
2144+
if [ -n "$CURRENT_CCACHE_SIZE" ]; then
2145+
echo "Current ccache size is: $CURRENT_CCACHE_SIZE" >&2
2146+
else
2147+
echo "No cached files in ccache." >&2
21392148
fi
2140-
$ccache_path -o compression=true
2141-
echo -e "ccache enabled and CCACHE_EXEC has been set to : $ccache_path"
21422149
else
2143-
echo -e "ccache not found installed!"
2150+
echo "Error: ccache not found. Please install ccache." >&2
21442151
fi
21452152
fi
21462153

0 commit comments

Comments
 (0)