diff --git a/context.go b/context.go index 6ec1641..40b0789 100644 --- a/context.go +++ b/context.go @@ -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, } } diff --git a/module_ctx.go b/module_ctx.go index cb86f43..6650503 100644 --- a/module_ctx.go +++ b/module_ctx.go @@ -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 { diff --git a/proptools/configurable.go b/proptools/configurable.go index 4ca92fc..46c98fd 100644 --- a/proptools/configurable.go +++ b/proptools/configurable.go @@ -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 diff --git a/singleton_ctx.go b/singleton_ctx.go index e600cfd..fdcf2a9 100644 --- a/singleton_ctx.go +++ b/singleton_ctx.go @@ -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 }