ccache during system build

From: Rozhuk Ivan <rozhuk.im_at_gmail.com>
Date: Fri, 10 Jun 2022 03:34:47 UTC
Hi!


Just few tips.


1. bsd.compiler.mk set COMPILERCHECK env var:
============================================================================
# Handle bootstrapped compiler changes properly by hashing their content
# rather than checking mtime.  For external compilers it should be safe
# to use the more optimal mtime check.
# XXX: CCACHE_COMPILERCHECK= string:<compiler_version, compiler_build_rev, compiler_patch_rev, compiler_default_target, compiler_default_sysroot>
.if ${CC:N${CCACHE_BIN}:[1]:M/*} == ""
CCACHE_COMPILERCHECK?=	content
.else
CCACHE_COMPILERCHECK?=	mtime
.endif
============================================================================
this overrides ccache.conf setting and increase build time.
CCACHE_COMPILERCHECK='%compiler% -dumpversion'
makes first build and second system rebuild faster.


2. To allow ccache hit in case with different src and obj location
a) obj must be placed inside src
b) OBJTOP env var must be set to new obj location
without this obj path will contain src path and not hit to ccache.
c) CCACHE_BASEDIR must be set to src
d) CCACHE_NOHASHDIR=yes
e) CCACHE_COMPILERCHECK='%compiler% -dumpversion'
f) MAKEOBJDIRPREFIX=''
g) -o nocache must be used with mount_nullfs to avoid error during install:
exec(btxld) failed (No such file or directory) and obj via nullfs


As example, attached scripts build kernel and world using obj stored inside /tmp,
after build files from temp obj moved to /usr/obj dir.
Using simular technic for build FreeBSD inside other src and obj locations I got
ccache hit and reduce build time.

I got ccache miss only for kernel build in case different KERNCONF, because it is mapped
to obj dir path. Probably overwriting OBJROOT will fix it.