Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f768e6e2 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

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

parents f5ee8e3f ed940008
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -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,12 +678,17 @@ func ProductVariableProperties(ctx ArchVariantContext, module Module) ProductCon

	if moduleBase.variableProperties != nil {
		productVariablesProperty := proptools.FieldNameForProperty("product_variables")
		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, "")
		}
	}

	if m, ok := module.(Bazelable); ok && m.namespacedVariableProps() != nil {
+68 −1
Original line number Diff line number Diff line
@@ -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,
				})
		})
	}
}