diff options
author | Tobias Bosch <tbosch@google.com> | 2019-06-10 15:50:33 -0700 |
---|---|---|
committer | Tobias Bosch <tbosch@google.com> | 2019-06-20 15:41:37 +0000 |
commit | ef8f969c8ea2498c2a8aa701cb2e83833339f9a8 (patch) | |
tree | a3c988999263f4e43ec561908b452093ad169b53 /compiler_wrapper/ccache_flag.go | |
parent | 87d457dfc5ae0a7631917523eb3c62751453e4bb (diff) | |
download | toolchain-utils-ef8f969c8ea2498c2a8aa701cb2e83833339f9a8.tar.gz |
Initial version of a go version of the compiler wrapper.
Still calls the old wrapper if one of the following flags is given:
- Xclang-path
- clang-syntax
- env WITH_TIDY
- env FORCE_DISABLE_WERROR
- env GETRUSAGE
- env BISECT_STAGE
BUG=chromium:773875
TEST=Unit tests that also verify the produced command against the
TEST=existing compiler wrapper.
Change-Id: I1e0a720ce9f485d8015deefb2682f2cb760d82e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1652057
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Reviewed-by: Tobias Bosch <tbosch@google.com>
Reviewed-by: George Burgess <gbiv@chromium.org>
Tested-by: Tobias Bosch <tbosch@google.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Diffstat (limited to 'compiler_wrapper/ccache_flag.go')
-rw-r--r-- | compiler_wrapper/ccache_flag.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/compiler_wrapper/ccache_flag.go b/compiler_wrapper/ccache_flag.go new file mode 100644 index 00000000..13ee234d --- /dev/null +++ b/compiler_wrapper/ccache_flag.go @@ -0,0 +1,60 @@ +package main + +func processCCacheFlag(sysroot string, builder *commandBuilder) { + // We should be able to share the objects across compilers as + // the pre-processed output will differ. This allows boards + // that share compiler flags (like x86 boards) to share caches. + const ccacheDir = "/var/cache/distfiles/ccache" + + useCCache := true + builder.transformArgs(func(arg builderArg) string { + if arg.Value == "-noccache" { + useCCache = false + return "" + } + return arg.Value + }) + + if useCCache { + // We need to get ccache to make relative paths from within the + // sysroot. This lets us share cached files across boards (if + // all other things are equal of course like CFLAGS) as well as + // across versions. A quick test is something like: + // $ export CFLAGS='-O2 -g -pipe' CXXFLAGS='-O2 -g -pipe' + // $ BOARD=x86-alex + // $ cros_workon-$BOARD stop cros-disks + // $ emerge-$BOARD cros-disks + // $ cros_workon-$BOARD start cros-disks + // $ emerge-$BOARD cros-disks + // $ BOARD=amd64-generic + // $ cros_workon-$BOARD stop cros-disks + // $ emerge-$BOARD cros-disks + // $ cros_workon-$BOARD start cros-disks + // $ emerge-$BOARD cros-disks + // All of those will get cache hits (ignoring the first one + // which will seed the cache) due to this setting. + builder.updateEnv("CCACHE_BASEDIR=" + sysroot) + if builder.env.getenv("CCACHE_DISABLE") != "" { + // Portage likes to set this for us when it has FEATURES=-ccache. + // The other vars we need to setup manually because of tools like + // scons that scrubs the env before we get executed. + builder.updateEnv("CCACHE_DISABLE=") + } + // If RESTRICT=sandbox is enabled, then sandbox won't be setup, + // and the env vars won't be available for appending. + if sandboxRewrite := builder.env.getenv("SANDBOX_WRITE"); sandboxRewrite != "" { + builder.updateEnv("SANDBOX_WRITE=" + sandboxRewrite + ":" + ccacheDir) + } + + // Make sure we keep the cached files group writable. + builder.updateEnv("CCACHE_DIR="+ccacheDir, "CCACHE_UMASK=002") + + // ccache may generate false positive warnings. + // Workaround bug https://crbug.com/649740 + if builder.target.compilerType == clangType { + builder.updateEnv("CCACHE_CPP2=yes") + } + + builder.wrapPath("/usr/bin/ccache") + } +} |