Make PackageVarContext implement PathGlobContext

Make PackageVarContext implement PathGlobContext by implementing
GlobWithDeps.  This will allow calls to ExistentPathForSource
inside a VariableFunc to use optimized glob dependencies instead of
falling back to AddNinjaFileDeps, which is resulting in extra
dependencies from soong_build on top level directories, triggering
extra Soong regenerations.

Remove the fallback path in ExistentPathForSource by making it take
a PathGlobContext, which is now a superset of PathContext.

Rewrite TestNinjaDeps to not rely on the unoptimized glob dependencies
in VariableFuncs and instead call ctx.Config().AddNinjaFileDeps
directly.

Bug: 257079828
Test: test_create_global_include_directory
Change-Id: I48cf189157d78b9252d339dbc9baeb27e4694807
This commit is contained in:
Colin Cross
2022-11-03 20:38:01 -07:00
parent 1265bfdfbd
commit 662d61430f
5 changed files with 59 additions and 55 deletions

View File

@@ -48,7 +48,7 @@ type configErrorWrapper struct {
var _ PathContext = &configErrorWrapper{}
var _ errorfContext = &configErrorWrapper{}
var _ PackageVarContext = &configErrorWrapper{}
var _ PackageVarContext = &variableFuncContextWrapper{}
var _ PackagePoolContext = &configErrorWrapper{}
var _ PackageRuleContext = &configErrorWrapper{}
@@ -62,21 +62,33 @@ func (e *configErrorWrapper) AddNinjaFileDeps(deps ...string) {
e.config.addNinjaFileDeps(deps...)
}
type PackageVarContext interface {
type variableFuncContextWrapper struct {
configErrorWrapper
blueprint.VariableFuncContext
}
type PackagePoolContext interface {
PathContext
errorfContext
}
type PackagePoolContext PackageVarContext
type PackageRuleContext PackageVarContext
type PackageRuleContext PackagePoolContext
type PackageVarContext interface {
PackagePoolContext
PathGlobContext
}
// VariableFunc wraps blueprint.PackageContext.VariableFunc, converting the interface{} config
// argument to a PackageVarContext.
func (p PackageContext) VariableFunc(name string,
f func(PackageVarContext) string) blueprint.Variable {
return p.PackageContext.VariableFunc(name, func(config interface{}) (string, error) {
ctx := &configErrorWrapper{p, config.(Config), nil}
return p.PackageContext.VariableFunc(name, func(bpctx blueprint.VariableFuncContext, config interface{}) (string, error) {
ctx := &variableFuncContextWrapper{
configErrorWrapper: configErrorWrapper{p, config.(Config), nil},
VariableFuncContext: bpctx,
}
ret := f(ctx)
if len(ctx.errors) > 0 {
return "", ctx.errors[0]