From 9e05d1c5cdc6b263cac19e9a78f791b0d63c8921 Mon Sep 17 00:00:00 2001 From: Qing Shen Date: Tue, 13 Aug 2024 02:04:53 +0000 Subject: [PATCH] Add a coverage suffix to avoid Ninja file regeneration. This CL uses the environment variable, EMMA_INSTRUMENT to determine whether or not coverage is enabled. If coverage is enabled, it adds a bunch of suffixes to the files generated in out/soong/ folders. This change reduces the build time by avoiding ninja regeneration when users simply switches from atest to atest --experimental-coverage, or vice versa, and no Android.bp changes are made. Bug: 331444846 Test: Locally run m libc, and then EMMA_INSTRUMENT m libc twice, no ninja regenerations required. Compared the hash of out/target/product/vsoc_x86_64/ between the before-change repo and after-change repo. Only diff is the after-change directory contains an extra file `out/target/product/vsoc_x86_64/.installable_files` while the original directory has only `out/target/product/vsoc_x86_64/.installable_files.previous`, both files have the same hash. Change-Id: I972aec20a9d97b223cc833ee245016ac4b0f09a2 --- ui/build/config.go | 19 +++++++++++++------ ui/build/kati.go | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ui/build/config.go b/ui/build/config.go index 631b76f03..b64a65f9b 100644 --- a/ui/build/config.go +++ b/ui/build/config.go @@ -1041,7 +1041,7 @@ func (c *configImpl) NamedGlobFile(name string) string { func (c *configImpl) UsedEnvFile(tag string) string { if v, ok := c.environ.Get("TARGET_PRODUCT"); ok { - return shared.JoinPath(c.SoongOutDir(), usedEnvFile+"."+v+"."+tag) + return shared.JoinPath(c.SoongOutDir(), usedEnvFile+"."+v+c.CoverageSuffix()+"."+tag) } return shared.JoinPath(c.SoongOutDir(), usedEnvFile+"."+tag) } @@ -1149,6 +1149,13 @@ func (c *configImpl) TargetProductOrErr() (string, error) { return "", fmt.Errorf("TARGET_PRODUCT is not defined") } +func (c *configImpl) CoverageSuffix() string { + if v := c.environ.IsEnvTrue("EMMA_INSTRUMENT"); v { + return ".coverage" + } + return "" +} + func (c *configImpl) TargetDevice() string { return c.targetDevice } @@ -1521,7 +1528,7 @@ func (c *configImpl) SoongVarsFile() string { if err != nil { return filepath.Join(c.SoongOutDir(), "soong.variables") } else { - return filepath.Join(c.SoongOutDir(), "soong."+targetProduct+".variables") + return filepath.Join(c.SoongOutDir(), "soong."+targetProduct+c.CoverageSuffix()+".variables") } } @@ -1530,7 +1537,7 @@ func (c *configImpl) SoongExtraVarsFile() string { if err != nil { return filepath.Join(c.SoongOutDir(), "soong.extra.variables") } else { - return filepath.Join(c.SoongOutDir(), "soong."+targetProduct+".extra.variables") + return filepath.Join(c.SoongOutDir(), "soong."+targetProduct+c.CoverageSuffix()+".extra.variables") } } @@ -1539,7 +1546,7 @@ func (c *configImpl) SoongNinjaFile() string { if err != nil { return filepath.Join(c.SoongOutDir(), "build.ninja") } else { - return filepath.Join(c.SoongOutDir(), "build."+targetProduct+".ninja") + return filepath.Join(c.SoongOutDir(), "build."+targetProduct+c.CoverageSuffix()+".ninja") } } @@ -1551,11 +1558,11 @@ func (c *configImpl) CombinedNinjaFile() string { } func (c *configImpl) SoongAndroidMk() string { - return filepath.Join(c.SoongOutDir(), "Android-"+c.TargetProduct()+".mk") + return filepath.Join(c.SoongOutDir(), "Android-"+c.TargetProduct()+c.CoverageSuffix()+".mk") } func (c *configImpl) SoongMakeVarsMk() string { - return filepath.Join(c.SoongOutDir(), "make_vars-"+c.TargetProduct()+".mk") + return filepath.Join(c.SoongOutDir(), "make_vars-"+c.TargetProduct()+c.CoverageSuffix()+".mk") } func (c *configImpl) SoongBuildMetrics() string { diff --git a/ui/build/kati.go b/ui/build/kati.go index a0efd2c88..5743ff7a7 100644 --- a/ui/build/kati.go +++ b/ui/build/kati.go @@ -41,7 +41,7 @@ const katiPackageSuffix = "-package" // arguments. func genKatiSuffix(ctx Context, config Config) { // Construct the base suffix. - katiSuffix := "-" + config.TargetProduct() + katiSuffix := "-" + config.TargetProduct() + config.CoverageSuffix() // Append kati arguments to the suffix. if args := config.KatiArgs(); len(args) > 0 {