bpmodify: Add a set-bool flag to set single boolean values
This is treated similar to other set commands, but add a single boolean value to the property. Test: bpmodify_test.go Test: bpmodify -d -m android.hardware.drm -property frozen -set-bool false Android.bp Test: Same command above with "true" "misspelled" "1" for -set-bool Bug: 231903487 Change-Id: I598da41a38409877af410f9715838d86b0873173
This commit is contained in:
parent
645184efb0
commit
753a555fdd
2 changed files with 62 additions and 5 deletions
|
@ -8,7 +8,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/google/blueprint/parser"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
@ -17,6 +16,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
|
"github.com/google/blueprint/parser"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -34,6 +35,7 @@ var (
|
||||||
newLocation string
|
newLocation string
|
||||||
setString *string
|
setString *string
|
||||||
addLiteral *string
|
addLiteral *string
|
||||||
|
setBool *string
|
||||||
replaceProperty = new(replacements)
|
replaceProperty = new(replacements)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -43,10 +45,11 @@ func init() {
|
||||||
flag.StringVar(&newLocation, "new-location", "", " use with moveProperty to move contents of -property into a property with name -new-location ")
|
flag.StringVar(&newLocation, "new-location", "", " use with moveProperty to move contents of -property into a property with name -new-location ")
|
||||||
flag.Var(targetedProperties, "property", "comma-separated list of fully qualified `name`s of properties to modify (default \"deps\")")
|
flag.Var(targetedProperties, "property", "comma-separated list of fully qualified `name`s of properties to modify (default \"deps\")")
|
||||||
flag.Var(addIdents, "a", "comma or whitespace separated list of identifiers to add")
|
flag.Var(addIdents, "a", "comma or whitespace separated list of identifiers to add")
|
||||||
flag.Var(stringPtrFlag{&addLiteral}, "add-literal", "a literal to add")
|
flag.Var(stringPtrFlag{&addLiteral}, "add-literal", "a literal to add to a list")
|
||||||
flag.Var(removeIdents, "r", "comma or whitespace separated list of identifiers to remove")
|
flag.Var(removeIdents, "r", "comma or whitespace separated list of identifiers to remove")
|
||||||
flag.Var(stringPtrFlag{&setString}, "str", "set a string property")
|
flag.Var(stringPtrFlag{&setString}, "str", "set a string property")
|
||||||
flag.Var(replaceProperty, "replace-property", "property names to be replaced, in the form of oldName1=newName1,oldName2=newName2")
|
flag.Var(replaceProperty, "replace-property", "property names to be replaced, in the form of oldName1=newName1,oldName2=newName2")
|
||||||
|
flag.Var(stringPtrFlag{&setBool}, "set-bool", "a boolean value to set a property with (not a list)")
|
||||||
flag.Usage = usage
|
flag.Usage = usage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,6 +157,9 @@ func processModuleProperty(module *parser.Module, moduleName string,
|
||||||
} else if setString != nil {
|
} else if setString != nil {
|
||||||
// We setting a non-existent string property, so we need to create it first.
|
// We setting a non-existent string property, so we need to create it first.
|
||||||
prop, modified, err = createRecursiveProperty(module, property.name(), property.prefixes(), &parser.String{})
|
prop, modified, err = createRecursiveProperty(module, property.name(), property.prefixes(), &parser.String{})
|
||||||
|
} else if setBool != nil {
|
||||||
|
// We are setting a non-existent property, so we need to create it first.
|
||||||
|
prop, modified, err = createRecursiveProperty(module, property.name(), property.prefixes(), &parser.Bool{})
|
||||||
} else {
|
} else {
|
||||||
// We cannot find an existing prop, and we aren't adding anything to the prop,
|
// We cannot find an existing prop, and we aren't adding anything to the prop,
|
||||||
// which means we must be removing something from a non-existing prop,
|
// which means we must be removing something from a non-existing prop,
|
||||||
|
@ -278,6 +284,21 @@ func processParameter(value parser.Expression, paramName, moduleName string,
|
||||||
}
|
}
|
||||||
list.Values = append(list.Values, value)
|
list.Values = append(list.Values, value)
|
||||||
modified = true
|
modified = true
|
||||||
|
} else if setBool != nil {
|
||||||
|
res, ok := value.(*parser.Bool)
|
||||||
|
if !ok {
|
||||||
|
return false, []error{fmt.Errorf("expected parameter %s in module %s to be bool, found %s",
|
||||||
|
paramName, moduleName, value.Type().String())}
|
||||||
|
}
|
||||||
|
if *setBool == "true" {
|
||||||
|
res.Value = true
|
||||||
|
} else if *setBool == "false" {
|
||||||
|
res.Value = false
|
||||||
|
} else {
|
||||||
|
return false, []error{fmt.Errorf("expected parameter %s to be true or false, found %s",
|
||||||
|
paramName, *setBool)}
|
||||||
|
}
|
||||||
|
modified = true
|
||||||
} else if setString != nil {
|
} else if setString != nil {
|
||||||
str, ok := value.(*parser.String)
|
str, ok := value.(*parser.String)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -345,7 +366,7 @@ func main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(addIdents.idents) == 0 && len(removeIdents.idents) == 0 && setString == nil && addLiteral == nil && !*removeProperty && !*moveProperty && (*replaceProperty).size() == 0 {
|
if len(addIdents.idents) == 0 && len(removeIdents.idents) == 0 && setString == nil && addLiteral == nil && !*removeProperty && !*moveProperty && (*replaceProperty).size() == 0 && setBool == nil {
|
||||||
report(fmt.Errorf("-a, -add-literal, -r, -remove-property, -move-property, replace-property or -str parameter is required"))
|
report(fmt.Errorf("-a, -add-literal, -r, -remove-property, -move-property, replace-property or -str parameter is required"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,11 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/blueprint/parser"
|
|
||||||
"github.com/google/blueprint/proptools"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/blueprint/parser"
|
||||||
|
"github.com/google/blueprint/proptools"
|
||||||
)
|
)
|
||||||
|
|
||||||
var testCases = []struct {
|
var testCases = []struct {
|
||||||
|
@ -29,6 +30,7 @@ var testCases = []struct {
|
||||||
removeSet string
|
removeSet string
|
||||||
addLiteral *string
|
addLiteral *string
|
||||||
setString *string
|
setString *string
|
||||||
|
setBool *string
|
||||||
removeProperty bool
|
removeProperty bool
|
||||||
replaceProperty string
|
replaceProperty string
|
||||||
moveProperty bool
|
moveProperty bool
|
||||||
|
@ -306,6 +308,39 @@ var testCases = []struct {
|
||||||
property: "foo",
|
property: "foo",
|
||||||
setString: proptools.StringPtr("bar"),
|
setString: proptools.StringPtr("bar"),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "set bool",
|
||||||
|
input: `
|
||||||
|
cc_foo {
|
||||||
|
name: "foo",
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
output: `
|
||||||
|
cc_foo {
|
||||||
|
name: "foo",
|
||||||
|
foo: true,
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
property: "foo",
|
||||||
|
setBool: proptools.StringPtr("true"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "set existing bool",
|
||||||
|
input: `
|
||||||
|
cc_foo {
|
||||||
|
name: "foo",
|
||||||
|
foo: true,
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
output: `
|
||||||
|
cc_foo {
|
||||||
|
name: "foo",
|
||||||
|
foo: false,
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
property: "foo",
|
||||||
|
setBool: proptools.StringPtr("false"),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "remove existing property",
|
name: "remove existing property",
|
||||||
input: `
|
input: `
|
||||||
|
@ -516,6 +551,7 @@ func TestProcessModule(t *testing.T) {
|
||||||
moveProperty = &testCase.moveProperty
|
moveProperty = &testCase.moveProperty
|
||||||
newLocation = testCase.newLocation
|
newLocation = testCase.newLocation
|
||||||
setString = testCase.setString
|
setString = testCase.setString
|
||||||
|
setBool = testCase.setBool
|
||||||
addLiteral = testCase.addLiteral
|
addLiteral = testCase.addLiteral
|
||||||
replaceProperty.Set(testCase.replaceProperty)
|
replaceProperty.Set(testCase.replaceProperty)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue