Add OtherModulePropertyErrorf am: 4f968700d1

Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/3010376

Change-Id: I2c196005d97516e273d56b8637f54d5e151db202
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Cole Faust 2024-03-26 21:11:15 +00:00 committed by Automerger Merge Worker
commit f4551ed37f
4 changed files with 48 additions and 26 deletions

View file

@ -4125,9 +4125,34 @@ func (c *Context) ModuleErrorf(logicModule Module, format string,
args ...interface{}) error {
module := c.moduleInfo[logicModule]
return &BlueprintError{
Err: fmt.Errorf(format, args...),
Pos: module.pos,
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,
}
}

View file

@ -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]
d.error(d.context.PropertyErrorf(d.module.logicModule, property, format, args...))
}
if !pos.IsValid() {
pos = d.module.pos
}
func (d *baseModuleContext) OtherModulePropertyErrorf(logicModule Module, property string, format string,
args ...interface{}) {
d.error(&PropertyError{
ModuleError: ModuleError{
BlueprintError: BlueprintError{
Err: fmt.Errorf(format, args...),
Pos: pos,
},
module: d.module,
},
property: property,
})
d.error(d.context.PropertyErrorf(logicModule, property, format, args...))
}
func (d *baseModuleContext) Failed() bool {

View file

@ -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

View file

@ -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
}