Make MakeVarsContext a PathContext
Expose all of SingletonContext to makeVarsContext, and then export the subset of it that is used through MakeVarsContext.SingletonContext, plus what is necessary for PathContext, directly through MakeVarsContext. Test: m checkbuild Change-Id: Ie00f36e577fe110b6fa03b901da489d8547773c6
This commit is contained in:
parent
7cf14099b7
commit
65494b962b
|
@ -22,6 +22,8 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/google/blueprint"
|
||||||
|
"github.com/google/blueprint/pathtools"
|
||||||
"github.com/google/blueprint/proptools"
|
"github.com/google/blueprint/proptools"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -38,7 +40,21 @@ func androidMakeVarsProvider(ctx MakeVarsContext) {
|
||||||
type MakeVarsContext interface {
|
type MakeVarsContext interface {
|
||||||
Config() Config
|
Config() Config
|
||||||
DeviceConfig() DeviceConfig
|
DeviceConfig() DeviceConfig
|
||||||
SingletonContext() SingletonContext
|
AddNinjaFileDeps(deps ...string)
|
||||||
|
Fs() pathtools.FileSystem
|
||||||
|
|
||||||
|
ModuleName(module blueprint.Module) string
|
||||||
|
ModuleDir(module blueprint.Module) string
|
||||||
|
ModuleSubDir(module blueprint.Module) string
|
||||||
|
ModuleType(module blueprint.Module) string
|
||||||
|
BlueprintFile(module blueprint.Module) string
|
||||||
|
|
||||||
|
ModuleErrorf(module blueprint.Module, format string, args ...interface{})
|
||||||
|
Errorf(format string, args ...interface{})
|
||||||
|
Failed() bool
|
||||||
|
|
||||||
|
VisitAllModules(visit func(Module))
|
||||||
|
VisitAllModulesIf(pred func(Module) bool, visit func(Module))
|
||||||
|
|
||||||
// Verify the make variable matches the Soong version, fail the build
|
// Verify the make variable matches the Soong version, fail the build
|
||||||
// if it does not. If the make variable is empty, just set it.
|
// if it does not. If the make variable is empty, just set it.
|
||||||
|
@ -66,6 +82,8 @@ type MakeVarsContext interface {
|
||||||
CheckRaw(name, value string)
|
CheckRaw(name, value string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ PathContext = MakeVarsContext(nil)
|
||||||
|
|
||||||
type MakeVarsProvider func(ctx MakeVarsContext)
|
type MakeVarsProvider func(ctx MakeVarsContext)
|
||||||
|
|
||||||
func RegisterMakeVarsProvider(pctx PackageContext, provider MakeVarsProvider) {
|
func RegisterMakeVarsProvider(pctx PackageContext, provider MakeVarsProvider) {
|
||||||
|
@ -92,8 +110,8 @@ type makeVarsProvider struct {
|
||||||
var makeVarsProviders []makeVarsProvider
|
var makeVarsProviders []makeVarsProvider
|
||||||
|
|
||||||
type makeVarsContext struct {
|
type makeVarsContext struct {
|
||||||
|
SingletonContext
|
||||||
config Config
|
config Config
|
||||||
ctx SingletonContext
|
|
||||||
pctx PackageContext
|
pctx PackageContext
|
||||||
vars []makeVarsVariable
|
vars []makeVarsVariable
|
||||||
}
|
}
|
||||||
|
@ -121,9 +139,8 @@ func (s *makeVarsSingleton) GenerateBuildActions(ctx SingletonContext) {
|
||||||
vars := []makeVarsVariable{}
|
vars := []makeVarsVariable{}
|
||||||
for _, provider := range makeVarsProviders {
|
for _, provider := range makeVarsProviders {
|
||||||
mctx := &makeVarsContext{
|
mctx := &makeVarsContext{
|
||||||
config: ctx.Config(),
|
SingletonContext: ctx,
|
||||||
ctx: ctx,
|
pctx: provider.pctx,
|
||||||
pctx: provider.pctx,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
provider.call(mctx)
|
provider.call(mctx)
|
||||||
|
@ -229,22 +246,14 @@ my_check_failed :=
|
||||||
return buf.Bytes()
|
return buf.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *makeVarsContext) Config() Config {
|
|
||||||
return c.config
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *makeVarsContext) DeviceConfig() DeviceConfig {
|
func (c *makeVarsContext) DeviceConfig() DeviceConfig {
|
||||||
return DeviceConfig{c.config.deviceConfig}
|
return DeviceConfig{c.Config().deviceConfig}
|
||||||
}
|
|
||||||
|
|
||||||
func (c *makeVarsContext) SingletonContext() SingletonContext {
|
|
||||||
return c.ctx
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var ninjaDescaper = strings.NewReplacer("$$", "$")
|
var ninjaDescaper = strings.NewReplacer("$$", "$")
|
||||||
|
|
||||||
func (c *makeVarsContext) Eval(ninjaStr string) (string, error) {
|
func (c *makeVarsContext) Eval(ninjaStr string) (string, error) {
|
||||||
s, err := c.ctx.Eval(c.pctx, ninjaStr)
|
s, err := c.SingletonContext.Eval(c.pctx, ninjaStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -265,7 +274,7 @@ func (c *makeVarsContext) addVariableRaw(name, value string, strict, sort bool)
|
||||||
func (c *makeVarsContext) addVariable(name, ninjaStr string, strict, sort bool) {
|
func (c *makeVarsContext) addVariable(name, ninjaStr string, strict, sort bool) {
|
||||||
value, err := c.Eval(ninjaStr)
|
value, err := c.Eval(ninjaStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ctx.Errorf(err.Error())
|
c.SingletonContext.Errorf(err.Error())
|
||||||
}
|
}
|
||||||
c.addVariableRaw(name, value, strict, sort)
|
c.addVariableRaw(name, value, strict, sort)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import (
|
||||||
// SingletonContext
|
// SingletonContext
|
||||||
type SingletonContext interface {
|
type SingletonContext interface {
|
||||||
Config() Config
|
Config() Config
|
||||||
|
DeviceConfig() DeviceConfig
|
||||||
|
|
||||||
ModuleName(module blueprint.Module) string
|
ModuleName(module blueprint.Module) string
|
||||||
ModuleDir(module blueprint.Module) string
|
ModuleDir(module blueprint.Module) string
|
||||||
|
@ -93,6 +94,10 @@ func (s singletonContextAdaptor) Config() Config {
|
||||||
return s.SingletonContext.Config().(Config)
|
return s.SingletonContext.Config().(Config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s singletonContextAdaptor) DeviceConfig() DeviceConfig {
|
||||||
|
return DeviceConfig{s.Config().deviceConfig}
|
||||||
|
}
|
||||||
|
|
||||||
func (s singletonContextAdaptor) Variable(pctx PackageContext, name, value string) {
|
func (s singletonContextAdaptor) Variable(pctx PackageContext, name, value string) {
|
||||||
s.SingletonContext.Variable(pctx.PackageContext, name, value)
|
s.SingletonContext.Variable(pctx.PackageContext, name, value)
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ func makeVarsProvider(ctx android.MakeVarsContext) {
|
||||||
|
|
||||||
// Filter vendor_public_library that are exported to make
|
// Filter vendor_public_library that are exported to make
|
||||||
exportedVendorPublicLibraries := []string{}
|
exportedVendorPublicLibraries := []string{}
|
||||||
ctx.SingletonContext().VisitAllModules(func(module android.Module) {
|
ctx.VisitAllModules(func(module android.Module) {
|
||||||
if ccModule, ok := module.(*Module); ok {
|
if ccModule, ok := module.(*Module); ok {
|
||||||
baseName := ccModule.BaseModuleName()
|
baseName := ccModule.BaseModuleName()
|
||||||
if inList(baseName, vendorPublicLibraries) && module.ExportedToMake() {
|
if inList(baseName, vendorPublicLibraries) && module.ExportedToMake() {
|
||||||
|
|
|
@ -28,9 +28,8 @@ func init() {
|
||||||
func supportLibrariesMakeVarsProvider(ctx android.MakeVarsContext) {
|
func supportLibrariesMakeVarsProvider(ctx android.MakeVarsContext) {
|
||||||
var supportAars, supportJars []string
|
var supportAars, supportJars []string
|
||||||
|
|
||||||
sctx := ctx.SingletonContext()
|
ctx.VisitAllModules(func(module android.Module) {
|
||||||
sctx.VisitAllModules(func(module android.Module) {
|
dir := ctx.ModuleDir(module)
|
||||||
dir := sctx.ModuleDir(module)
|
|
||||||
switch {
|
switch {
|
||||||
case strings.HasPrefix(dir, "prebuilts/sdk/current/extras"),
|
case strings.HasPrefix(dir, "prebuilts/sdk/current/extras"),
|
||||||
dir == "prebuilts/sdk/current/androidx",
|
dir == "prebuilts/sdk/current/androidx",
|
||||||
|
@ -43,7 +42,7 @@ func supportLibrariesMakeVarsProvider(ctx android.MakeVarsContext) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
name := sctx.ModuleName(module)
|
name := ctx.ModuleName(module)
|
||||||
if strings.HasSuffix(name, "-nodeps") {
|
if strings.HasSuffix(name, "-nodeps") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -54,7 +53,7 @@ func supportLibrariesMakeVarsProvider(ctx android.MakeVarsContext) {
|
||||||
case *Library, *Import:
|
case *Library, *Import:
|
||||||
supportJars = append(supportJars, name)
|
supportJars = append(supportJars, name)
|
||||||
default:
|
default:
|
||||||
sctx.ModuleErrorf(module, "unknown module type %t", module)
|
ctx.ModuleErrorf(module, "unknown module type %t", module)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue