Loading genrule/genrule.go +36 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,8 @@ import ( ) func init() { android.RegisterModuleType("genrule_defaults", defaultsFactory) android.RegisterModuleType("gensrcs", GenSrcsFactory) android.RegisterModuleType("genrule", GenRuleFactory) } Loading Loading @@ -95,6 +97,7 @@ type generatorProperties struct { type Module struct { android.ModuleBase android.DefaultableModuleBase // For other packages to make their own genrules with extra // properties Loading Loading @@ -502,6 +505,7 @@ func NewGenRule() *Module { func GenRuleFactory() android.Module { m := NewGenRule() android.InitAndroidModule(m) android.InitDefaultableModule(m) return m } Loading @@ -512,3 +516,35 @@ type genRuleProperties struct { var Bool = proptools.Bool var String = proptools.String // // Defaults // type Defaults struct { android.ModuleBase android.DefaultsModuleBase } func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { } func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) { } func defaultsFactory() android.Module { return DefaultsFactory() } func DefaultsFactory(props ...interface{}) android.Module { module := &Defaults{} module.AddProperties(props...) module.AddProperties( &generatorProperties{}, &genRuleProperties{}, ) android.InitDefaultsModule(module) return module } genrule/genrule_test.go +43 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import ( "testing" "android/soong/android" "reflect" ) var buildDir string Loading Loading @@ -54,7 +55,9 @@ func testContext(config android.Config, bp string, ctx := android.NewTestArchContext() ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory)) ctx.RegisterModuleType("genrule", android.ModuleFactoryAdaptor(GenRuleFactory)) ctx.RegisterModuleType("genrule_defaults", android.ModuleFactoryAdaptor(defaultsFactory)) ctx.RegisterModuleType("tool", android.ModuleFactoryAdaptor(toolFactory)) ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) ctx.Register() bp += ` Loading Loading @@ -465,6 +468,46 @@ func TestGenruleCmd(t *testing.T) { } func TestGenruleDefaults(t *testing.T) { config := android.TestArchConfig(buildDir, nil) bp := ` genrule_defaults { name: "gen_defaults1", cmd: "cp $(in) $(out)", } genrule_defaults { name: "gen_defaults2", srcs: ["in1"], } genrule { name: "gen", out: ["out"], defaults: ["gen_defaults1", "gen_defaults2"], } ` ctx := testContext(config, bp, nil) _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) if errs == nil { _, errs = ctx.PrepareBuildActions(config) } if errs != nil { t.Fatal(errs) } gen := ctx.ModuleForTests("gen", "").Module().(*Module) expectedCmd := "'cp ${in} __SBOX_OUT_FILES__'" if gen.rawCommand != expectedCmd { t.Errorf("Expected cmd: %q, actual: %q", expectedCmd, gen.rawCommand) } expectedSrcs := []string{"in1"} if !reflect.DeepEqual(expectedSrcs, gen.properties.Srcs) { t.Errorf("Expected srcs: %q, actual: %q", expectedSrcs, gen.properties.Srcs) } } type testTool struct { android.ModuleBase outputFile android.Path Loading Loading
genrule/genrule.go +36 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,8 @@ import ( ) func init() { android.RegisterModuleType("genrule_defaults", defaultsFactory) android.RegisterModuleType("gensrcs", GenSrcsFactory) android.RegisterModuleType("genrule", GenRuleFactory) } Loading Loading @@ -95,6 +97,7 @@ type generatorProperties struct { type Module struct { android.ModuleBase android.DefaultableModuleBase // For other packages to make their own genrules with extra // properties Loading Loading @@ -502,6 +505,7 @@ func NewGenRule() *Module { func GenRuleFactory() android.Module { m := NewGenRule() android.InitAndroidModule(m) android.InitDefaultableModule(m) return m } Loading @@ -512,3 +516,35 @@ type genRuleProperties struct { var Bool = proptools.Bool var String = proptools.String // // Defaults // type Defaults struct { android.ModuleBase android.DefaultsModuleBase } func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { } func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) { } func defaultsFactory() android.Module { return DefaultsFactory() } func DefaultsFactory(props ...interface{}) android.Module { module := &Defaults{} module.AddProperties(props...) module.AddProperties( &generatorProperties{}, &genRuleProperties{}, ) android.InitDefaultsModule(module) return module }
genrule/genrule_test.go +43 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import ( "testing" "android/soong/android" "reflect" ) var buildDir string Loading Loading @@ -54,7 +55,9 @@ func testContext(config android.Config, bp string, ctx := android.NewTestArchContext() ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory)) ctx.RegisterModuleType("genrule", android.ModuleFactoryAdaptor(GenRuleFactory)) ctx.RegisterModuleType("genrule_defaults", android.ModuleFactoryAdaptor(defaultsFactory)) ctx.RegisterModuleType("tool", android.ModuleFactoryAdaptor(toolFactory)) ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) ctx.Register() bp += ` Loading Loading @@ -465,6 +468,46 @@ func TestGenruleCmd(t *testing.T) { } func TestGenruleDefaults(t *testing.T) { config := android.TestArchConfig(buildDir, nil) bp := ` genrule_defaults { name: "gen_defaults1", cmd: "cp $(in) $(out)", } genrule_defaults { name: "gen_defaults2", srcs: ["in1"], } genrule { name: "gen", out: ["out"], defaults: ["gen_defaults1", "gen_defaults2"], } ` ctx := testContext(config, bp, nil) _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) if errs == nil { _, errs = ctx.PrepareBuildActions(config) } if errs != nil { t.Fatal(errs) } gen := ctx.ModuleForTests("gen", "").Module().(*Module) expectedCmd := "'cp ${in} __SBOX_OUT_FILES__'" if gen.rawCommand != expectedCmd { t.Errorf("Expected cmd: %q, actual: %q", expectedCmd, gen.rawCommand) } expectedSrcs := []string{"in1"} if !reflect.DeepEqual(expectedSrcs, gen.properties.Srcs) { t.Errorf("Expected srcs: %q, actual: %q", expectedSrcs, gen.properties.Srcs) } } type testTool struct { android.ModuleBase outputFile android.Path Loading