aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCole Faust <colefaust@google.com>2024-03-21 17:52:10 -0700
committerCole Faust <colefaust@google.com>2024-03-22 13:02:51 -0700
commit4f968700d169e19677b7d15ccadf6695622f76f0 (patch)
treec2dd7b8f240434ee017d5da900d4e2216b81559b
parent894b3185285af9a7d866c7c3cafea52a488d9f48 (diff)
downloadblueprint-4f968700d169e19677b7d15ccadf6695622f76f0.tar.gz
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
-rw-r--r--context.go31
-rw-r--r--module_ctx.go30
-rw-r--r--proptools/configurable.go4
-rw-r--r--singleton_ctx.go9
4 files changed, 48 insertions, 26 deletions
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
}