1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # T2 SDE: package/*/ccache/parse-config
3 # Copyright (C) 2004 - 2021 The T2 SDE Project
5 # This Copyright note is generated by scripts/Create-CopyPatch,
6 # more information can be found in the files COPYING and README.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; version 2 of the License. A copy of the
11 # GNU General Public License can be found in the file COPYING.
12 # --- T2-COPYRIGHT-NOTE-END ---
14 if [ "$SDECFG_PKG_CCACHE_USEIT" = 1 -a "`type -p ccache`" ]; then
15 if [ "$pkg" == gcc -a "$SDECFG_MULTILIB" = 1 ]; then
16 : # in GCC multilib builds the ccache hash currently collides (or so)
21 # wrap the sytem compiler
22 atstage toolchain && var_append ccache_dir - ${arch_build%%-*}
23 var_append ccache_dir - $arch
25 # do not trash the cache with feature-less built packages
26 [ $stagelevel -le 2 ] && var_append ccache_dir - $stagelevel
28 export CCACHE_DIR="$base/build/$ccache_dir/$pkg"
29 export CCACHE_DONT_STAT_COMPILER=1 # legacy T2, could be removed in the future
30 export CCACHE_COMPILERCHECK="none" # native since ccache-3.1.5
31 export CCACHE_UNIFY=1 # needed to e.g. strip comments
32 #export CCACHE_LOGFILE="$CCACHE_DIR.log"
34 # In the chroot sandbox we need to wire the cccache-$arch out by using
35 # the existing bind mount. We only do this, if we are not doing a
36 # manual stage9 build ...
37 if atstage native && [ "$ROCK_THIS_IS_CHROOT" ]; then
38 mkdir -p $base/loop/build/$ccache_dir
39 ln -snf ../loop/build/$ccache_dir $base/build/$ccache_dir
42 # we instruct the flist wrapper to filter out ccache access, to
43 # further reduce flist post processing time for big packages
44 var_append FLWRAPPER_FILTERDIR ':' "$CCACHE_DIR"
46 mkdir -p "$CCACHE_DIR"
48 if [ "$SDECFG_PKG_CCACHE_CLEANUP" != 0 ]; then
49 # we need to know if atime tests work or not
50 echo > $CCACHE_DIR/.timestamp
51 echo > $CCACHE_DIR/.timestamp-reference
54 ccache -M $SDECFG_PKG_CCACHE_MAX > /dev/null
56 # just using the CC_WRAPPER would not wrap KCC ... - thus we use GCC for C and C++
57 # and KCC for the kernel builds ...
58 if ! atstage toolchain; then
59 var_insert KCC_WRAPPER_OTHERS ":" "ccache"
60 var_insert GCC_WRAPPER_OTHERS ":" "ccache"
62 var_insert SYSCC_WRAPPER_OTHERS ":" "ccache"
65 eval "$(ccache -s | gawk 'BEGIN {hit=0}
66 /cache hit \(/ { hit+=$4; }
67 /cache miss/ { miss=$3; }
68 END { if (hit+miss == 0) print "x=0.00";
69 else printf "x=%.2f\n", hit*100 / (hit+miss);
70 print "ccache_hit=" hit "; ccache_miss=" miss; }' )"
71 echo_status "Compiler Cache enabled: $x% cache hits so far"
73 ccache_print_status_and_cleanup () {
74 eval "$(ccache -s | gawk 'BEGIN {hit=0}
75 /cache hit \(/ { hit+=$4; }
76 /cache miss/ { miss=$3; }
77 END { hit-='$ccache_hit'; miss-='$ccache_miss';
78 if (hit+miss == 0) print "x=0.00";
79 else printf "x=%.2f\n", hit*100 / (hit+miss);
80 print "ccache_hit=" hit "; ccache_miss=" miss; }' )"
81 echo_status "Compiler Cache Hits while pkg build: $x% (`
82 `$ccache_hit hits, $ccache_miss misses)"
84 if [ "$SDECFG_PKG_CCACHE_CLEANUP" != 0 ]; then
85 # test if fs supports atime
86 cat $CCACHE_DIR/.timestamp > /dev/null
87 if [ "$( find $CCACHE_DIR/.timestamp -anewer $CCACHE_DIR/.timestamp-reference )" ]
89 if [ -f $root/var/adm/logs/$stagelevel-$xpkg.log ]; then
91 # remove non-hits from the ccache cache ...
93 echo_status "Cleaning up ccache"
94 find $CCACHE_DIR -type f ! -anewer $CCACHE_DIR/.timestamp-reference -a ! -name '*.stderr' |
96 rm -f $fn{,.stderr} 2>/dev/null
100 echo_warning "No atime support available, ccache clean up not possible!"
105 hook_add finish 9 ccache_print_status_and_cleanup
107 # last but not least make sure the package does not depend on ccache
108 var_append flistrfilter "|" ".*bin/ccache"