From d6b2525b003b5620b3745a79dce56093173504f5 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 11 Aug 2020 12:17:01 -0700 Subject: Deduplicate APEX variants that would build identically APEX variants that share the same SDK version and updatability almost always use identical command line arguments to build but with different intermediates directories. This causes unnecessary build time and disk space for duplicated work. Deduplicate APEX variants that would build identically. Create aliases from the per-APEX variations to the new shared variations so that the APEX modules can continue to depend on them via the APEX name as the variation. This has one significant change in behavior. Before this change, if an APEX had two libraries in its direct dependencies and one of those libraries depended on the other, and the second library had stubs, then the first library would depend on the implementation of the second library and not the stubs. After this change, if the first library is also present in a second APEX but the second library is not, then the common variant shared between the two APEXes would use the stubs, not the implementation. In a correctly configured set of build rules this change will be irrelevant, because if the compilation worked for the second APEX using stubs then it will work for the common variant using stubs. However, if an incorrect change to the build rules is made this could lead to confusing errors, as a previously-working common variant could suddenly stop building when a module is added to a new APEX without its dependencies that require implementation APIs to compile. This change reduces the number of modules in an AOSP arm64-userdebug build by 3% (52242 to 50586), reduces the number of variants of the libcutils module from 74 to 53, and reduces the number of variants of the massive libart[d] modules from 44 to 32. Bug: 164216768 Test: go test ./build/soong/apex/... Change-Id: I0529837476a253c32b3dfb98dcccf107427c742c --- cc/cc.go | 18 ++++++++++++++---- cc/compiler.go | 4 ++++ 2 files changed, 18 insertions(+), 4 deletions(-) (limited to 'cc') diff --git a/cc/cc.go b/cc/cc.go index 4d61fa2b4..9bf9c84fa 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -2390,7 +2390,7 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { if ccDep.CcLibrary() && !libDepTag.static() { depIsStubs := ccDep.BuildStubs() depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants() - depInSameApex := android.DirectlyInApex(c.ApexVariationName(), depName) + depInSameApexes := android.DirectlyInAllApexes(c.InApexes(), depName) depInPlatform := !android.DirectlyInAnyApex(ctx, depName) var useThisDep bool @@ -2420,9 +2420,9 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { } } } else { - // If building for APEX, use stubs only when it is not from - // the same APEX - useThisDep = (depInSameApex != depIsStubs) + // If building for APEX, use stubs when the parent is in any APEX that + // the child is not in. + useThisDep = (depInSameApexes != depIsStubs) } // when to use (unspecified) stubs, check min_sdk_version and choose the right one @@ -2895,6 +2895,16 @@ func (c *Module) TestFor() []string { } } +func (c *Module) UniqueApexVariations() bool { + if u, ok := c.compiler.(interface { + uniqueApexVariations() bool + }); ok { + return u.uniqueApexVariations() + } else { + return false + } +} + // Return true if the module is ever installable. func (c *Module) EverInstallable() bool { return c.installer != nil && diff --git a/cc/compiler.go b/cc/compiler.go index 4a42d07e3..e06243b50 100644 --- a/cc/compiler.go +++ b/cc/compiler.go @@ -556,6 +556,10 @@ func (compiler *baseCompiler) hasSrcExt(ext string) bool { return false } +func (compiler *baseCompiler) uniqueApexVariations() bool { + return Bool(compiler.Properties.Use_apex_name_macro) +} + // makeDefineString transforms a name of an APEX module into a value to be used as value for C define // For example, com.android.foo => COM_ANDROID_FOO func makeDefineString(name string) string { -- cgit v1.2.3-59-g8ed1b