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:
@@ -18,21 +18,6 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// This variable uses ExistentPathForSource on a PackageVarContext, which is a PathContext
|
||||
// that is not a PathGlobContext. That requires the deps to be stored in the Config.
|
||||
pctx.VariableFunc("test_ninja_deps_variable", func(ctx PackageVarContext) string {
|
||||
// Using ExistentPathForSource to look for a file that does not exist in a directory that
|
||||
// does exist (test_ninja_deps) from a PackageVarContext adds a dependency from build.ninja
|
||||
// to the directory.
|
||||
if ExistentPathForSource(ctx, "test_ninja_deps/does_not_exist").Valid() {
|
||||
return "true"
|
||||
} else {
|
||||
return "false"
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func testNinjaDepsSingletonFactory() Singleton {
|
||||
return testNinjaDepsSingleton{}
|
||||
}
|
||||
@@ -40,33 +25,19 @@ func testNinjaDepsSingletonFactory() Singleton {
|
||||
type testNinjaDepsSingleton struct{}
|
||||
|
||||
func (testNinjaDepsSingleton) GenerateBuildActions(ctx SingletonContext) {
|
||||
// Reference the test_ninja_deps_variable in a build statement so Blueprint is forced to
|
||||
// evaluate it.
|
||||
ctx.Build(pctx, BuildParams{
|
||||
Rule: Cp,
|
||||
Input: PathForTesting("foo"),
|
||||
Output: PathForOutput(ctx, "test_ninja_deps_out"),
|
||||
Args: map[string]string{
|
||||
"cpFlags": "${test_ninja_deps_variable}",
|
||||
},
|
||||
})
|
||||
ctx.Config().addNinjaFileDeps("foo")
|
||||
}
|
||||
|
||||
func TestNinjaDeps(t *testing.T) {
|
||||
fs := MockFS{
|
||||
"test_ninja_deps/exists": nil,
|
||||
}
|
||||
|
||||
result := GroupFixturePreparers(
|
||||
FixtureRegisterWithContext(func(ctx RegistrationContext) {
|
||||
ctx.RegisterSingletonType("test_ninja_deps_singleton", testNinjaDepsSingletonFactory)
|
||||
ctx.RegisterSingletonType("ninja_deps_singleton", ninjaDepsSingletonFactory)
|
||||
}),
|
||||
fs.AddToFixture(),
|
||||
).RunTest(t)
|
||||
|
||||
// Verify that the ninja file has a dependency on the test_ninja_deps directory.
|
||||
if g, w := result.NinjaDeps, "test_ninja_deps"; !InList(w, g) {
|
||||
if g, w := result.NinjaDeps, "foo"; !InList(w, g) {
|
||||
t.Errorf("expected %q in %q", w, g)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user