sdk_lib: Reduce scope of ccache cleanups

We're running a relatively expensive `find` operation over
/var/cache/distfiles/ccache, for little reason. This seems to have been
carried from over 10 years ago, perhaps as an extra-cautious safeguard
against people running ccache-enabled compilers as root. This seems
overly cautious, and the main thing we care about is getting the initial
settings right on fresh chroots.

This expensive operation is currently sent to the background to reduce
its latency impact on chroot entry, but that causes its own problems,
around ensuring mount operations don't conflict.

Rather than retain the expensive operation and the parallelism
complexity, just strip down the operation to its minimum.

We could probably also move this entirely to or
build_sdk_board eventually.

Also, update the gcc comments, since the gcc ebuild is no longer doing
any such ccache cleanup:


Change-Id: Id978bd038edc06f85c03c03dceb6185fabf648d6
Reviewed-by: Mike Frysinger <>
Commit-Queue: Brian Norris <>
Tested-by: Brian Norris <>
diff --git a/sdk_lib/ b/sdk_lib/
index 43edddd..c969d0a 100755
--- a/sdk_lib/
+++ b/sdk_lib/
@@ -556,17 +556,18 @@
       setup_mount "${modules_dir}" "${modules_dir}" --bind -o ro
-    # Fix permissions on ccache tree.  If this is a fresh chroot, then they
-    # might not be set up yet.  Or if the user manually `rm -rf`-ed things,
-    # we need to reset it.  Otherwise, gcc itself takes care of fixing things
-    # on demand, but only when it updates.
+    # Set up ccache tree. If this is a fresh or wiped chroot, then things might
+    # not be set up yet.
     if [[ ! -d ${ccache_dir} ]]; then
       # shellcheck disable=SC2174
       mkdir -p -m 2775 "${ccache_dir}"
+      chgrp 250 "${ccache_dir}"
-    unshare --mount "${SCRIPT_ROOT}/sdk_lib/" --chroot \
-      "${FLAGS_chroot}" &
+    if [[ ! -e ${ccache_dir}/ccache.conf ]]; then
+      chroot "${FLAGS_chroot}" env CCACHE_DIR=/var/cache/distfiles/ccache \
+        CCACHE_UMASK=002 ccache -F 0 -M 11G >/dev/null
+    fi
     # Certain files get copied into the chroot when entering.
     for fn in "${FILES_TO_COPY_TO_CHROOT[@]}"; do
diff --git a/sdk_lib/ b/sdk_lib/
deleted file mode 100755
index c036386..0000000
--- a/sdk_lib/
+++ /dev/null
@@ -1,36 +0,0 @@
-# Copyright 2023 The ChromiumOS Authors
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-# Script to fix permissions on ccache tree.
-SCRIPT_ROOT=$(readlink -f "$(dirname "$0")"/..)
-# shellcheck source=../
-. "${SCRIPT_ROOT}/" || exit 1
-# Define command line flags
-# See
-DEFINE_string chroot "" "The destination dir for the chroot environment."
-# Parse command line flags.
-FLAGS_HELP="usage: ${SCRIPT_NAME} [flags]"
-FLAGS "$@" || exit 1
-eval set -- "${FLAGS_ARGV}"
-if [ -z "${FLAGS_chroot}" ]; then
-  die "--chroot is required"
-# Walking ccache dir can be expensive, so only do it once, but make sure
-# to run both sets of tests+execs independently.
-find -H "${ccache_dir}" \
-  '(' -type d -a '!' -perm 2775 ')' -exec chmod 2775 {} + \
-  , \
-  -gid 0 -exec chgrp 250 {} +
-# These settings are kept in sync with the gcc ebuild.
-chroot "${FLAGS_chroot}" env CCACHE_DIR=/var/cache/distfiles/ccache \
-  CCACHE_UMASK=002 ccache -F 0 -M 11G >/dev/null