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
This commit is contained in:
parent
c21d11850d
commit
3a7822c571
|
@ -19,6 +19,7 @@ package bpfix
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/google/blueprint/parser"
|
"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
|
// 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 {
|
type FixRequest struct {
|
||||||
simplifyKnownRedundantVariables bool
|
simplifyKnownRedundantVariables bool
|
||||||
removeEmptyLists bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFixRequest() FixRequest {
|
func NewFixRequest() FixRequest {
|
||||||
|
@ -36,7 +36,6 @@ func NewFixRequest() FixRequest {
|
||||||
func (r FixRequest) AddAll() (result FixRequest) {
|
func (r FixRequest) AddAll() (result FixRequest) {
|
||||||
result = r
|
result = r
|
||||||
result.simplifyKnownRedundantVariables = true
|
result.simplifyKnownRedundantVariables = true
|
||||||
result.removeEmptyLists = true
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,12 +88,6 @@ func fixTreeOnce(tree *parser.File, config FixRequest) (fixed *parser.File, err
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if config.removeEmptyLists {
|
|
||||||
tree, err = removePropertiesHavingTheirDefaultValues(tree)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tree, err
|
return tree, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,32 +147,3 @@ func removeMatchingModuleListProperties(tree *parser.File, canonicalName string,
|
||||||
}
|
}
|
||||||
return tree, nil
|
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
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue