aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCole Faust <colefaust@google.com>2024-03-26 20:55:34 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-03-26 20:55:34 +0000
commit3e39bb6025c4b5c654156e2ae081ac5fa335f8ab (patch)
tree0c2bc44c9de5836d0d484d3288a756469f7ff8ea
parentddde9e29a477ed46d14411c4d252df50e68ee114 (diff)
parent02987bd9d275fde4dc47fc404644748d5639bd72 (diff)
downloadsoong-3e39bb6025c4b5c654156e2ae081ac5fa335f8ab.tar.gz
Merge "Implement OtherModulePropertyErrorf proxies" into main
-rw-r--r--android/base_module_context.go38
-rw-r--r--android/early_module_context.go10
-rw-r--r--android/module.go66
-rw-r--r--android/module_context.go2
-rw-r--r--android/singleton.go7
5 files changed, 87 insertions, 36 deletions
diff --git a/android/base_module_context.go b/android/base_module_context.go
index 3367b0669..c4922f4bc 100644
--- a/android/base_module_context.go
+++ b/android/base_module_context.go
@@ -219,7 +219,7 @@ type BaseModuleContext interface {
// EvaluateConfiguration makes ModuleContext a valid proptools.ConfigurableEvaluator, so this context
// can be used to evaluate the final value of Configurable properties.
- EvaluateConfiguration(parser.SelectType, string) (string, bool)
+ EvaluateConfiguration(parser.SelectType, string, string) (string, bool)
}
type baseModuleContext struct {
@@ -577,38 +577,6 @@ func (b *baseModuleContext) GetPathString(skipFirst bool) string {
return sb.String()
}
-func (m *baseModuleContext) EvaluateConfiguration(ty parser.SelectType, condition string) (string, bool) {
- switch ty {
- case parser.SelectTypeReleaseVariable:
- if v, ok := m.Config().productVariables.BuildFlags[condition]; ok {
- return v, true
- }
- return "", false
- case parser.SelectTypeProductVariable:
- // TODO(b/323382414): Might add these on a case-by-case basis
- m.ModuleErrorf("TODO(b/323382414): Product variables are not yet supported in selects")
- return "", false
- case parser.SelectTypeSoongConfigVariable:
- parts := strings.Split(condition, ":")
- namespace := parts[0]
- variable := parts[1]
- if n, ok := m.Config().productVariables.VendorVars[namespace]; ok {
- if v, ok := n[variable]; ok {
- return v, true
- }
- }
- return "", false
- case parser.SelectTypeVariant:
- if condition == "arch" {
- if !m.ArchReady() {
- m.ModuleErrorf("A select on arch was attempted before the arch mutator ran")
- return "", false
- }
- return m.Arch().ArchType.Name, true
- }
- m.ModuleErrorf("Unknown variant " + condition)
- return "", false
- default:
- panic("Should be unreachable")
- }
+func (m *baseModuleContext) EvaluateConfiguration(ty parser.SelectType, property, condition string) (string, bool) {
+ return m.Module().ConfigurableEvaluator(m).EvaluateConfiguration(ty, property, condition)
}
diff --git a/android/early_module_context.go b/android/early_module_context.go
index 8f7577358..cf1b5fcab 100644
--- a/android/early_module_context.go
+++ b/android/early_module_context.go
@@ -15,9 +15,10 @@
package android
import (
- "github.com/google/blueprint"
"os"
"text/scanner"
+
+ "github.com/google/blueprint"
)
// EarlyModuleContext provides methods that can be called early, as soon as the properties have
@@ -54,6 +55,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(module Module, property, fmt 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.
@@ -167,3 +171,7 @@ func (e *earlyModuleContext) SystemExtSpecific() bool {
func (e *earlyModuleContext) Namespace() *Namespace {
return e.EarlyModuleContext.Namespace().(*Namespace)
}
+
+func (e *earlyModuleContext) OtherModulePropertyErrorf(module Module, property string, fmt string, args ...interface{}) {
+ e.EarlyModuleContext.OtherModulePropertyErrorf(module, property, fmt, args)
+}
diff --git a/android/module.go b/android/module.go
index c0597fafb..9f1d5eff0 100644
--- a/android/module.go
+++ b/android/module.go
@@ -29,6 +29,7 @@ import (
"android/soong/bazel"
"github.com/google/blueprint"
+ "github.com/google/blueprint/parser"
"github.com/google/blueprint/proptools"
)
@@ -123,6 +124,8 @@ type Module interface {
// TransitivePackagingSpecs returns the PackagingSpecs for this module and any transitive
// dependencies with dependency tags for which IsInstallDepNeeded() returns true.
TransitivePackagingSpecs() []PackagingSpec
+
+ ConfigurableEvaluator(ctx ConfigAndErrorContext) proptools.ConfigurableEvaluator
}
// Qualified id for a module
@@ -1230,6 +1233,10 @@ func (m *ModuleBase) GenerateTaggedDistFiles(ctx BaseModuleContext) TaggedDistFi
return distFiles
}
+func (m *ModuleBase) ArchReady() bool {
+ return m.commonProperties.ArchReady
+}
+
func (m *ModuleBase) Target() Target {
return m.commonProperties.CompileTarget
}
@@ -2104,6 +2111,65 @@ func (m *ModuleBase) IsNativeBridgeSupported() bool {
return proptools.Bool(m.commonProperties.Native_bridge_supported)
}
+type ConfigAndErrorContext interface {
+ Config() Config
+ OtherModulePropertyErrorf(module Module, property string, fmt string, args ...interface{})
+}
+
+type configurationEvalutor struct {
+ ctx ConfigAndErrorContext
+ m Module
+}
+
+func (m *ModuleBase) ConfigurableEvaluator(ctx ConfigAndErrorContext) proptools.ConfigurableEvaluator {
+ return configurationEvalutor{
+ ctx: ctx,
+ m: m.module,
+ }
+}
+
+func (e configurationEvalutor) PropertyErrorf(property string, fmt string, args ...interface{}) {
+ e.ctx.OtherModulePropertyErrorf(e.m, property, fmt, args)
+}
+
+func (e configurationEvalutor) EvaluateConfiguration(ty parser.SelectType, property, condition string) (string, bool) {
+ ctx := e.ctx
+ m := e.m
+ switch ty {
+ case parser.SelectTypeReleaseVariable:
+ if v, ok := ctx.Config().productVariables.BuildFlags[condition]; ok {
+ return v, true
+ }
+ return "", false
+ case parser.SelectTypeProductVariable:
+ // TODO(b/323382414): Might add these on a case-by-case basis
+ ctx.OtherModulePropertyErrorf(m, property, "TODO(b/323382414): Product variables are not yet supported in selects")
+ return "", false
+ case parser.SelectTypeSoongConfigVariable:
+ parts := strings.Split(condition, ":")
+ namespace := parts[0]
+ variable := parts[1]
+ if n, ok := ctx.Config().productVariables.VendorVars[namespace]; ok {
+ if v, ok := n[variable]; ok {
+ return v, true
+ }
+ }
+ return "", false
+ case parser.SelectTypeVariant:
+ if condition == "arch" {
+ if !m.base().ArchReady() {
+ ctx.OtherModulePropertyErrorf(m, property, "A select on arch was attempted before the arch mutator ran")
+ return "", false
+ }
+ return m.base().Arch().ArchType.Name, true
+ }
+ ctx.OtherModulePropertyErrorf(m, property, "Unknown variant %s", condition)
+ return "", false
+ default:
+ panic("Should be unreachable")
+ }
+}
+
// ModuleNameWithPossibleOverride returns the name of the OverrideModule that overrides the current
// variant of this OverridableModule, or ctx.ModuleName() if this module is not an OverridableModule
// or if this variant is not overridden.
diff --git a/android/module_context.go b/android/module_context.go
index 1cab63022..d3e2770cb 100644
--- a/android/module_context.go
+++ b/android/module_context.go
@@ -234,6 +234,8 @@ type moduleContext struct {
variables map[string]string
}
+var _ ModuleContext = &moduleContext{}
+
func (m *moduleContext) ninjaError(params BuildParams, err error) (PackageContext, BuildParams) {
return pctx, BuildParams{
Rule: ErrorRule,
diff --git a/android/singleton.go b/android/singleton.go
index 5f939967c..76df1ebba 100644
--- a/android/singleton.go
+++ b/android/singleton.go
@@ -87,6 +87,9 @@ type SingletonContext interface {
// builder whenever a file matching the pattern as added or removed, without rerunning if a
// file that does not match the pattern is added to a searched directory.
GlobWithDeps(pattern string, excludes []string) ([]string, error)
+
+ // 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{})
}
type singletonAdaptor struct {
@@ -279,3 +282,7 @@ func (s *singletonContextAdaptor) ModuleVariantsFromName(referer Module, name st
func (s *singletonContextAdaptor) moduleProvider(module blueprint.Module, provider blueprint.AnyProviderKey) (any, bool) {
return s.SingletonContext.ModuleProvider(module, provider)
}
+
+func (s *singletonContextAdaptor) OtherModulePropertyErrorf(module Module, property string, format string, args ...interface{}) {
+ s.blueprintSingletonContext().OtherModulePropertyErrorf(module, property, format, args)
+}