Add VendorConfig for board-level Soong plugin configuration
This allows Soong (Go) plugins to get custom configurations set in the current product's BoardConfig.mk. I'll have some more comprehensive documentation later, but the general concept is that you'd have one namespace per plugin, defined in the BoardConfig.mk (though they would work in the product.mk files too): SOONG_CONFIG_NAMESPACES += myPlugin Within that namespace you can set key-value pairs: SOONG_CONFIG_myPlugin := key1 key2 ... ... SOONG_CONFIG_myPlugin_key1 := value ... SOONG_CONFIG_myPlugin_key2 := true Then in your plugin, you can ask for your namespace: vars := ctx.Config().VendorConfig("myPlugin") And then use them: str := vars.String("key1") if vars.Bool("key2") { ... } if vars.IsSet("key3") { ... } Warning: It's not a good idea to fail on missing inputs, since an android tree may contain plugins from multiple owners, and we may configure your modules (but not build/install them) even if they're not meant for the currently configured product. Bug: 76168832 Test: define some variables, use them Test: m blueprint_tools Change-Id: I4c38f5a4344022c6f332de279d9bbef24502e741
This commit is contained in:
@@ -65,6 +65,20 @@ type DeviceConfig struct {
|
||||
*deviceConfig
|
||||
}
|
||||
|
||||
type VendorConfig interface {
|
||||
// Bool interprets the variable named `name` as a boolean, returning true if, after
|
||||
// lowercasing, it matches one of "1", "y", "yes", "on", or "true". Unset, or any other
|
||||
// value will return false.
|
||||
Bool(name string) bool
|
||||
|
||||
// String returns the string value of `name`. If the variable was not set, it will
|
||||
// return the empty string.
|
||||
String(name string) string
|
||||
|
||||
// IsSet returns whether the variable `name` was set by Make.
|
||||
IsSet(name string) bool
|
||||
}
|
||||
|
||||
type config struct {
|
||||
FileConfigurableOptions
|
||||
productVariables productVariables
|
||||
@@ -107,6 +121,8 @@ type deviceConfig struct {
|
||||
OncePer
|
||||
}
|
||||
|
||||
type vendorConfig map[string]string
|
||||
|
||||
type jsonConfigurable interface {
|
||||
SetDefaultConfig()
|
||||
}
|
||||
@@ -788,6 +804,24 @@ func (c *config) CFIEnabledForPath(path string) bool {
|
||||
return PrefixInList(path, *c.productVariables.CFIIncludePaths)
|
||||
}
|
||||
|
||||
func (c *config) VendorConfig(name string) VendorConfig {
|
||||
return vendorConfig(c.productVariables.VendorVars[name])
|
||||
}
|
||||
|
||||
func (c vendorConfig) Bool(name string) bool {
|
||||
v := strings.ToLower(c[name])
|
||||
return v == "1" || v == "y" || v == "yes" || v == "on" || v == "true"
|
||||
}
|
||||
|
||||
func (c vendorConfig) String(name string) string {
|
||||
return c[name]
|
||||
}
|
||||
|
||||
func (c vendorConfig) IsSet(name string) bool {
|
||||
_, ok := c[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
func stringSlice(s *[]string) []string {
|
||||
if s != nil {
|
||||
return *s
|
||||
|
@@ -84,3 +84,10 @@ func TestProductConfigAnnotations(t *testing.T) {
|
||||
t.Errorf(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestMissingVendorConfig(t *testing.T) {
|
||||
c := &config{}
|
||||
if c.VendorConfig("test").Bool("not_set") {
|
||||
t.Errorf("Expected false")
|
||||
}
|
||||
}
|
||||
|
@@ -205,6 +205,8 @@ type productVariables struct {
|
||||
NamespacesToExport []string `json:",omitempty"`
|
||||
|
||||
PgoAdditionalProfileDirs []string `json:",omitempty"`
|
||||
|
||||
VendorVars map[string]map[string]string `json:",omitempty"`
|
||||
}
|
||||
|
||||
func boolPtr(v bool) *bool {
|
||||
|
Reference in New Issue
Block a user