Allow RuleBuilder to be used with SingletonContext

Make RuleBuilder.Build take a subset of ModuleContext and
SingletonContext, and dynamically call PathForModuleOut only
if it is available.

Test: rule_builder_test.go
Change-Id: Id825cb75236acf187e9d4a36353a47abcac71927
This commit is contained in:
Colin Cross
2019-02-01 16:41:11 -08:00
parent feec25b084
commit 786cd6dc13
2 changed files with 52 additions and 11 deletions

View File

@@ -93,11 +93,27 @@ type testRuleBuilderModule struct {
}
func (t *testRuleBuilderModule) GenerateAndroidBuildActions(ctx ModuleContext) {
rule := RuleBuilder{}
in := PathForSource(ctx, t.properties.Src)
out := PathForModuleOut(ctx, ctx.ModuleName())
testRuleBuilder_Build(ctx, in, out)
}
type testRuleBuilderSingleton struct{}
func testRuleBuilderSingletonFactory() Singleton {
return &testRuleBuilderSingleton{}
}
func (t *testRuleBuilderSingleton) GenerateBuildActions(ctx SingletonContext) {
in := PathForSource(ctx, "bar")
out := PathForOutput(ctx, "baz")
testRuleBuilder_Build(ctx, in, out)
}
func testRuleBuilder_Build(ctx BuilderContext, in Path, out WritablePath) {
rule := RuleBuilder{}
rule.Command().Tool("cp").Input(in.String()).Output(out.String())
rule.Build(pctx, ctx, "rule", "desc")
@@ -125,6 +141,7 @@ func TestRuleBuilder_Build(t *testing.T) {
"cp": nil,
})
ctx.RegisterModuleType("rule_builder_test", ModuleFactoryAdaptor(testRuleBuilderFactory))
ctx.RegisterSingletonType("rule_builder_test", SingletonFactoryAdaptor(testRuleBuilderSingletonFactory))
ctx.Register()
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})