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