Add flags for ccache

This add support of toggling on ccache.

A rebuild of @portage//target/sys-apps/attr, after modifying
things like build_package, takes 2600 seconds with ccache
instead of 4000 seconds on my workstation.

Some stats after 1 cold + 1 warm cache build:
% CCACHE_DIR=$HOME/ccache ccache --print-stats
autoconf_test   3596
bad_compiler_arguments  174
bad_output_file 0
cache_miss      43037
cache_size_kibibyte     1117400
called_for_link 4210
called_for_preprocessing        3144
cleanups_performed      0
compile_failed  820
compiler_check_failed   0
compiler_produced_empty_output  24
compiler_produced_no_output     0
compiler_produced_stdout        0
could_not_find_compiler 0
could_not_use_modules   0
could_not_use_precompiled_header        0
direct_cache_hit        48125
direct_cache_miss       47024
disabled        2
error_hashing_extra_file        0
files_in_cache  84016
internal_error  0
local_storage_hit       51048
local_storage_miss      43037
local_storage_read_hit  100823
local_storage_read_miss 89221
local_storage_write     86388
missing_cache_file      0
multiple_source_files   4
no_input_file   6732
output_to_stdout        6
preprocessed_cache_hit  2923
preprocessed_cache_miss 43881
preprocessor_error      216
recache 0
remote_storage_error    0
remote_storage_hit      0
remote_storage_miss     0
remote_storage_read_hit 0
remote_storage_read_miss        0
remote_storage_timeout  0
remote_storage_write    0
stats_updated_timestamp 1705452543
stats_zeroed_timestamp  0
unsupported_code_directive      4
unsupported_compiler_option     152
unsupported_environment_variable        0
unsupported_source_language     4

BUG=b:308409836
TEST=BOARD=amd64-generic bazel build @portage//target/sys-apps/attr --//bazel/portage:ccache --//bazel/portage:ccache_dir=$HOME/ccache

Cq-Depend: chromium:4999889
Change-Id: I8a5d483221e128d5f99efa7ed91e303817404b05
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/bazel/+/5009669
Commit-Queue: Li-Yu Yu <aaronyu@google.com>
Tested-by: Li-Yu Yu <aaronyu@google.com>
Reviewed-by: Shuhei Takahashi <nya@chromium.org>
2 files changed