Add filegroup_defaults module
Allows specifying shared filegroup attributes in a central place. Test: filegroup_test.go Change-Id: I82feac37ae6998313a0004f8af58f3decf7a514e (cherry picked from https://android-review.googlesource.com/q/commit:7d6dd8bb3324e81b5c4afc80b062baad2fed1770) Merged-In: I82feac37ae6998313a0004f8af58f3decf7a514e
This commit is contained in:
@@ -23,13 +23,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)
|
||||
}
|
||||
|
||||
// IsFilegroup checks that a module is a filegroup type
|
||||
func IsFilegroup(ctx bazel.OtherModuleContext, m blueprint.Module) bool {
|
||||
return ctx.OtherModuleType(m) == "filegroup"
|
||||
@@ -97,6 +102,7 @@ type fileGroupProperties struct {
|
||||
type fileGroup struct {
|
||||
ModuleBase
|
||||
BazelModuleBase
|
||||
DefaultableModuleBase
|
||||
properties fileGroupProperties
|
||||
srcs Paths
|
||||
}
|
||||
@@ -111,6 +117,7 @@ func FileGroupFactory() Module {
|
||||
module.AddProperties(&module.properties)
|
||||
InitAndroidModule(module)
|
||||
InitBazelModule(module)
|
||||
InitDefaultableModule(module)
|
||||
return module
|
||||
}
|
||||
|
||||
@@ -161,3 +168,17 @@ func (fg *fileGroup) MakeVars(ctx MakeVarsModuleContext) {
|
||||
ctx.StrictRaw(makeVar, strings.Join(fg.srcs.Strings(), " "))
|
||||
}
|
||||
}
|
||||
|
||||
// Defaults
|
||||
type FileGroupDefaults struct {
|
||||
ModuleBase
|
||||
DefaultsModuleBase
|
||||
}
|
||||
|
||||
func FileGroupDefaultsFactory() Module {
|
||||
module := &FileGroupDefaults{}
|
||||
module.AddProperties(&fileGroupProperties{})
|
||||
InitDefaultsModule(module)
|
||||
|
||||
return module
|
||||
}
|
||||
|
26
android/filegroup_test.go
Normal file
26
android/filegroup_test.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package android
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
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())
|
||||
}
|
Reference in New Issue
Block a user