debugValue: handle Interfaces better. am: 89e90b4c60 am: 34847c828d

Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2975295

Change-Id: I0656d3ea8a02e73f164bd89fa507fbaa8d7a6ead
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
LaMont Jones 2024-02-26 21:15:51 +00:00 committed by Automerger Merge Worker
commit 25e25de53e

View file

@ -5010,8 +5010,10 @@ func debugKey(value reflect.Value) string {
// Convert a single value (possibly a map or slice too) in a reflect.Value to a value suitable for outputting to json
func debugValue(value reflect.Value) interface{} {
// Remember if we originally received a reflect.Interface.
wasInterface := value.Kind() == reflect.Interface
// Dereference pointers down to the real type
for value.Kind() == reflect.Ptr {
for value.Kind() == reflect.Ptr || value.Kind() == reflect.Interface {
// If it's nil, return nil
if value.IsNil() {
return nil
@ -5030,13 +5032,17 @@ func debugValue(value reflect.Value) interface{} {
case reflect.Slice:
return debugSlice(value)
case reflect.Struct:
// If we originally received an interface, and there is a String() method, call that.
// TODO: figure out why Path doesn't work correctly otherwise (in aconfigPropagatingDeclarationsInfo)
if s, ok := value.Interface().(interface{ String() string }); wasInterface && ok {
return s.String()
}
return debugStruct(value)
case reflect.Map:
return debugMap(value)
case reflect.Interface:
// ???
default:
// ???
// TODO: add cases as we find them.
return fmt.Sprintf("debugValue(Kind=%v, wasInterface=%v)", kind, wasInterface)
}
return nil