add target_compatible_with stanza for host targets

Soong modules that are specific for the host platform (e.g.
java_library_host, cc_binary_host, java_genrule_host, etc.) should
not be built on the target platform (Android), so we add a
target_compatible_with attribute to skip this type of module on an
Android target build.

Bug: 215229742
Test: go test ./bp2build
Change-Id: Ifb76ef4e0dc4cb3adb6a64b5c375ce36f7973e48
This commit is contained in:
Sam Delmerico
2022-01-31 14:37:29 +00:00
parent d519b331f2
commit 75539d62ae
9 changed files with 236 additions and 95 deletions

View File

@@ -1165,6 +1165,11 @@ func (attrs *CommonAttributes) fillCommonBp2BuildModuleAttrs(ctx *topDownMutator
productConfigEnabledLabels, nil, productConfigEnabledLabels, nil,
}) })
moduleSupportsDevice := mod.commonProperties.HostOrDeviceSupported&deviceSupported == deviceSupported
if mod.commonProperties.HostOrDeviceSupported != NeitherHostNorDeviceSupported && !moduleSupportsDevice {
enabledProperty.SetSelectValue(bazel.OsConfigurationAxis, Android.Name, proptools.BoolPtr(false))
}
platformEnabledAttribute, err := enabledProperty.ToLabelListAttribute( platformEnabledAttribute, err := enabledProperty.ToLabelListAttribute(
bazel.LabelList{[]bazel.Label{bazel.Label{Label: "@platforms//:incompatible"}}, nil}, bazel.LabelList{[]bazel.Label{bazel.Label{Label: "@platforms//:incompatible"}}, nil},
bazel.LabelList{[]bazel.Label{}, nil}) bazel.LabelList{[]bazel.Label{}, nil})

View File

@@ -84,13 +84,13 @@ func runCcHostBinaryTestCase(t *testing.T, tc ccBinaryBp2buildTestCase) {
t.Helper() t.Helper()
testCase := tc testCase := tc
for i, tar := range testCase.targets { for i, tar := range testCase.targets {
if tar.typ != "cc_binary" { switch tar.typ {
continue case "cc_binary", "proto_library", "cc_lite_proto_library":
} tar.attrs["target_compatible_with"] = `select({
tar.attrs["target_compatible_with"] = `select({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"], "//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [], "//conditions:default": [],
})` })`
}
testCase.targets[i] = tar testCase.targets[i] = tar
} }
moduleTypeUnderTest := "cc_binary_host" moduleTypeUnderTest := "cc_binary_host"

View File

@@ -97,13 +97,22 @@ func TestGenruleCliVariableReplacement(t *testing.T) {
}` }`
for _, tc := range testCases { for _, tc := range testCases {
moduleAttrs := attrNameToString{
"cmd": fmt.Sprintf(`"$(location :foo.tool) --genDir=%s arg $(SRCS) $(OUTS)"`, tc.genDir),
"outs": `["foo.out"]`,
"srcs": `["foo.in"]`,
"tools": `[":foo.tool"]`,
}
if tc.moduleType == "java_genrule_host" {
moduleAttrs["target_compatible_with"] = `select({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`
}
expectedBazelTargets := []string{ expectedBazelTargets := []string{
makeBazelTarget("genrule", "foo", attrNameToString{ makeBazelTarget("genrule", "foo", moduleAttrs),
"cmd": fmt.Sprintf(`"$(location :foo.tool) --genDir=%s arg $(SRCS) $(OUTS)"`, tc.genDir),
"outs": `["foo.out"]`,
"srcs": `["foo.in"]`,
"tools": `[":foo.tool"]`,
}),
} }
t.Run(tc.moduleType, func(t *testing.T) { t.Run(tc.moduleType, func(t *testing.T) {
@@ -158,25 +167,36 @@ func TestGenruleLocationsLabel(t *testing.T) {
bazel_module: { bp2build_available: true }, bazel_module: { bp2build_available: true },
}` }`
expectedBazelTargets := for _, tc := range testCases {
[]string{ fooAttrs := attrNameToString{
makeBazelTarget("genrule", "foo", attrNameToString{ "cmd": `"$(locations :foo.tools) -s $(OUTS) $(SRCS)"`,
"cmd": `"$(locations :foo.tools) -s $(OUTS) $(SRCS)"`, "outs": `["foo.out"]`,
"outs": `["foo.out"]`, "srcs": `["foo.in"]`,
"srcs": `["foo.in"]`, "tools": `[":foo.tools"]`,
"tools": `[":foo.tools"]`, }
}), fooToolsAttrs := attrNameToString{
makeBazelTarget("genrule", "foo.tools", attrNameToString{ "cmd": `"cp $(SRCS) $(OUTS)"`,
"cmd": `"cp $(SRCS) $(OUTS)"`, "outs": `[
"outs": `[
"foo_tool.out", "foo_tool.out",
"foo_tool2.out", "foo_tool2.out",
]`, ]`,
"srcs": `["foo_tool.in"]`, "srcs": `["foo_tool.in"]`,
}), }
if tc.moduleType == "java_genrule_host" {
compatibilityAttrs := `select({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`
fooAttrs["target_compatible_with"] = compatibilityAttrs
fooToolsAttrs["target_compatible_with"] = compatibilityAttrs
}
expectedBazelTargets := []string{
makeBazelTarget("genrule", "foo", fooAttrs),
makeBazelTarget("genrule", "foo.tools", fooToolsAttrs),
} }
for _, tc := range testCases {
t.Run(tc.moduleType, func(t *testing.T) { t.Run(tc.moduleType, func(t *testing.T) {
runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
bp2buildTestCase{ bp2buildTestCase{
@@ -221,16 +241,25 @@ func TestGenruleLocationsAbsoluteLabel(t *testing.T) {
bazel_module: { bp2build_available: true }, bazel_module: { bp2build_available: true },
}` }`
expectedBazelTargets := []string{ for _, tc := range testCases {
makeBazelTarget("genrule", "foo", attrNameToString{ moduleAttrs := attrNameToString{
"cmd": `"$(locations //other:foo.tool) -s $(OUTS) $(SRCS)"`, "cmd": `"$(locations //other:foo.tool) -s $(OUTS) $(SRCS)"`,
"outs": `["foo.out"]`, "outs": `["foo.out"]`,
"srcs": `["foo.in"]`, "srcs": `["foo.in"]`,
"tools": `["//other:foo.tool"]`, "tools": `["//other:foo.tool"]`,
}), }
}
if tc.moduleType == "java_genrule_host" {
moduleAttrs["target_compatible_with"] = `select({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`
}
expectedBazelTargets := []string{
makeBazelTarget("genrule", "foo", moduleAttrs),
}
for _, tc := range testCases {
t.Run(tc.moduleType, func(t *testing.T) { t.Run(tc.moduleType, func(t *testing.T) {
runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
bp2buildTestCase{ bp2buildTestCase{
@@ -276,16 +305,25 @@ func TestGenruleSrcsLocationsAbsoluteLabel(t *testing.T) {
bazel_module: { bp2build_available: true }, bazel_module: { bp2build_available: true },
}` }`
expectedBazelTargets := []string{ for _, tc := range testCases {
makeBazelTarget("genrule", "foo", attrNameToString{ moduleAttrs := attrNameToString{
"cmd": `"$(locations //other:foo.tool) -s $(OUTS) $(location //other:other.tool)"`, "cmd": `"$(locations //other:foo.tool) -s $(OUTS) $(location //other:other.tool)"`,
"outs": `["foo.out"]`, "outs": `["foo.out"]`,
"srcs": `["//other:other.tool"]`, "srcs": `["//other:other.tool"]`,
"tools": `["//other:foo.tool"]`, "tools": `["//other:foo.tool"]`,
}), }
}
if tc.moduleType == "java_genrule_host" {
moduleAttrs["target_compatible_with"] = `select({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`
}
expectedBazelTargets := []string{
makeBazelTarget("genrule", "foo", moduleAttrs),
}
for _, tc := range testCases {
t.Run(tc.moduleType, func(t *testing.T) { t.Run(tc.moduleType, func(t *testing.T) {
runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
bp2buildTestCase{ bp2buildTestCase{
@@ -331,8 +369,8 @@ func TestGenruleLocationLabelShouldSubstituteFirstToolLabel(t *testing.T) {
bazel_module: { bp2build_available: true }, bazel_module: { bp2build_available: true },
}` }`
expectedBazelTargets := []string{ for _, tc := range testCases {
makeBazelTarget("genrule", "foo", attrNameToString{ moduleAttrs := attrNameToString{
"cmd": `"$(location //other:foo.tool) -s $(OUTS) $(SRCS)"`, "cmd": `"$(location //other:foo.tool) -s $(OUTS) $(SRCS)"`,
"outs": `["foo.out"]`, "outs": `["foo.out"]`,
"srcs": `["foo.in"]`, "srcs": `["foo.in"]`,
@@ -340,9 +378,19 @@ func TestGenruleLocationLabelShouldSubstituteFirstToolLabel(t *testing.T) {
"//other:foo.tool", "//other:foo.tool",
"//other:other.tool", "//other:other.tool",
]`, ]`,
})} }
if tc.moduleType == "java_genrule_host" {
moduleAttrs["target_compatible_with"] = `select({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`
}
expectedBazelTargets := []string{
makeBazelTarget("genrule", "foo", moduleAttrs),
}
for _, tc := range testCases {
t.Run(tc.moduleType, func(t *testing.T) { t.Run(tc.moduleType, func(t *testing.T) {
runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
bp2buildTestCase{ bp2buildTestCase{
@@ -388,8 +436,8 @@ func TestGenruleLocationsLabelShouldSubstituteFirstToolLabel(t *testing.T) {
bazel_module: { bp2build_available: true }, bazel_module: { bp2build_available: true },
}` }`
expectedBazelTargets := []string{ for _, tc := range testCases {
makeBazelTarget("genrule", "foo", attrNameToString{ moduleAttrs := attrNameToString{
"cmd": `"$(locations //other:foo.tool) -s $(OUTS) $(SRCS)"`, "cmd": `"$(locations //other:foo.tool) -s $(OUTS) $(SRCS)"`,
"outs": `["foo.out"]`, "outs": `["foo.out"]`,
"srcs": `["foo.in"]`, "srcs": `["foo.in"]`,
@@ -397,9 +445,19 @@ func TestGenruleLocationsLabelShouldSubstituteFirstToolLabel(t *testing.T) {
"//other:foo.tool", "//other:foo.tool",
"//other:other.tool", "//other:other.tool",
]`, ]`,
})} }
if tc.moduleType == "java_genrule_host" {
moduleAttrs["target_compatible_with"] = `select({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`
}
expectedBazelTargets := []string{
makeBazelTarget("genrule", "foo", moduleAttrs),
}
for _, tc := range testCases {
t.Run(tc.moduleType, func(t *testing.T) { t.Run(tc.moduleType, func(t *testing.T) {
runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
bp2buildTestCase{ bp2buildTestCase{
@@ -444,14 +502,24 @@ func TestGenruleWithoutToolsOrToolFiles(t *testing.T) {
bazel_module: { bp2build_available: true }, bazel_module: { bp2build_available: true },
}` }`
expectedBazelTargets := []string{ for _, tc := range testCases {
makeBazelTarget("genrule", "foo", attrNameToString{ moduleAttrs := attrNameToString{
"cmd": `"cp $(SRCS) $(OUTS)"`, "cmd": `"cp $(SRCS) $(OUTS)"`,
"outs": `["foo.out"]`, "outs": `["foo.out"]`,
"srcs": `["foo.in"]`, "srcs": `["foo.in"]`,
})} }
if tc.moduleType == "java_genrule_host" {
moduleAttrs["target_compatible_with"] = `select({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`
}
expectedBazelTargets := []string{
makeBazelTarget("genrule", "foo", moduleAttrs),
}
for _, tc := range testCases {
t.Run(tc.moduleType, func(t *testing.T) { t.Run(tc.moduleType, func(t *testing.T) {
runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {},
bp2buildTestCase{ bp2buildTestCase{

View File

@@ -59,6 +59,10 @@ func TestJavaBinaryHost(t *testing.T) {
"deps": `["//other:jni-lib-1"]`, "deps": `["//other:jni-lib-1"]`,
"jvm_flags": `["-Djava.library.path=$${RUNPATH}other"]`, "jvm_flags": `["-Djava.library.path=$${RUNPATH}other"]`,
"javacopts": `["-Xdoclint:all/protected"]`, "javacopts": `["-Xdoclint:all/protected"]`,
"target_compatible_with": `select({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}), }),
}, },
}) })

View File

@@ -48,9 +48,17 @@ java_library_host {
makeBazelTarget("java_library", "java-lib-host-1", attrNameToString{ makeBazelTarget("java_library", "java-lib-host-1", attrNameToString{
"srcs": `["a.java"]`, "srcs": `["a.java"]`,
"deps": `[":java-lib-host-2"]`, "deps": `[":java-lib-host-2"]`,
"target_compatible_with": `select({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}), }),
makeBazelTarget("java_library", "java-lib-host-2", attrNameToString{ makeBazelTarget("java_library", "java-lib-host-2", attrNameToString{
"srcs": `["c.java"]`, "srcs": `["c.java"]`,
"target_compatible_with": `select({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}), }),
}, },
}) })

View File

@@ -51,6 +51,10 @@ func TestPythonBinaryHostSimple(t *testing.T) {
"b/c.py", "b/c.py",
"b/d.py", "b/d.py",
]`, ]`,
"target_compatible_with": `select({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}), }),
}, },
}) })
@@ -80,6 +84,10 @@ func TestPythonBinaryHostPy2(t *testing.T) {
makeBazelTarget("py_binary", "foo", attrNameToString{ makeBazelTarget("py_binary", "foo", attrNameToString{
"python_version": `"PY2"`, "python_version": `"PY2"`,
"srcs": `["a.py"]`, "srcs": `["a.py"]`,
"target_compatible_with": `select({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}), }),
}, },
}) })
@@ -109,6 +117,10 @@ func TestPythonBinaryHostPy3(t *testing.T) {
// python_version is PY3 by default. // python_version is PY3 by default.
makeBazelTarget("py_binary", "foo", attrNameToString{ makeBazelTarget("py_binary", "foo", attrNameToString{
"srcs": `["a.py"]`, "srcs": `["a.py"]`,
"target_compatible_with": `select({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}), }),
}, },
}) })
@@ -140,6 +152,10 @@ func TestPythonBinaryHostArchVariance(t *testing.T) {
"//build/bazel/platforms/arch:arm": ["arm.py"], "//build/bazel/platforms/arch:arm": ["arm.py"],
"//build/bazel/platforms/arch:x86": ["x86.py"], "//build/bazel/platforms/arch:x86": ["x86.py"],
"//conditions:default": [], "//conditions:default": [],
})`,
"target_compatible_with": `select({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`, })`,
}), }),
}, },

View File

@@ -11,19 +11,51 @@ import (
// TODO(alexmarquez): Should be lifted into a generic Bp2Build file // TODO(alexmarquez): Should be lifted into a generic Bp2Build file
type PythonLibBp2Build func(ctx android.TopDownMutatorContext) type PythonLibBp2Build func(ctx android.TopDownMutatorContext)
func runPythonLibraryTestCase(t *testing.T, tc bp2buildTestCase) { type pythonLibBp2BuildTestCase struct {
description string
filesystem map[string]string
blueprint string
expectedBazelTargets []testBazelTarget
}
func convertPythonLibTestCaseToBp2build_Host(tc pythonLibBp2BuildTestCase) bp2buildTestCase {
for i := range tc.expectedBazelTargets {
tc.expectedBazelTargets[i].attrs["target_compatible_with"] = `select({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`
}
return convertPythonLibTestCaseToBp2build(tc)
}
func convertPythonLibTestCaseToBp2build(tc pythonLibBp2BuildTestCase) bp2buildTestCase {
var bp2BuildTargets []string
for _, t := range tc.expectedBazelTargets {
bp2BuildTargets = append(bp2BuildTargets, makeBazelTarget(t.typ, t.name, t.attrs))
}
return bp2buildTestCase{
description: tc.description,
filesystem: tc.filesystem,
blueprint: tc.blueprint,
expectedBazelTargets: bp2BuildTargets,
}
}
func runPythonLibraryTestCase(t *testing.T, tc pythonLibBp2BuildTestCase) {
t.Helper() t.Helper()
testCase := tc testCase := convertPythonLibTestCaseToBp2build(tc)
testCase.description = fmt.Sprintf(testCase.description, "python_library") testCase.description = fmt.Sprintf(testCase.description, "python_library")
testCase.blueprint = fmt.Sprintf(testCase.blueprint, "python_library") testCase.blueprint = fmt.Sprintf(testCase.blueprint, "python_library")
testCase.moduleTypeUnderTest = "python_library" testCase.moduleTypeUnderTest = "python_library"
testCase.moduleTypeUnderTestFactory = python.PythonLibraryFactory testCase.moduleTypeUnderTestFactory = python.PythonLibraryFactory
runBp2BuildTestCaseSimple(t, testCase) runBp2BuildTestCaseSimple(t, testCase)
} }
func runPythonLibraryHostTestCase(t *testing.T, tc bp2buildTestCase) { func runPythonLibraryHostTestCase(t *testing.T, tc pythonLibBp2BuildTestCase) {
t.Helper() t.Helper()
testCase := tc testCase := convertPythonLibTestCaseToBp2build_Host(tc)
testCase.description = fmt.Sprintf(testCase.description, "python_library_host") testCase.description = fmt.Sprintf(testCase.description, "python_library_host")
testCase.blueprint = fmt.Sprintf(testCase.blueprint, "python_library_host") testCase.blueprint = fmt.Sprintf(testCase.blueprint, "python_library_host")
testCase.moduleTypeUnderTest = "python_library_host" testCase.moduleTypeUnderTest = "python_library_host"
@@ -34,14 +66,14 @@ func runPythonLibraryHostTestCase(t *testing.T, tc bp2buildTestCase) {
testCase) testCase)
} }
func runPythonLibraryTestCases(t *testing.T, tc bp2buildTestCase) { func runPythonLibraryTestCases(t *testing.T, tc pythonLibBp2BuildTestCase) {
t.Helper() t.Helper()
runPythonLibraryTestCase(t, tc) runPythonLibraryTestCase(t, tc)
runPythonLibraryHostTestCase(t, tc) runPythonLibraryHostTestCase(t, tc)
} }
func TestSimplePythonLib(t *testing.T) { func TestSimplePythonLib(t *testing.T) {
testCases := []bp2buildTestCase{ testCases := []pythonLibBp2BuildTestCase{
{ {
description: "simple %s converts to a native py_library", description: "simple %s converts to a native py_library",
filesystem: map[string]string{ filesystem: map[string]string{
@@ -64,17 +96,21 @@ func TestSimplePythonLib(t *testing.T) {
srcs: ["b/e.py"], srcs: ["b/e.py"],
bazel_module: { bp2build_available: false }, bazel_module: { bp2build_available: false },
}`, }`,
expectedBazelTargets: []string{ expectedBazelTargets: []testBazelTarget{
makeBazelTarget("py_library", "foo", attrNameToString{ {
"data": `["files/data.txt"]`, typ: "py_library",
"deps": `[":bar"]`, name: "foo",
"srcs": `[ attrs: attrNameToString{
"data": `["files/data.txt"]`,
"deps": `[":bar"]`,
"srcs": `[
"a.py", "a.py",
"b/c.py", "b/c.py",
"b/d.py", "b/d.py",
]`, ]`,
"srcs_version": `"PY3"`, "srcs_version": `"PY3"`,
}), },
},
}, },
}, },
{ {
@@ -93,11 +129,15 @@ func TestSimplePythonLib(t *testing.T) {
bazel_module: { bp2build_available: true }, bazel_module: { bp2build_available: true },
}`, }`,
expectedBazelTargets: []string{ expectedBazelTargets: []testBazelTarget{
makeBazelTarget("py_library", "foo", attrNameToString{ {
"srcs": `["a.py"]`, typ: "py_library",
"srcs_version": `"PY2"`, name: "foo",
}), attrs: attrNameToString{
"srcs": `["a.py"]`,
"srcs_version": `"PY2"`,
},
},
}, },
}, },
{ {
@@ -116,11 +156,15 @@ func TestSimplePythonLib(t *testing.T) {
bazel_module: { bp2build_available: true }, bazel_module: { bp2build_available: true },
}`, }`,
expectedBazelTargets: []string{ expectedBazelTargets: []testBazelTarget{
makeBazelTarget("py_library", "foo", attrNameToString{ {
"srcs": `["a.py"]`, typ: "py_library",
"srcs_version": `"PY3"`, name: "foo",
}), attrs: attrNameToString{
"srcs": `["a.py"]`,
"srcs_version": `"PY3"`,
},
},
}, },
}, },
{ {
@@ -139,11 +183,15 @@ func TestSimplePythonLib(t *testing.T) {
bazel_module: { bp2build_available: true }, bazel_module: { bp2build_available: true },
}`, }`,
expectedBazelTargets: []string{ expectedBazelTargets: []testBazelTarget{
// srcs_version is PY2ANDPY3 by default. {
makeBazelTarget("py_library", "foo", attrNameToString{ // srcs_version is PY2ANDPY3 by default.
"srcs": `["a.py"]`, typ: "py_library",
}), name: "foo",
attrs: attrNameToString{
"srcs": `["a.py"]`,
},
},
}, },
}, },
} }
@@ -156,7 +204,7 @@ func TestSimplePythonLib(t *testing.T) {
} }
func TestPythonArchVariance(t *testing.T) { func TestPythonArchVariance(t *testing.T) {
runPythonLibraryTestCases(t, bp2buildTestCase{ runPythonLibraryTestCases(t, pythonLibBp2BuildTestCase{
description: "test %s arch variants", description: "test %s arch variants",
filesystem: map[string]string{ filesystem: map[string]string{
"dir/arm.py": "", "dir/arm.py": "",
@@ -173,15 +221,19 @@ func TestPythonArchVariance(t *testing.T) {
}, },
}, },
}`, }`,
expectedBazelTargets: []string{ expectedBazelTargets: []testBazelTarget{
makeBazelTarget("py_library", "foo", attrNameToString{ {
"srcs": `select({ typ: "py_library",
name: "foo",
attrs: attrNameToString{
"srcs": `select({
"//build/bazel/platforms/arch:arm": ["arm.py"], "//build/bazel/platforms/arch:arm": ["arm.py"],
"//build/bazel/platforms/arch:x86": ["x86.py"], "//build/bazel/platforms/arch:x86": ["x86.py"],
"//conditions:default": [], "//conditions:default": [],
})`, })`,
"srcs_version": `"PY3"`, "srcs_version": `"PY3"`,
}), },
},
}, },
}) })
} }

View File

@@ -605,19 +605,12 @@ func binaryBp2build(ctx android.TopDownMutatorContext, m *Module, typ string) {
Features: baseAttrs.features, Features: baseAttrs.features,
} }
var enabledProperty bazel.BoolAttribute ctx.CreateBazelTargetModule(bazel.BazelTargetModuleProperties{
if typ == "cc_binary_host" {
falseVal := false
enabledProperty.SetSelectValue(bazel.OsConfigurationAxis, android.Android.Name, &falseVal)
}
ctx.CreateBazelTargetModuleWithRestrictions(bazel.BazelTargetModuleProperties{
Rule_class: "cc_binary", Rule_class: "cc_binary",
Bzl_load_location: "//build/bazel/rules:cc_binary.bzl", Bzl_load_location: "//build/bazel/rules:cc_binary.bzl",
}, },
android.CommonAttributes{Name: m.Name()}, android.CommonAttributes{Name: m.Name()},
attrs, attrs)
enabledProperty)
} }
// binaryAttributes contains Bazel attributes corresponding to a cc binary // binaryAttributes contains Bazel attributes corresponding to a cc binary

View File

@@ -17,8 +17,6 @@ package java
import ( import (
"android/soong/android" "android/soong/android"
"android/soong/bazel" "android/soong/bazel"
"github.com/google/blueprint/proptools"
) )
func init() { func init() {
@@ -78,12 +76,9 @@ func (p *Plugin) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
attrs.Processor_class = p.pluginProperties.Processor_class attrs.Processor_class = p.pluginProperties.Processor_class
} }
var enabledProperty bazel.BoolAttribute
enabledProperty.SetSelectValue(bazel.OsConfigurationAxis, android.Android.Name, proptools.BoolPtr(false))
props := bazel.BazelTargetModuleProperties{ props := bazel.BazelTargetModuleProperties{
Rule_class: "java_plugin", Rule_class: "java_plugin",
} }
ctx.CreateBazelTargetModuleWithRestrictions(props, android.CommonAttributes{Name: p.Name()}, attrs, enabledProperty) ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: p.Name()}, attrs)
} }