From 69a680feec6aa2977afd988aca74bddd9dce3d8d Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 29 Jan 2024 13:18:43 -0800 Subject: [PATCH] Prevent defaults modules from expanding path property dependencies Defaults modules should not have dependencies added to them for path properties, the properties will already have been squashed into other modules that depend on the defaults modules, and the path dependencies will be added to those modules. Fixes: 321056451 Test: TestDefaultsPathProperties Change-Id: I59049f94b7a0924a7b1d997d15723901b0d522ee --- android/defaults_test.go | 42 +++++++++++++++++++++++++++++++++++++- android/path_properties.go | 5 +++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/android/defaults_test.go b/android/defaults_test.go index a7542abb3..0ad0fb859 100644 --- a/android/defaults_test.go +++ b/android/defaults_test.go @@ -16,10 +16,13 @@ package android import ( "testing" + + "github.com/google/blueprint" ) type defaultsTestProperties struct { - Foo []string + Foo []string + Path_prop []string `android:"path"` } type defaultsTestModule struct { @@ -130,3 +133,40 @@ func TestDefaultsAllowMissingDependencies(t *testing.T) { // TODO: missing transitive defaults is currently not handled _ = missingTransitiveDefaults } + +func TestDefaultsPathProperties(t *testing.T) { + bp := ` + defaults { + name: "defaults", + path_prop: [":gen"], + } + + test { + name: "foo", + defaults: ["defaults"], + } + + test { + name: "gen", + } + ` + + result := GroupFixturePreparers( + prepareForDefaultsTest, + FixtureWithRootAndroidBp(bp), + ).RunTest(t) + + collectDeps := func(m Module) []string { + var deps []string + result.VisitDirectDeps(m, func(dep blueprint.Module) { + deps = append(deps, result.ModuleName(dep)) + }) + return deps + } + + foo := result.Module("foo", "") + defaults := result.Module("defaults", "") + + AssertStringListContains(t, "foo should depend on gen", collectDeps(foo), "gen") + AssertStringListDoesNotContain(t, "defaults should not depend on gen", collectDeps(defaults), "gen") +} diff --git a/android/path_properties.go b/android/path_properties.go index fdc4d918f..bbfaa8c46 100644 --- a/android/path_properties.go +++ b/android/path_properties.go @@ -33,6 +33,11 @@ func registerPathDepsMutator(ctx RegisterMutatorsContext) { // The pathDepsMutator automatically adds dependencies on any module that is listed with the // ":module" module reference syntax in a property that is tagged with `android:"path"`. func pathDepsMutator(ctx BottomUpMutatorContext) { + if _, ok := ctx.Module().(DefaultsModule); ok { + // Defaults modules shouldn't have dependencies added for path properties, they have already been + // squashed into the real modules. + return + } props := ctx.Module().base().GetProperties() addPathDepsForProps(ctx, props) }