From 3a7822c57193a42ffe0dcb67e77be1dfded2c2a8 Mon Sep 17 00:00:00 2001 From: Jeff Gaston Date: Thu, 5 Oct 2017 18:17:53 -0700 Subject: [PATCH] Have bpfix not remove empty lists Since in some cases they're not the default value. Test: echo "cc_defaults{ system_shared_libs:[] }" | bpfix | grep system_shared_libs > /dev/null && echo ok Bug: 66979076 Change-Id: I760b34f980281b955972819676bd62154a6c73f5 --- bpfix/bpfix/bpfix.go | 38 +------------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/bpfix/bpfix/bpfix.go b/bpfix/bpfix/bpfix.go index 124949438..fcd4fecf7 100644 --- a/bpfix/bpfix/bpfix.go +++ b/bpfix/bpfix/bpfix.go @@ -19,6 +19,7 @@ package bpfix import ( "bytes" "fmt" + "github.com/google/blueprint/parser" ) @@ -26,7 +27,6 @@ import ( // A FixRequest doesn't specify whether to do a dry run or where to write the results; that's in cmd/bpfix.go type FixRequest struct { simplifyKnownRedundantVariables bool - removeEmptyLists bool } func NewFixRequest() FixRequest { @@ -36,7 +36,6 @@ func NewFixRequest() FixRequest { func (r FixRequest) AddAll() (result FixRequest) { result = r result.simplifyKnownRedundantVariables = true - result.removeEmptyLists = true return result } @@ -89,12 +88,6 @@ func fixTreeOnce(tree *parser.File, config FixRequest) (fixed *parser.File, err return nil, err } } - if config.removeEmptyLists { - tree, err = removePropertiesHavingTheirDefaultValues(tree) - if err != nil { - return nil, err - } - } return tree, err } @@ -154,32 +147,3 @@ func removeMatchingModuleListProperties(tree *parser.File, canonicalName string, } return tree, nil } - -func removePropertiesHavingTheirDefaultValues(tree *parser.File) (fixed *parser.File, err error) { - for _, def := range tree.Defs { - mod, ok := def.(*parser.Module) - if !ok { - continue - } - writeIndex := 0 - for _, prop := range mod.Properties { - val := prop.Value - keep := true - switch val := val.(type) { - case *parser.List: - if len(val.Values) == 0 { - keep = false - } - break - default: - keep = true - } - if keep { - mod.Properties[writeIndex] = prop - writeIndex++ - } - } - mod.Properties = mod.Properties[:writeIndex] - } - return tree, nil -}