Merge "Bp2build product variables on non-arch-variant module types" into main

This commit is contained in:
Treehugger Robot
2023-08-15 21:51:31 +00:00
committed by Gerrit Code Review
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,
})
})
}
}