summaryrefslogtreecommitdiff
path: root/android/variable.go
diff options
context:
space:
mode:
author Liz Kammer <eakammer@google.com> 2021-03-31 21:17:47 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2021-03-31 21:17:47 +0000
commitfc8bc62d2a72cb7e6ec55e2ae201f8fc9962f194 (patch)
tree73ae656acd27fe0ecd13a76e1850de6c9f4d8951 /android/variable.go
parent9af11134ff6220c594814b4162895f917dd1462a (diff)
parent263bdc570c347fa90c795dbb693061b82d5684df (diff)
Merge "Handle product_variable asflag for cc_object." am: acacbc1166 am: 2cc845060d am: 263bdc570c
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1652787 Change-Id: I6f9fd6727fd3eb0a5fdf3b0ccd324fed24a05be6
Diffstat (limited to 'android/variable.go')
-rw-r--r--android/variable.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/android/variable.go b/android/variable.go
index 57a01a4bb..859a0b0b0 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -449,6 +449,63 @@ func (v *productVariables) SetDefaultConfig() {
}
}
+// ProductConfigContext requires the access to the Module to get product config properties.
+type ProductConfigContext interface {
+ Module() Module
+}
+
+// ProductConfigProperty contains the information for a single property (may be a struct) paired
+// with the appropriate ProductConfigVariable.
+type ProductConfigProperty struct {
+ ProductConfigVariable string
+ Property interface{}
+}
+
+// ProductConfigProperties is a map of property name to a slice of ProductConfigProperty such that
+// all it all product variable-specific versions of a property are easily accessed together
+type ProductConfigProperties map[string][]ProductConfigProperty
+
+// ProductVariableProperties returns a ProductConfigProperties containing only the properties which
+// have been set for the module in the given context.
+func ProductVariableProperties(ctx ProductConfigContext) ProductConfigProperties {
+ module := ctx.Module()
+ moduleBase := module.base()
+
+ productConfigProperties := ProductConfigProperties{}
+
+ if moduleBase.variableProperties == nil {
+ return productConfigProperties
+ }
+
+ variableValues := reflect.ValueOf(moduleBase.variableProperties).Elem().FieldByName("Product_variables")
+ for i := 0; i < variableValues.NumField(); i++ {
+ variableValue := variableValues.Field(i)
+ // Check if any properties were set for the module
+ if variableValue.IsZero() {
+ continue
+ }
+ // e.g. Platform_sdk_version, Unbundled_build, Malloc_not_svelte, etc.
+ productVariableName := variableValues.Type().Field(i).Name
+ for j := 0; j < variableValue.NumField(); j++ {
+ property := variableValue.Field(j)
+ // If the property wasn't set, no need to pass it along
+ if property.IsZero() {
+ continue
+ }
+
+ // e.g. Asflags, Cflags, Enabled, etc.
+ propertyName := variableValue.Type().Field(j).Name
+ productConfigProperties[propertyName] = append(productConfigProperties[propertyName],
+ ProductConfigProperty{
+ ProductConfigVariable: productVariableName,
+ Property: property.Interface(),
+ })
+ }
+ }
+
+ return productConfigProperties
+}
+
func VariableMutator(mctx BottomUpMutatorContext) {
var module Module
var ok bool