Merge "Implement OtherModulePropertyErrorf proxies" into main am: 3e39bb6025
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/3010317 Change-Id: I9da28213d80659ec1e78725bd56cd114ae7f92fc Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -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.
|
||||
|
@@ -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,
|
||||
|
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user