From f0006e713787420e3a449747302d2ad833a43264 Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Mon, 19 Aug 2024 14:39:19 -0700 Subject: [PATCH] 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 --- android/sdk.go | 1 + cc/binary_sdk_member.go | 2 +- cc/cc.go | 2 +- cc/cmake_module_cc.txt | 8 ++++---- cc/cmake_snapshot.go | 20 ++++++++++++++++++-- cc/compiler.go | 6 +++--- cc/library.go | 41 ++++++++++++++++++++-------------------- cc/library_sdk_member.go | 2 +- cc/linker.go | 21 ++++++++++---------- cc/object.go | 19 +++++++++++-------- rust/bindgen.go | 6 +++--- sdk/update.go | 8 ++++++++ 12 files changed, 83 insertions(+), 53 deletions(-) diff --git a/android/sdk.go b/android/sdk.go index 4bcbe2e7a..d3f04a4f9 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -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. diff --git a/cc/binary_sdk_member.go b/cc/binary_sdk_member.go index 71e0cd8ce..8a7ea8845 100644 --- a/cc/binary_sdk_member.go +++ b/cc/binary_sdk_member.go @@ -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 diff --git a/cc/cc.go b/cc/cc.go index b3cac6256..947dc1aee 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -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) } diff --git a/cc/cmake_module_cc.txt b/cc/cmake_module_cc.txt index 0dc45aed1..0f6e62f10 100644 --- a/cc/cmake_module_cc.txt +++ b/cc/cmake_module_cc.txt @@ -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>> diff --git a/cc/cmake_snapshot.go b/cc/cmake_snapshot.go index 9159156b9..db1e619f9 100644 --- a/cc/cmake_snapshot.go +++ b/cc/cmake_snapshot.go @@ -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 { diff --git a/cc/compiler.go b/cc/compiler.go index 0e0b9a72d..396ec886b 100644 --- a/cc/compiler.go +++ b/cc/compiler.go @@ -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"` diff --git a/cc/library.go b/cc/library.go index de0070a15..60178484f 100644 --- a/cc/library.go +++ b/cc/library.go @@ -152,11 +152,11 @@ 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"` - System_shared_libs []string `android:"arch_variant"` + Enabled *bool `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"` Export_static_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 && diff --git a/cc/library_sdk_member.go b/cc/library_sdk_member.go index e8a98274c..053c46069 100644 --- a/cc/library_sdk_member.go +++ b/cc/library_sdk_member.go @@ -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() { diff --git a/cc/linker.go b/cc/linker.go index d2974c204..00568177f 100644 --- a/cc/linker.go +++ b/cc/linker.go @@ -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. diff --git a/cc/object.go b/cc/object.go index 8b23295c7..a4f4c8408 100644 --- a/cc/object.go +++ b/cc/object.go @@ -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. diff --git a/rust/bindgen.go b/rust/bindgen.go index a81024acd..31aa13725 100644 --- a/rust/bindgen.go +++ b/rust/bindgen.go @@ -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 } diff --git a/sdk/update.go b/sdk/update.go index 198c8d4a8..a4b1967af 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -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) {