From 6a730045b5bfcfdc3e0709f4283ade8a541dc618 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 5 Dec 2024 13:53:43 -0800 Subject: Add and use staticLibrary() Add staticLibrary() that returns true for a static variant of a library, and replace all instances of foo.static() && !foo.staticBinary() with foo.staticLibrary. Test: builds Change-Id: I0bf0c18669c24f23ebc9cc33d525b86d81e22d40 --- cc/afdo.go | 4 ++-- cc/cc.go | 14 ++++++++++++++ cc/coverage.go | 2 +- cc/library.go | 9 +++++++-- cc/orderfile.go | 2 +- 5 files changed, 25 insertions(+), 6 deletions(-) (limited to 'cc') diff --git a/cc/afdo.go b/cc/afdo.go index 14d105e99..03dc2713e 100644 --- a/cc/afdo.go +++ b/cc/afdo.go @@ -163,7 +163,7 @@ func (a *afdoTransitionMutator) OutgoingTransition(ctx android.OutgoingTransitio } // TODO(b/324141705): this is designed to prevent propagating AFDO from static libraries that have afdo: true set, but - // it should be m.static() && !m.staticBinary() so that static binaries use AFDO variants of dependencies. + // it should be m.staticLibrary() so that static binaries use AFDO variants of dependencies. if m.static() { return "" } @@ -188,7 +188,7 @@ func (a *afdoTransitionMutator) Mutate(ctx android.BottomUpMutatorContext, varia if variation == "" { // The empty variation is either a module that has enabled AFDO for itself, or the non-AFDO // variant of a dependency. - if m.afdo.afdoEnabled() && !(m.static() && !m.staticBinary()) && !m.Host() { + if m.afdo.afdoEnabled() && !m.staticLibrary() && !m.Host() { m.afdo.addDep(ctx, ctx.ModuleName()) } } else { diff --git a/cc/cc.go b/cc/cc.go index 4838a5f5f..802332426 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -519,6 +519,7 @@ type VendorProperties struct { type ModuleContextIntf interface { static() bool staticBinary() bool + staticLibrary() bool testBinary() bool testLibrary() bool header() bool @@ -1523,6 +1524,10 @@ func (ctx *moduleContextImpl) staticBinary() bool { return ctx.mod.staticBinary() } +func (ctx *moduleContextImpl) staticLibrary() bool { + return ctx.mod.staticLibrary() +} + func (ctx *moduleContextImpl) testBinary() bool { return ctx.mod.testBinary() } @@ -3550,6 +3555,15 @@ func (c *Module) static() bool { return false } +func (c *Module) staticLibrary() bool { + if static, ok := c.linker.(interface { + staticLibrary() bool + }); ok { + return static.staticLibrary() + } + return false +} + func (c *Module) staticBinary() bool { if static, ok := c.linker.(interface { staticBinary() bool diff --git a/cc/coverage.go b/cc/coverage.go index a7618dd96..dbb424f59 100644 --- a/cc/coverage.go +++ b/cc/coverage.go @@ -145,7 +145,7 @@ func (cov *coverage) flags(ctx ModuleContext, flags Flags, deps PathDeps) (Flags // Even if we don't have coverage enabled, if any of our object files were compiled // with coverage, then we need to add --coverage to our ldflags. if !cov.linkCoverage { - if ctx.static() && !ctx.staticBinary() { + if ctx.staticLibrary() { // For static libraries, the only thing that changes our object files // are included whole static libraries, so check to see if any of // those have coverage enabled. diff --git a/cc/library.go b/cc/library.go index ea8794644..6485ea364 100644 --- a/cc/library.go +++ b/cc/library.go @@ -1800,12 +1800,17 @@ func (library *libraryDecorator) everInstallable() bool { return library.shared() || library.static() } -// static returns true if this library is for a "static' variant. +// static returns true if this library is for a "static" variant. func (library *libraryDecorator) static() bool { return library.MutatedProperties.VariantIsStatic } -// shared returns true if this library is for a "shared' variant. +// staticLibrary returns true if this library is for a "static"" variant. +func (library *libraryDecorator) staticLibrary() bool { + return library.static() +} + +// shared returns true if this library is for a "shared" variant. func (library *libraryDecorator) shared() bool { return library.MutatedProperties.VariantIsShared } diff --git a/cc/orderfile.go b/cc/orderfile.go index 6e08da7a0..c07a09851 100644 --- a/cc/orderfile.go +++ b/cc/orderfile.go @@ -153,7 +153,7 @@ func (orderfile *orderfile) begin(ctx BaseModuleContext) { } // Currently, we are not enabling orderfiles to begin from static libraries - if ctx.static() && !ctx.staticBinary() { + if ctx.staticLibrary() { return } -- cgit v1.2.3-59-g8ed1b