Make cc_genrule.srcs configurable.
Also disallow arch variant of genrule.out. This is to be consistent with bazel where we are migrating to. Bug: 254114674 Test: Manual Change-Id: I685a2e64102b7bb68128b39931f0bc85878bc6de
This commit is contained in:
parent
bdb7495fe5
commit
d6201013eb
3 changed files with 71 additions and 8 deletions
|
@ -15,12 +15,13 @@
|
|||
package bp2build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/cc"
|
||||
"android/soong/genrule"
|
||||
"android/soong/java"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
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,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -40,14 +40,13 @@ func TestArchGenruleCmd(t *testing.T) {
|
|||
name: "gen",
|
||||
tool_files: ["tool"],
|
||||
cmd: "$(location tool) $(in) $(out)",
|
||||
out: ["out_arm"],
|
||||
arch: {
|
||||
arm: {
|
||||
srcs: ["foo"],
|
||||
out: ["out_arm"],
|
||||
},
|
||||
arm64: {
|
||||
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())
|
||||
}
|
||||
|
||||
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"}
|
||||
if !reflect.DeepEqual(expected, gen.Implicits.Strings()[:len(expected)]) {
|
||||
t.Errorf(`want arm64 inputs %v, got %v`, expected, gen.Implicits.Strings())
|
||||
|
|
|
@ -875,7 +875,7 @@ func GenRuleFactory() android.Module {
|
|||
|
||||
type genRuleProperties struct {
|
||||
// names of the output files that will be generated
|
||||
Out []string `android:"arch_variant"`
|
||||
Out []string
|
||||
}
|
||||
|
||||
type bazelGenruleAttributes struct {
|
||||
|
@ -893,11 +893,27 @@ func (m *Module) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
|
|||
tools_prop.Append(tool_files_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
|
||||
allReplacements.Append(tools.Value)
|
||||
allReplacements.Append(srcs.Value)
|
||||
allReplacements.Append(bazel.FirstUniqueBazelLabelList(srcs_labels))
|
||||
|
||||
// Replace in and out variables with $< and $@
|
||||
var cmd string
|
||||
|
|
Loading…
Reference in a new issue