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 make_chroot.sh or
build_sdk_board eventually.

Also, update the gcc comments, since the gcc ebuild is no longer doing
any such ccache cleanup:
https://chromium-review.googlesource.com/c/chromiumos/overlays/chromiumos-overlay/+/2090134

BUG=b:301643895
TEST=`cros_sdk`

Change-Id: Id978bd038edc06f85c03c03dceb6185fabf648d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosutils/+/4885689
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Brian Norris <briannorris@chromium.org>
Tested-by: Brian Norris <briannorris@chromium.org>
diff --git a/sdk_lib/enter_chroot.sh b/sdk_lib/enter_chroot.sh
index 43edddd..c969d0a 100755
--- a/sdk_lib/enter_chroot.sh
+++ b/sdk_lib/enter_chroot.sh
@@ -556,17 +556,18 @@
       setup_mount "${modules_dir}" "${modules_dir}" --bind -o ro
     fi
 
-    # 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.
     ccache_dir="${FLAGS_chroot}/var/cache/distfiles/ccache"
     if [[ ! -d ${ccache_dir} ]]; then
       # shellcheck disable=SC2174
       mkdir -p -m 2775 "${ccache_dir}"
+      chgrp 250 "${ccache_dir}"
     fi
-    unshare --mount "${SCRIPT_ROOT}/sdk_lib/fix_ccache.sh" --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/fix_ccache.sh b/sdk_lib/fix_ccache.sh
deleted file mode 100755
index c036386..0000000
--- a/sdk_lib/fix_ccache.sh
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/bash
-
-# 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=../common.sh
-. "${SCRIPT_ROOT}/common.sh" || exit 1
-
-# Define command line flags
-# See http://code.google.com/p/shflags/wiki/Documentation10x
-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"
-fi
-
-# Walking ccache dir can be expensive, so only do it once, but make sure
-# to run both sets of tests+execs independently.
-ccache_dir="${FLAGS_chroot}/var/cache/distfiles/ccache"
-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