Bp2build genrule commands as configurable properties
So that users can use soong config variables / product variables
to adjust a genrule's command.
Bug: 295910468
Test: m nothing
Change-Id: I9fedf8d5d52e515c3fdb913411ce1b3fecb7ba81
diff --git a/bp2build/genrule_conversion_test.go b/bp2build/genrule_conversion_test.go
index 5a73969..2dcc5e4 100644
--- a/bp2build/genrule_conversion_test.go
+++ b/bp2build/genrule_conversion_test.go
@@ -772,3 +772,77 @@
})
}
}
+
+func TestGenruleWithConfiguredCmd(t *testing.T) {
+ testCases := []struct {
+ moduleType string
+ factory android.ModuleFactory
+ hod android.HostOrDeviceSupported
+ }{
+ {
+ moduleType: "genrule",
+ factory: genrule.GenRuleFactory,
+ },
+ {
+ moduleType: "cc_genrule",
+ factory: cc.GenRuleFactory,
+ hod: android.DeviceSupported,
+ },
+ {
+ moduleType: "java_genrule",
+ factory: java.GenRuleFactory,
+ hod: android.DeviceSupported,
+ },
+ {
+ moduleType: "java_genrule_host",
+ factory: java.GenRuleFactoryHost,
+ hod: android.HostSupported,
+ },
+ }
+
+ bp := `
+soong_config_module_type {
+ name: "my_genrule",
+ module_type: "%s",
+ config_namespace: "my_namespace",
+ bool_variables: ["my_variable"],
+ properties: ["cmd"],
+}
+
+my_genrule {
+ name: "foo",
+ out: ["foo.txt"],
+ cmd: "echo 'no variable' > $(out)",
+ soong_config_variables: {
+ my_variable: {
+ cmd: "echo 'with variable' > $(out)",
+ },
+ },
+ bazel_module: { bp2build_available: true },
+}
+`
+
+ for _, tc := range testCases {
+ moduleAttrs := AttrNameToString{
+ "cmd": `select({
+ "//build/bazel/product_config/config_settings:my_namespace__my_variable": "echo 'with variable' > $(OUTS)",
+ "//conditions:default": "echo 'no variable' > $(OUTS)",
+ })`,
+ "outs": `["foo.txt"]`,
+ }
+
+ expectedBazelTargets := []string{
+ makeBazelTargetHostOrDevice("genrule", "foo", moduleAttrs, tc.hod),
+ }
+
+ t.Run(tc.moduleType, func(t *testing.T) {
+ RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) { android.RegisterSoongConfigModuleBuildComponents(ctx) },
+ Bp2buildTestCase{
+ Blueprint: fmt.Sprintf(bp, tc.moduleType),
+ ModuleTypeUnderTest: tc.moduleType,
+ ModuleTypeUnderTestFactory: tc.factory,
+ ExpectedBazelTargets: expectedBazelTargets,
+ })
+ })
+ }
+}