Add OtherModulePropertyErrorf
...and pass property name to ConfigurableEvaluator. When trying to convert Enabled to a configurable property, I enountered a bunch of different context types that all had different error methods. OtherModulePropertyErrorf is an error method that can be implemented by all contexts. Bug: 323382414 Test: m nothing --no-skip-soong-tests Change-Id: I38b2a545c0ee8d23281cd88bc397f79f39835bc4
This commit is contained in:
parent
894b318528
commit
4f968700d1
4 changed files with 48 additions and 26 deletions
27
context.go
27
context.go
|
@ -4125,9 +4125,34 @@ func (c *Context) ModuleErrorf(logicModule Module, format string,
|
|||
args ...interface{}) error {
|
||||
|
||||
module := c.moduleInfo[logicModule]
|
||||
return &BlueprintError{
|
||||
return &ModuleError{
|
||||
BlueprintError: BlueprintError{
|
||||
Err: fmt.Errorf(format, args...),
|
||||
Pos: module.pos,
|
||||
},
|
||||
module: module,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Context) PropertyErrorf(logicModule Module, property string, format string,
|
||||
args ...interface{}) error {
|
||||
|
||||
module := c.moduleInfo[logicModule]
|
||||
pos := module.propertyPos[property]
|
||||
|
||||
if !pos.IsValid() {
|
||||
pos = module.pos
|
||||
}
|
||||
|
||||
return &PropertyError{
|
||||
ModuleError: ModuleError{
|
||||
BlueprintError: BlueprintError{
|
||||
Err: fmt.Errorf(format, args...),
|
||||
Pos: pos,
|
||||
},
|
||||
module: module,
|
||||
},
|
||||
property: property,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -166,6 +166,9 @@ type EarlyModuleContext interface {
|
|||
// PropertyErrorf reports an error at the line number of a property in the module definition.
|
||||
PropertyErrorf(property, fmt string, args ...interface{})
|
||||
|
||||
// OtherModulePropertyErrorf reports an error at the line number of a property in the given module definition.
|
||||
OtherModulePropertyErrorf(logicModule Module, property string, format string, args ...interface{})
|
||||
|
||||
// Failed returns true if any errors have been reported. In most cases the module can continue with generating
|
||||
// build rules after an error, allowing it to report additional errors in a single run, but in cases where the error
|
||||
// has prevented the module from creating necessary data it can return early when Failed returns true.
|
||||
|
@ -454,34 +457,19 @@ func (d *baseModuleContext) Errorf(pos scanner.Position,
|
|||
func (d *baseModuleContext) ModuleErrorf(format string,
|
||||
args ...interface{}) {
|
||||
|
||||
d.error(&ModuleError{
|
||||
BlueprintError: BlueprintError{
|
||||
Err: fmt.Errorf(format, args...),
|
||||
Pos: d.module.pos,
|
||||
},
|
||||
module: d.module,
|
||||
})
|
||||
d.error(d.context.ModuleErrorf(d.module.logicModule, format, args...))
|
||||
}
|
||||
|
||||
func (d *baseModuleContext) PropertyErrorf(property, format string,
|
||||
args ...interface{}) {
|
||||
|
||||
pos := d.module.propertyPos[property]
|
||||
|
||||
if !pos.IsValid() {
|
||||
pos = d.module.pos
|
||||
d.error(d.context.PropertyErrorf(d.module.logicModule, property, format, args...))
|
||||
}
|
||||
|
||||
d.error(&PropertyError{
|
||||
ModuleError: ModuleError{
|
||||
BlueprintError: BlueprintError{
|
||||
Err: fmt.Errorf(format, args...),
|
||||
Pos: pos,
|
||||
},
|
||||
module: d.module,
|
||||
},
|
||||
property: property,
|
||||
})
|
||||
func (d *baseModuleContext) OtherModulePropertyErrorf(logicModule Module, property string, format string,
|
||||
args ...interface{}) {
|
||||
|
||||
d.error(d.context.PropertyErrorf(logicModule, property, format, args...))
|
||||
}
|
||||
|
||||
func (d *baseModuleContext) Failed() bool {
|
||||
|
|
|
@ -28,7 +28,7 @@ type ConfigurableElements interface {
|
|||
}
|
||||
|
||||
type ConfigurableEvaluator interface {
|
||||
EvaluateConfiguration(parser.SelectType, string) (string, bool)
|
||||
EvaluateConfiguration(typ parser.SelectType, property, condition string) (string, bool)
|
||||
PropertyErrorf(property, fmt string, args ...interface{})
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ func (c *Configurable[T]) evaluateNonTransitive(evaluator ConfigurableEvaluator)
|
|||
}
|
||||
return &result
|
||||
}
|
||||
val, defined := evaluator.EvaluateConfiguration(c.typ, c.condition)
|
||||
val, defined := evaluator.EvaluateConfiguration(c.typ, c.propertyName, c.condition)
|
||||
if !defined {
|
||||
if result, ok := c.cases[default_select_branch_name]; ok {
|
||||
return &result
|
||||
|
|
|
@ -60,6 +60,9 @@ type SingletonContext interface {
|
|||
// Errorf reports an error at the specified position of the module definition file.
|
||||
Errorf(format string, args ...interface{})
|
||||
|
||||
// OtherModulePropertyErrorf reports an error on the line number of the given property of the given module
|
||||
OtherModulePropertyErrorf(module Module, property string, format string, args ...interface{})
|
||||
|
||||
// Failed returns true if any errors have been reported. In most cases the singleton can continue with generating
|
||||
// build rules after an error, allowing it to report additional errors in a single run, but in cases where the error
|
||||
// has prevented the singleton from creating necessary data it can return early when Failed returns true.
|
||||
|
@ -224,6 +227,12 @@ func (s *singletonContext) Errorf(format string, args ...interface{}) {
|
|||
s.error(fmt.Errorf(format, args...))
|
||||
}
|
||||
|
||||
func (s *singletonContext) OtherModulePropertyErrorf(logicModule Module, property string, format string,
|
||||
args ...interface{}) {
|
||||
|
||||
s.error(s.context.PropertyErrorf(logicModule, property, format, args...))
|
||||
}
|
||||
|
||||
func (s *singletonContext) Failed() bool {
|
||||
return len(s.errs) > 0
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue