1// Copyright 2019 The Chromium OS Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5package main 6 7func processCCacheFlag(builder *commandBuilder) { 8 // We should be able to share the objects across compilers as 9 // the pre-processed output will differ. This allows boards 10 // that share compiler flags (like x86 boards) to share caches. 11 const ccacheDir = "/var/cache/distfiles/ccache" 12 13 useCCache := true 14 builder.transformArgs(func(arg builderArg) string { 15 if arg.value == "-noccache" { 16 useCCache = false 17 return "" 18 } 19 return arg.value 20 }) 21 22 // Disable ccache during portage's src_configure phase. Using ccache here is generally a 23 // waste of time, since these files are very small. Experimentally, this speeds up 24 // configuring by ~13%. 25 if val, present := builder.env.getenv("EBUILD_PHASE"); present && val == "configure" { 26 useCCache = false 27 } 28 29 if builder.cfg.useCCache && useCCache { 30 // Note: we used to also set CCACHE_BASEDIR but don't do it 31 // anymore for reasons outlined in crrev.com/c/2103170. 32 if _, present := builder.env.getenv("CCACHE_DISABLE"); present { 33 // Portage likes to set this for us when it has FEATURES=-ccache. 34 // The other vars we need to setup manually because of tools like 35 // scons that scrubs the env before we get executed. 36 builder.updateEnv("CCACHE_DISABLE=") 37 } 38 // If RESTRICT=sandbox is enabled, then sandbox won't be setup, 39 // and the env vars won't be available for appending. 40 if sandboxRewrite, present := builder.env.getenv("SANDBOX_WRITE"); present { 41 builder.updateEnv("SANDBOX_WRITE=" + sandboxRewrite + ":" + ccacheDir) 42 } 43 44 // Make sure we keep the cached files group writable. 45 builder.updateEnv("CCACHE_DIR="+ccacheDir, "CCACHE_UMASK=002") 46 47 // ccache may generate false positive warnings. 48 // Workaround bug https://crbug.com/649740 49 if builder.target.compilerType == clangType { 50 builder.updateEnv("CCACHE_CPP2=yes") 51 } 52 53 builder.wrapPath("/usr/bin/ccache") 54 } 55} 56