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
diff --git a/android/rule_builder_test.go b/android/rule_builder_test.go
index b4c9e0e..533b090 100644
--- a/android/rule_builder_test.go
+++ b/android/rule_builder_test.go
@@ -93,11 +93,27 @@
 }
 
 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 @@
 		"cp":         nil,
 	})
 	ctx.RegisterModuleType("rule_builder_test", ModuleFactoryAdaptor(testRuleBuilderFactory))
+	ctx.RegisterSingletonType("rule_builder_test", SingletonFactoryAdaptor(testRuleBuilderSingletonFactory))
 	ctx.Register()
 
 	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})