Browse Source

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
Jeff Gaston 6 years ago
parent
commit
3a7822c571
1 changed files with 1 additions and 37 deletions
  1. 1 37
      bpfix/bpfix/bpfix.go

+ 1 - 37
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
-}