Bp2build product variables on non-arch-variant module types

Mostly so that genrules can have their command qualified on a product
variable.

Bug: 295910468
Test: m nothing
Change-Id: I28cc18a1b3b00368f4768a1326259a656ce970ec
This commit is contained in:
Cole Faust
2023-08-15 11:59:24 -07:00
parent 9db358d43d
commit ed940008ac
2 changed files with 78 additions and 5 deletions

View File

@@ -138,6 +138,7 @@ type variableProperties struct {
Srcs []string
Exclude_srcs []string
Cmd *string
}
// eng is true for -eng builds, and can be used to turn on additional heavyweight debugging
@@ -677,11 +678,16 @@ func ProductVariableProperties(ctx ArchVariantContext, module Module) ProductCon
if moduleBase.variableProperties != nil {
productVariablesProperty := proptools.FieldNameForProperty("product_variables")
for /* axis */ _, configToProps := range moduleBase.GetArchVariantProperties(ctx, moduleBase.variableProperties) {
for config, props := range configToProps {
variableValues := reflect.ValueOf(props).Elem().FieldByName(productVariablesProperty)
productConfigProperties.AddProductConfigProperties(variableValues, config)
if moduleBase.ArchSpecific() {
for /* axis */ _, configToProps := range moduleBase.GetArchVariantProperties(ctx, moduleBase.variableProperties) {
for config, props := range configToProps {
variableValues := reflect.ValueOf(props).Elem().FieldByName(productVariablesProperty)
productConfigProperties.AddProductConfigProperties(variableValues, config)
}
}
} else {
variableValues := reflect.ValueOf(moduleBase.variableProperties).Elem().FieldByName(productVariablesProperty)
productConfigProperties.AddProductConfigProperties(variableValues, "")
}
}

View File

@@ -773,7 +773,7 @@ func TestGenruleWithExportIncludeDirs(t *testing.T) {
}
}
func TestGenruleWithConfiguredCmd(t *testing.T) {
func TestGenruleWithSoongConfigVariableConfiguredCmd(t *testing.T) {
testCases := []struct {
moduleType string
factory android.ModuleFactory
@@ -846,3 +846,70 @@ my_genrule {
})
}
}
func TestGenruleWithProductVariableConfiguredCmd(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 := `
%s {
name: "foo",
out: ["foo.txt"],
cmd: "echo 'no variable' > $(out)",
product_variables: {
debuggable: {
cmd: "echo 'with variable' > $(out)",
},
},
bazel_module: { bp2build_available: true },
}
`
for _, tc := range testCases {
moduleAttrs := AttrNameToString{
"cmd": `select({
"//build/bazel/product_config/config_settings:debuggable": "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,
})
})
}
}