From bdd8aeeb58d08630fad0e70df69cd4afa22e45cd Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Thu, 14 Mar 2024 14:33:02 -0700 Subject: Make select statements work on path properties Fixes: 329711542 Test: go test Change-Id: I71f489c26c535174e226e4a9ab449cc2b4bee83a --- android/path_properties.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'android/path_properties.go') diff --git a/android/path_properties.go b/android/path_properties.go index bbfaa8c46..ea925654e 100644 --- a/android/path_properties.go +++ b/android/path_properties.go @@ -47,7 +47,7 @@ func addPathDepsForProps(ctx BottomUpMutatorContext, props []interface{}) { // tagged with `android:"path"`. var pathProperties []string for _, ps := range props { - pathProperties = append(pathProperties, pathPropertiesForPropertyStruct(ps)...) + pathProperties = append(pathProperties, pathPropertiesForPropertyStruct(ctx, ps)...) } // Remove duplicates to avoid multiple dependencies. @@ -64,7 +64,7 @@ func addPathDepsForProps(ctx BottomUpMutatorContext, props []interface{}) { // pathPropertiesForPropertyStruct uses the indexes of properties that are tagged with // android:"path" to extract all their values from a property struct, returning them as a single // slice of strings. -func pathPropertiesForPropertyStruct(ps interface{}) []string { +func pathPropertiesForPropertyStruct(ctx BottomUpMutatorContext, ps interface{}) []string { v := reflect.ValueOf(ps) if v.Kind() != reflect.Ptr || v.Elem().Kind() != reflect.Struct { panic(fmt.Errorf("type %s is not a pointer to a struct", v.Type())) @@ -106,6 +106,16 @@ func pathPropertiesForPropertyStruct(ps interface{}) []string { ret = append(ret, sv.String()) case reflect.Slice: ret = append(ret, sv.Interface().([]string)...) + case reflect.Struct: + intf := sv.Interface() + if configurable, ok := intf.(proptools.Configurable[string]); ok { + ret = append(ret, proptools.String(configurable.Evaluate(ctx))) + } else if configurable, ok := intf.(proptools.Configurable[[]string]); ok { + ret = append(ret, proptools.Slice(configurable.Evaluate(ctx))...) + } else { + panic(fmt.Errorf(`field %s in type %s has tag android:"path" but is not a string or slice of strings, it is a %s`, + v.Type().FieldByIndex(i).Name, v.Type(), sv.Type())) + } default: panic(fmt.Errorf(`field %s in type %s has tag android:"path" but is not a string or slice of strings, it is a %s`, v.Type().FieldByIndex(i).Name, v.Type(), sv.Type())) -- cgit v1.2.3-59-g8ed1b