Add filegroup_defaults module

Allows specifying shared filegroup attributes in a central place.

Test: filegroup_test.go
Change-Id: I82feac37ae6998313a0004f8af58f3decf7a514e
This commit is contained in:
Anton Hansson 2023-03-06 11:26:17 +00:00
parent 7a444cec60
commit 7d6dd8bb33
2 changed files with 44 additions and 2 deletions

View file

@ -26,13 +26,18 @@ import (
)
func init() {
RegisterModuleType("filegroup", FileGroupFactory)
RegisterFilegroupBuildComponents(InitRegistrationContext)
}
var PrepareForTestWithFilegroup = FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.RegisterModuleType("filegroup", FileGroupFactory)
RegisterFilegroupBuildComponents(ctx)
})
func RegisterFilegroupBuildComponents(ctx RegistrationContext) {
ctx.RegisterModuleType("filegroup", FileGroupFactory)
ctx.RegisterModuleType("filegroup_defaults", FileGroupDefaultsFactory)
}
var convertedProtoLibrarySuffix = "_bp2build_converted"
// IsFilegroup checks that a module is a filegroup type
@ -178,6 +183,7 @@ type fileGroupProperties struct {
type fileGroup struct {
ModuleBase
BazelModuleBase
DefaultableModuleBase
FileGroupAsLibrary
properties fileGroupProperties
srcs Paths
@ -195,6 +201,7 @@ func FileGroupFactory() Module {
module.AddProperties(&module.properties)
InitAndroidModule(module)
InitBazelModule(module)
InitDefaultableModule(module)
return module
}
@ -326,3 +333,17 @@ func ToFileGroupAsLibrary(ctx BazelConversionPathContext, name string) (FileGrou
}
return nil, false
}
// Defaults
type FileGroupDefaults struct {
ModuleBase
DefaultsModuleBase
}
func FileGroupDefaultsFactory() Module {
module := &FileGroupDefaults{}
module.AddProperties(&fileGroupProperties{})
InitDefaultsModule(module)
return module
}

View file

@ -58,3 +58,24 @@ func TestFileGroupWithPathProp(t *testing.T) {
AssertStringEquals(t, "src full path", expectedOutputfile, fg.srcs[0].String())
}
}
func TestFilegroupDefaults(t *testing.T) {
bp := FixtureAddTextFile("p/Android.bp", `
filegroup_defaults {
name: "defaults",
visibility: ["//x"],
}
filegroup {
name: "foo",
defaults: ["defaults"],
visibility: ["//y"],
}
`)
result := GroupFixturePreparers(
PrepareForTestWithFilegroup,
PrepareForTestWithDefaults,
PrepareForTestWithVisibility,
bp).RunTest(t)
rules := effectiveVisibilityRules(result.Config, qualifiedModuleName{pkg: "p", name: "foo"})
AssertDeepEquals(t, "visibility", []string{"//x", "//y"}, rules.Strings())
}