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

Commit 230c57af authored by Jingwen Chen's avatar Jingwen Chen Committed by Gerrit Code Review
Browse files

Merge "Make cc_genrule.srcs configurable."

parents 85c0ef15 d6201013
Loading
Loading
Loading
Loading
+50 −2
Original line number Original line Diff line number Diff line
@@ -15,12 +15,13 @@
package bp2build
package bp2build


import (
import (
	"fmt"
	"testing"

	"android/soong/android"
	"android/soong/android"
	"android/soong/cc"
	"android/soong/cc"
	"android/soong/genrule"
	"android/soong/genrule"
	"android/soong/java"
	"android/soong/java"
	"fmt"
	"testing"
)
)


func registerGenruleModuleTypes(ctx android.RegistrationContext) {
func registerGenruleModuleTypes(ctx android.RegistrationContext) {
@@ -643,3 +644,50 @@ genrule {
		})
		})
	}
	}
}
}

func TestCcGenruleArchAndExcludeSrcs(t *testing.T) {
	name := "cc_genrule with arch"
	bp := `
	cc_genrule {
		name: "foo",
		srcs: [
			"foo1.in",
			"foo2.in",
		],
		exclude_srcs: ["foo2.in"],
		arch: {
			arm: {
				srcs: [
					"foo1_arch.in",
					"foo2_arch.in",
				],
				exclude_srcs: ["foo2_arch.in"],
			},
		},
		cmd: "cat $(in) > $(out)",
		bazel_module: { bp2build_available: true },
	}`

	expectedBazelAttrs := AttrNameToString{
		"srcs": `["foo1.in"] + select({
        "//build/bazel/platforms/arch:arm": ["foo1_arch.in"],
        "//conditions:default": [],
    })`,
		"cmd":                    `"cat $(SRCS) > $(OUTS)"`,
		"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
	}

	expectedBazelTargets := []string{
		MakeBazelTargetNoRestrictions("genrule", "foo", expectedBazelAttrs),
	}

	t.Run(name, func(t *testing.T) {
		RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
			Bp2buildTestCase{
				ModuleTypeUnderTest:        "cc_genrule",
				ModuleTypeUnderTestFactory: cc.GenRuleFactory,
				Blueprint:                  bp,
				ExpectedBazelTargets:       expectedBazelTargets,
			})
	})
}
+2 −3
Original line number Original line Diff line number Diff line
@@ -40,14 +40,13 @@ func TestArchGenruleCmd(t *testing.T) {
					name: "gen",
					name: "gen",
					tool_files: ["tool"],
					tool_files: ["tool"],
					cmd: "$(location tool) $(in) $(out)",
					cmd: "$(location tool) $(in) $(out)",
					out: ["out_arm"],
					arch: {
					arch: {
						arm: {
						arm: {
							srcs: ["foo"],
							srcs: ["foo"],
							out: ["out_arm"],
						},
						},
						arm64: {
						arm64: {
							srcs: ["bar"],
							srcs: ["bar"],
							out: ["out_arm64"],
						},
						},
					},
					},
				}
				}
@@ -70,7 +69,7 @@ func TestArchGenruleCmd(t *testing.T) {
		t.Errorf(`want arm inputs %v, got %v`, expected, gen.Implicits.Strings())
		t.Errorf(`want arm inputs %v, got %v`, expected, gen.Implicits.Strings())
	}
	}


	gen = ctx.ModuleForTests("gen", "android_arm64_armv8-a").Output("out_arm64")
	gen = ctx.ModuleForTests("gen", "android_arm64_armv8-a").Output("out_arm")
	expected = []string{"bar"}
	expected = []string{"bar"}
	if !reflect.DeepEqual(expected, gen.Implicits.Strings()[:len(expected)]) {
	if !reflect.DeepEqual(expected, gen.Implicits.Strings()[:len(expected)]) {
		t.Errorf(`want arm64 inputs %v, got %v`, expected, gen.Implicits.Strings())
		t.Errorf(`want arm64 inputs %v, got %v`, expected, gen.Implicits.Strings())
+19 −3
Original line number Original line Diff line number Diff line
@@ -875,7 +875,7 @@ func GenRuleFactory() android.Module {


type genRuleProperties struct {
type genRuleProperties struct {
	// names of the output files that will be generated
	// names of the output files that will be generated
	Out []string `android:"arch_variant"`
	Out []string
}
}


type bazelGenruleAttributes struct {
type bazelGenruleAttributes struct {
@@ -893,11 +893,27 @@ func (m *Module) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
	tools_prop.Append(tool_files_prop)
	tools_prop.Append(tool_files_prop)


	tools := bazel.MakeLabelListAttribute(tools_prop)
	tools := bazel.MakeLabelListAttribute(tools_prop)
	srcs := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.properties.Srcs))
	srcs := bazel.LabelListAttribute{}
	srcs_labels := bazel.LabelList{}
	// Only cc_genrule is arch specific
	if ctx.ModuleType() == "cc_genrule" {
		for axis, configToProps := range m.GetArchVariantProperties(ctx, &generatorProperties{}) {
			for config, props := range configToProps {
				if props, ok := props.(*generatorProperties); ok {
					labels := android.BazelLabelForModuleSrcExcludes(ctx, props.Srcs, props.Exclude_srcs)
					srcs_labels.Append(labels)
					srcs.SetSelectValue(axis, config, labels)
				}
			}
		}
	} else {
		srcs_labels = android.BazelLabelForModuleSrcExcludes(ctx, m.properties.Srcs, m.properties.Exclude_srcs)
		srcs = bazel.MakeLabelListAttribute(srcs_labels)
	}


	var allReplacements bazel.LabelList
	var allReplacements bazel.LabelList
	allReplacements.Append(tools.Value)
	allReplacements.Append(tools.Value)
	allReplacements.Append(srcs.Value)
	allReplacements.Append(bazel.FirstUniqueBazelLabelList(srcs_labels))


	// Replace in and out variables with $< and $@
	// Replace in and out variables with $< and $@
	var cmd string
	var cmd string