Make the WholeStatic/Static/Shared libs properties configurable

So that you can use selects with them.

Bug: 342006386
Bug: 358377461
Test: m nothing --no-skip-soong-tests
Change-Id: I5a8350f670d51b7da411ad5c3cdbf5f2d6cdd63b
This commit is contained in:
Cole Faust
2024-08-19 14:39:19 -07:00
parent dd00f2de3c
commit f0006e7137
12 changed files with 83 additions and 53 deletions

View File

@@ -813,6 +813,7 @@ type SdkMemberProperties interface {
// SdkMemberContext provides access to information common to a specific member.
type SdkMemberContext interface {
ConfigAndErrorContext
// SdkModuleContext returns the module context of the sdk common os variant which is creating the
// snapshot.

View File

@@ -132,7 +132,7 @@ func (p *nativeBinaryInfoProperties) PopulateFromVariant(ctx android.SdkMemberCo
if ccModule.linker != nil {
specifiedDeps := specifiedDeps{}
specifiedDeps = ccModule.linker.linkerSpecifiedDeps(specifiedDeps)
specifiedDeps = ccModule.linker.linkerSpecifiedDeps(ctx, ccModule, specifiedDeps)
p.SharedLibs = specifiedDeps.sharedLibs
p.SystemSharedLibs = specifiedDeps.systemSharedLibs

View File

@@ -613,7 +613,7 @@ type linker interface {
coverageOutputFilePath() android.OptionalPath
// Get the deps that have been explicitly specified in the properties.
linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
linkerSpecifiedDeps(ctx android.ConfigAndErrorContext, module *Module, specifiedDeps specifiedDeps) specifiedDeps
moduleInfoJSON(ctx ModuleContext, moduleInfoJSON *android.ModuleInfoJSON)
}

View File

@@ -2,10 +2,10 @@
<<$includeDirs := getIncludeDirs .Ctx .M>>
<<$cflags := getCflagsProperty .Ctx .M>>
<<$deps := mapLibraries .Ctx .M (concat5
(getLinkerProperties .M).Whole_static_libs
(getLinkerProperties .M).Static_libs
(getLinkerProperties .M).Shared_libs
(getLinkerProperties .M).Header_libs
(getWholeStaticLibsProperty .Ctx .M)
(getStaticLibsProperty .Ctx .M)
(getSharedLibsProperty .Ctx .M)
(getHeaderLibsProperty .Ctx .M)
(getExtraLibs .M)
) .Pprop.LibraryMapping>>
<<$moduleType := getModuleType .M>>

View File

@@ -204,12 +204,28 @@ func parseTemplate(templateContents string) *template.Template {
return m.compiler.baseCompilerProps()
},
"getCflagsProperty": func(ctx android.ModuleContext, m *Module) []string {
cflags := m.compiler.baseCompilerProps().Cflags
return cflags.GetOrDefault(ctx, nil)
prop := m.compiler.baseCompilerProps().Cflags
return prop.GetOrDefault(ctx, nil)
},
"getLinkerProperties": func(m *Module) BaseLinkerProperties {
return m.linker.baseLinkerProps()
},
"getWholeStaticLibsProperty": func(ctx android.ModuleContext, m *Module) []string {
prop := m.linker.baseLinkerProps().Whole_static_libs
return prop.GetOrDefault(ctx, nil)
},
"getStaticLibsProperty": func(ctx android.ModuleContext, m *Module) []string {
prop := m.linker.baseLinkerProps().Static_libs
return prop.GetOrDefault(ctx, nil)
},
"getSharedLibsProperty": func(ctx android.ModuleContext, m *Module) []string {
prop := m.linker.baseLinkerProps().Shared_libs
return prop.GetOrDefault(ctx, nil)
},
"getHeaderLibsProperty": func(ctx android.ModuleContext, m *Module) []string {
prop := m.linker.baseLinkerProps().Header_libs
return prop.GetOrDefault(ctx, nil)
},
"getExtraLibs": getExtraLibs,
"getIncludeDirs": getIncludeDirs,
"mapLibraries": func(ctx android.ModuleContext, m *Module, libs []string, mapping map[string]LibraryMappingProperty) []string {

View File

@@ -798,13 +798,13 @@ type RustBindgenClangProperties struct {
Local_include_dirs []string `android:"arch_variant,variant_prepend"`
// list of static libraries that provide headers for this binding.
Static_libs []string `android:"arch_variant,variant_prepend"`
Static_libs proptools.Configurable[[]string] `android:"arch_variant,variant_prepend"`
// list of shared libraries that provide headers for this binding.
Shared_libs []string `android:"arch_variant"`
Shared_libs proptools.Configurable[[]string] `android:"arch_variant"`
// List of libraries which export include paths required for this module
Header_libs []string `android:"arch_variant,variant_prepend"`
Header_libs proptools.Configurable[[]string] `android:"arch_variant,variant_prepend"`
// list of clang flags required to correctly interpret the headers.
Cflags proptools.Configurable[[]string] `android:"arch_variant"`

View File

@@ -153,9 +153,9 @@ type StaticOrSharedProperties struct {
Cflags proptools.Configurable[[]string] `android:"arch_variant"`
Enabled *bool `android:"arch_variant"`
Whole_static_libs []string `android:"arch_variant"`
Static_libs []string `android:"arch_variant"`
Shared_libs []string `android:"arch_variant"`
Whole_static_libs proptools.Configurable[[]string] `android:"arch_variant"`
Static_libs proptools.Configurable[[]string] `android:"arch_variant"`
Shared_libs proptools.Configurable[[]string] `android:"arch_variant"`
System_shared_libs []string `android:"arch_variant"`
Export_shared_lib_headers []string `android:"arch_variant"`
@@ -837,9 +837,9 @@ func (library *libraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
if library.static() {
deps.WholeStaticLibs = append(deps.WholeStaticLibs,
library.StaticProperties.Static.Whole_static_libs...)
deps.StaticLibs = append(deps.StaticLibs, library.StaticProperties.Static.Static_libs...)
deps.SharedLibs = append(deps.SharedLibs, library.StaticProperties.Static.Shared_libs...)
library.StaticProperties.Static.Whole_static_libs.GetOrDefault(ctx, nil)...)
deps.StaticLibs = append(deps.StaticLibs, library.StaticProperties.Static.Static_libs.GetOrDefault(ctx, nil)...)
deps.SharedLibs = append(deps.SharedLibs, library.StaticProperties.Static.Shared_libs.GetOrDefault(ctx, nil)...)
deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, library.StaticProperties.Static.Export_shared_lib_headers...)
deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, library.StaticProperties.Static.Export_static_lib_headers...)
@@ -852,9 +852,9 @@ func (library *libraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
if library.baseLinker.Properties.crtPadSegment() {
deps.CrtEnd = append(deps.CrtEnd, ctx.toolchain().CrtPadSegmentSharedLibrary()...)
}
deps.WholeStaticLibs = append(deps.WholeStaticLibs, library.SharedProperties.Shared.Whole_static_libs...)
deps.StaticLibs = append(deps.StaticLibs, library.SharedProperties.Shared.Static_libs...)
deps.SharedLibs = append(deps.SharedLibs, library.SharedProperties.Shared.Shared_libs...)
deps.WholeStaticLibs = append(deps.WholeStaticLibs, library.SharedProperties.Shared.Whole_static_libs.GetOrDefault(ctx, nil)...)
deps.StaticLibs = append(deps.StaticLibs, library.SharedProperties.Shared.Static_libs.GetOrDefault(ctx, nil)...)
deps.SharedLibs = append(deps.SharedLibs, library.SharedProperties.Shared.Shared_libs.GetOrDefault(ctx, nil)...)
deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, library.SharedProperties.Shared.Export_shared_lib_headers...)
deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, library.SharedProperties.Shared.Export_static_lib_headers...)
@@ -900,8 +900,8 @@ func (library *libraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
return deps
}
func (library *libraryDecorator) linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps {
specifiedDeps = library.baseLinker.linkerSpecifiedDeps(specifiedDeps)
func (library *libraryDecorator) linkerSpecifiedDeps(ctx android.ConfigAndErrorContext, module *Module, specifiedDeps specifiedDeps) specifiedDeps {
specifiedDeps = library.baseLinker.linkerSpecifiedDeps(ctx, module, specifiedDeps)
var properties StaticOrSharedProperties
if library.static() {
properties = library.StaticProperties.Static
@@ -909,7 +909,8 @@ func (library *libraryDecorator) linkerSpecifiedDeps(specifiedDeps specifiedDeps
properties = library.SharedProperties.Shared
}
specifiedDeps.sharedLibs = append(specifiedDeps.sharedLibs, properties.Shared_libs...)
eval := module.ConfigurableEvaluator(ctx)
specifiedDeps.sharedLibs = append(specifiedDeps.sharedLibs, properties.Shared_libs.GetOrDefault(eval, nil)...)
// Must distinguish nil and [] in system_shared_libs - ensure that [] in
// either input list doesn't come out as nil.
@@ -2079,12 +2080,12 @@ func reuseStaticLibrary(ctx android.BottomUpMutatorContext, shared *Module) {
// include directories.
if len(sharedCompiler.StaticProperties.Static.Cflags.GetOrDefault(ctx, nil)) == 0 &&
len(sharedCompiler.SharedProperties.Shared.Cflags.GetOrDefault(ctx, nil)) == 0 &&
len(sharedCompiler.StaticProperties.Static.Whole_static_libs) == 0 &&
len(sharedCompiler.SharedProperties.Shared.Whole_static_libs) == 0 &&
len(sharedCompiler.StaticProperties.Static.Static_libs) == 0 &&
len(sharedCompiler.SharedProperties.Shared.Static_libs) == 0 &&
len(sharedCompiler.StaticProperties.Static.Shared_libs) == 0 &&
len(sharedCompiler.SharedProperties.Shared.Shared_libs) == 0 &&
len(sharedCompiler.StaticProperties.Static.Whole_static_libs.GetOrDefault(ctx, nil)) == 0 &&
len(sharedCompiler.SharedProperties.Shared.Whole_static_libs.GetOrDefault(ctx, nil)) == 0 &&
len(sharedCompiler.StaticProperties.Static.Static_libs.GetOrDefault(ctx, nil)) == 0 &&
len(sharedCompiler.SharedProperties.Shared.Static_libs.GetOrDefault(ctx, nil)) == 0 &&
len(sharedCompiler.StaticProperties.Static.Shared_libs.GetOrDefault(ctx, nil)) == 0 &&
len(sharedCompiler.SharedProperties.Shared.Shared_libs.GetOrDefault(ctx, nil)) == 0 &&
// Compare System_shared_libs properties with nil because empty lists are
// semantically significant for them.
sharedCompiler.StaticProperties.Static.System_shared_libs == nil &&

View File

@@ -543,7 +543,7 @@ func (p *nativeLibInfoProperties) PopulateFromVariant(ctx android.SdkMemberConte
p.ExportedFlags = exportedInfo.Flags
if ccModule.linker != nil {
specifiedDeps := specifiedDeps{}
specifiedDeps = ccModule.linker.linkerSpecifiedDeps(specifiedDeps)
specifiedDeps = ccModule.linker.linkerSpecifiedDeps(ctx, ccModule, specifiedDeps)
if lib := ccModule.library; lib != nil {
if !lib.hasStubsVariants() {

View File

@@ -37,16 +37,16 @@ type BaseLinkerProperties struct {
// in their entirety. For static library modules, all of the .o files from the intermediate
// directory of the dependency will be linked into this modules .a file. For a shared library,
// the dependency's .a file will be linked into this module using -Wl,--whole-archive.
Whole_static_libs []string `android:"arch_variant,variant_prepend"`
Whole_static_libs proptools.Configurable[[]string] `android:"arch_variant,variant_prepend"`
// list of modules that should be statically linked into this module.
Static_libs []string `android:"arch_variant,variant_prepend"`
Static_libs proptools.Configurable[[]string] `android:"arch_variant,variant_prepend"`
// list of modules that should be dynamically linked into this module.
Shared_libs []string `android:"arch_variant"`
Shared_libs proptools.Configurable[[]string] `android:"arch_variant"`
// list of modules that should only provide headers for this module.
Header_libs []string `android:"arch_variant,variant_prepend"`
Header_libs proptools.Configurable[[]string] `android:"arch_variant,variant_prepend"`
// list of module-specific flags that will be used for all link steps
Ldflags []string `android:"arch_variant"`
@@ -296,10 +296,10 @@ func (linker *baseLinker) baseLinkerProps() BaseLinkerProperties {
}
func (linker *baseLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
deps.WholeStaticLibs = append(deps.WholeStaticLibs, linker.Properties.Whole_static_libs...)
deps.HeaderLibs = append(deps.HeaderLibs, linker.Properties.Header_libs...)
deps.StaticLibs = append(deps.StaticLibs, linker.Properties.Static_libs...)
deps.SharedLibs = append(deps.SharedLibs, linker.Properties.Shared_libs...)
deps.WholeStaticLibs = append(deps.WholeStaticLibs, linker.Properties.Whole_static_libs.GetOrDefault(ctx, nil)...)
deps.HeaderLibs = append(deps.HeaderLibs, linker.Properties.Header_libs.GetOrDefault(ctx, nil)...)
deps.StaticLibs = append(deps.StaticLibs, linker.Properties.Static_libs.GetOrDefault(ctx, nil)...)
deps.SharedLibs = append(deps.SharedLibs, linker.Properties.Shared_libs.GetOrDefault(ctx, nil)...)
deps.RuntimeLibs = append(deps.RuntimeLibs, linker.Properties.Runtime_libs...)
deps.ReexportHeaderLibHeaders = append(deps.ReexportHeaderLibHeaders, linker.Properties.Export_header_lib_headers...)
@@ -645,8 +645,9 @@ func (linker *baseLinker) link(ctx ModuleContext,
panic(fmt.Errorf("baseLinker doesn't know how to link"))
}
func (linker *baseLinker) linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps {
specifiedDeps.sharedLibs = append(specifiedDeps.sharedLibs, linker.Properties.Shared_libs...)
func (linker *baseLinker) linkerSpecifiedDeps(ctx android.ConfigAndErrorContext, module *Module, specifiedDeps specifiedDeps) specifiedDeps {
eval := module.ConfigurableEvaluator(ctx)
specifiedDeps.sharedLibs = append(specifiedDeps.sharedLibs, linker.Properties.Shared_libs.GetOrDefault(eval, nil)...)
// Must distinguish nil and [] in system_shared_libs - ensure that [] in
// either input list doesn't come out as nil.

View File

@@ -19,6 +19,8 @@ import (
"strings"
"android/soong/android"
"github.com/google/blueprint/proptools"
)
//
@@ -50,13 +52,13 @@ type objectLinker struct {
type ObjectLinkerProperties struct {
// list of static library modules that should only provide headers for this module.
Static_libs []string `android:"arch_variant,variant_prepend"`
Static_libs proptools.Configurable[[]string] `android:"arch_variant,variant_prepend"`
// list of shared library modules should only provide headers for this module.
Shared_libs []string `android:"arch_variant,variant_prepend"`
Shared_libs proptools.Configurable[[]string] `android:"arch_variant,variant_prepend"`
// list of modules that should only provide headers for this module.
Header_libs []string `android:"arch_variant,variant_prepend"`
Header_libs proptools.Configurable[[]string] `android:"arch_variant,variant_prepend"`
// list of default libraries that will provide headers for this module. If unset, generally
// defaults to libc, libm, and libdl. Set to [] to prevent using headers from the defaults.
@@ -116,9 +118,9 @@ func (object *objectLinker) linkerProps() []interface{} {
func (*objectLinker) linkerInit(ctx BaseModuleContext) {}
func (object *objectLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
deps.HeaderLibs = append(deps.HeaderLibs, object.Properties.Header_libs...)
deps.SharedLibs = append(deps.SharedLibs, object.Properties.Shared_libs...)
deps.StaticLibs = append(deps.StaticLibs, object.Properties.Static_libs...)
deps.HeaderLibs = append(deps.HeaderLibs, object.Properties.Header_libs.GetOrDefault(ctx, nil)...)
deps.SharedLibs = append(deps.SharedLibs, object.Properties.Shared_libs.GetOrDefault(ctx, nil)...)
deps.StaticLibs = append(deps.StaticLibs, object.Properties.Static_libs.GetOrDefault(ctx, nil)...)
deps.ObjFiles = append(deps.ObjFiles, object.Properties.Objs...)
deps.SystemSharedLibs = object.Properties.System_shared_libs
@@ -201,8 +203,9 @@ func (object *objectLinker) link(ctx ModuleContext,
return outputFile
}
func (object *objectLinker) linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps {
specifiedDeps.sharedLibs = append(specifiedDeps.sharedLibs, object.Properties.Shared_libs...)
func (object *objectLinker) linkerSpecifiedDeps(ctx android.ConfigAndErrorContext, module *Module, specifiedDeps specifiedDeps) specifiedDeps {
eval := module.ConfigurableEvaluator(ctx)
specifiedDeps.sharedLibs = append(specifiedDeps.sharedLibs, object.Properties.Shared_libs.GetOrDefault(eval, nil)...)
// Must distinguish nil and [] in system_shared_libs - ensure that [] in
// either input list doesn't come out as nil.

View File

@@ -393,8 +393,8 @@ func (b *bindgenDecorator) SourceProviderDeps(ctx DepsContext, deps Deps) Deps {
deps.StaticLibs = append(deps.StaticLibs, String(b.Properties.Static_inline_library))
}
deps.SharedLibs = append(deps.SharedLibs, b.ClangProperties.Shared_libs...)
deps.StaticLibs = append(deps.StaticLibs, b.ClangProperties.Static_libs...)
deps.HeaderLibs = append(deps.HeaderLibs, b.ClangProperties.Header_libs...)
deps.SharedLibs = append(deps.SharedLibs, b.ClangProperties.Shared_libs.GetOrDefault(ctx, nil)...)
deps.StaticLibs = append(deps.StaticLibs, b.ClangProperties.Static_libs.GetOrDefault(ctx, nil)...)
deps.HeaderLibs = append(deps.HeaderLibs, b.ClangProperties.Header_libs.GetOrDefault(ctx, nil)...)
return deps
}

View File

@@ -1989,6 +1989,14 @@ func (m *memberContext) IsTargetBuildBeforeTiramisu() bool {
return m.builder.targetBuildRelease.EarlierThan(buildReleaseT)
}
func (m *memberContext) Config() android.Config {
return m.sdkMemberContext.Config()
}
func (m *memberContext) OtherModulePropertyErrorf(module android.Module, property string, fmt string, args ...interface{}) {
m.sdkMemberContext.OtherModulePropertyErrorf(module, property, fmt, args)
}
var _ android.SdkMemberContext = (*memberContext)(nil)
func (s *sdk) createMemberSnapshot(ctx *memberContext, member *sdkMember, bpModule *bpModule) {