Loading android/module.go +5 −0 Original line number Diff line number Diff line Loading @@ -1165,6 +1165,11 @@ func (attrs *CommonAttributes) fillCommonBp2BuildModuleAttrs(ctx *topDownMutator 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( bazel.LabelList{[]bazel.Label{bazel.Label{Label: "@platforms//:incompatible"}}, nil}, bazel.LabelList{[]bazel.Label{}, nil}) Loading bp2build/cc_binary_conversion_test.go +4 −4 Original line number Diff line number Diff line Loading @@ -84,13 +84,13 @@ func runCcHostBinaryTestCase(t *testing.T, tc ccBinaryBp2buildTestCase) { t.Helper() testCase := tc for i, tar := range testCase.targets { if tar.typ != "cc_binary" { continue } switch tar.typ { case "cc_binary", "proto_library", "cc_lite_proto_library": tar.attrs["target_compatible_with"] = `select({ "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], "//conditions:default": [], })` } testCase.targets[i] = tar } moduleTypeUnderTest := "cc_binary_host" Loading bp2build/genrule_conversion_test.go +110 −42 Original line number Diff line number Diff line Loading @@ -97,13 +97,22 @@ func TestGenruleCliVariableReplacement(t *testing.T) { }` for _, tc := range testCases { expectedBazelTargets := []string{ makeBazelTarget("genrule", "foo", attrNameToString{ 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{ makeBazelTarget("genrule", "foo", moduleAttrs), } t.Run(tc.moduleType, func(t *testing.T) { Loading Loading @@ -158,25 +167,36 @@ func TestGenruleLocationsLabel(t *testing.T) { bazel_module: { bp2build_available: true }, }` expectedBazelTargets := []string{ makeBazelTarget("genrule", "foo", attrNameToString{ for _, tc := range testCases { fooAttrs := attrNameToString{ "cmd": `"$(locations :foo.tools) -s $(OUTS) $(SRCS)"`, "outs": `["foo.out"]`, "srcs": `["foo.in"]`, "tools": `[":foo.tools"]`, }), makeBazelTarget("genrule", "foo.tools", attrNameToString{ } fooToolsAttrs := attrNameToString{ "cmd": `"cp $(SRCS) $(OUTS)"`, "outs": `[ "foo_tool.out", "foo_tool2.out", ]`, "srcs": `["foo_tool.in"]`, }), } for _, tc := range testCases { 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), } t.Run(tc.moduleType, func(t *testing.T) { runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, bp2buildTestCase{ Loading Loading @@ -221,16 +241,25 @@ func TestGenruleLocationsAbsoluteLabel(t *testing.T) { bazel_module: { bp2build_available: true }, }` expectedBazelTargets := []string{ makeBazelTarget("genrule", "foo", attrNameToString{ for _, tc := range testCases { moduleAttrs := attrNameToString{ "cmd": `"$(locations //other:foo.tool) -s $(OUTS) $(SRCS)"`, "outs": `["foo.out"]`, "srcs": `["foo.in"]`, "tools": `["//other:foo.tool"]`, }), } for _, tc := range testCases { 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), } t.Run(tc.moduleType, func(t *testing.T) { runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, bp2buildTestCase{ Loading Loading @@ -276,16 +305,25 @@ func TestGenruleSrcsLocationsAbsoluteLabel(t *testing.T) { bazel_module: { bp2build_available: true }, }` expectedBazelTargets := []string{ makeBazelTarget("genrule", "foo", attrNameToString{ for _, tc := range testCases { moduleAttrs := attrNameToString{ "cmd": `"$(locations //other:foo.tool) -s $(OUTS) $(location //other:other.tool)"`, "outs": `["foo.out"]`, "srcs": `["//other:other.tool"]`, "tools": `["//other:foo.tool"]`, }), } for _, tc := range testCases { 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), } t.Run(tc.moduleType, func(t *testing.T) { runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, bp2buildTestCase{ Loading Loading @@ -331,8 +369,8 @@ func TestGenruleLocationLabelShouldSubstituteFirstToolLabel(t *testing.T) { bazel_module: { bp2build_available: true }, }` expectedBazelTargets := []string{ makeBazelTarget("genrule", "foo", attrNameToString{ for _, tc := range testCases { moduleAttrs := attrNameToString{ "cmd": `"$(location //other:foo.tool) -s $(OUTS) $(SRCS)"`, "outs": `["foo.out"]`, "srcs": `["foo.in"]`, Loading @@ -340,9 +378,19 @@ func TestGenruleLocationLabelShouldSubstituteFirstToolLabel(t *testing.T) { "//other:foo.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) { runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, bp2buildTestCase{ Loading Loading @@ -388,8 +436,8 @@ func TestGenruleLocationsLabelShouldSubstituteFirstToolLabel(t *testing.T) { bazel_module: { bp2build_available: true }, }` expectedBazelTargets := []string{ makeBazelTarget("genrule", "foo", attrNameToString{ for _, tc := range testCases { moduleAttrs := attrNameToString{ "cmd": `"$(locations //other:foo.tool) -s $(OUTS) $(SRCS)"`, "outs": `["foo.out"]`, "srcs": `["foo.in"]`, Loading @@ -397,9 +445,19 @@ func TestGenruleLocationsLabelShouldSubstituteFirstToolLabel(t *testing.T) { "//other:foo.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) { runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, bp2buildTestCase{ Loading Loading @@ -444,14 +502,24 @@ func TestGenruleWithoutToolsOrToolFiles(t *testing.T) { bazel_module: { bp2build_available: true }, }` expectedBazelTargets := []string{ makeBazelTarget("genrule", "foo", attrNameToString{ for _, tc := range testCases { moduleAttrs := attrNameToString{ "cmd": `"cp $(SRCS) $(OUTS)"`, "outs": `["foo.out"]`, "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) { runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, bp2buildTestCase{ Loading bp2build/java_binary_host_conversion_test.go +4 −0 Original line number Diff line number Diff line Loading @@ -59,6 +59,10 @@ func TestJavaBinaryHost(t *testing.T) { "deps": `["//other:jni-lib-1"]`, "jvm_flags": `["-Djava.library.path=$${RUNPATH}other"]`, "javacopts": `["-Xdoclint:all/protected"]`, "target_compatible_with": `select({ "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], "//conditions:default": [], })`, }), }, }) Loading bp2build/java_library_host_conversion_test.go +8 −0 Original line number Diff line number Diff line Loading @@ -48,9 +48,17 @@ java_library_host { makeBazelTarget("java_library", "java-lib-host-1", attrNameToString{ "srcs": `["a.java"]`, "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{ "srcs": `["c.java"]`, "target_compatible_with": `select({ "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], "//conditions:default": [], })`, }), }, }) Loading Loading
android/module.go +5 −0 Original line number Diff line number Diff line Loading @@ -1165,6 +1165,11 @@ func (attrs *CommonAttributes) fillCommonBp2BuildModuleAttrs(ctx *topDownMutator 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( bazel.LabelList{[]bazel.Label{bazel.Label{Label: "@platforms//:incompatible"}}, nil}, bazel.LabelList{[]bazel.Label{}, nil}) Loading
bp2build/cc_binary_conversion_test.go +4 −4 Original line number Diff line number Diff line Loading @@ -84,13 +84,13 @@ func runCcHostBinaryTestCase(t *testing.T, tc ccBinaryBp2buildTestCase) { t.Helper() testCase := tc for i, tar := range testCase.targets { if tar.typ != "cc_binary" { continue } switch tar.typ { case "cc_binary", "proto_library", "cc_lite_proto_library": tar.attrs["target_compatible_with"] = `select({ "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], "//conditions:default": [], })` } testCase.targets[i] = tar } moduleTypeUnderTest := "cc_binary_host" Loading
bp2build/genrule_conversion_test.go +110 −42 Original line number Diff line number Diff line Loading @@ -97,13 +97,22 @@ func TestGenruleCliVariableReplacement(t *testing.T) { }` for _, tc := range testCases { expectedBazelTargets := []string{ makeBazelTarget("genrule", "foo", attrNameToString{ 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{ makeBazelTarget("genrule", "foo", moduleAttrs), } t.Run(tc.moduleType, func(t *testing.T) { Loading Loading @@ -158,25 +167,36 @@ func TestGenruleLocationsLabel(t *testing.T) { bazel_module: { bp2build_available: true }, }` expectedBazelTargets := []string{ makeBazelTarget("genrule", "foo", attrNameToString{ for _, tc := range testCases { fooAttrs := attrNameToString{ "cmd": `"$(locations :foo.tools) -s $(OUTS) $(SRCS)"`, "outs": `["foo.out"]`, "srcs": `["foo.in"]`, "tools": `[":foo.tools"]`, }), makeBazelTarget("genrule", "foo.tools", attrNameToString{ } fooToolsAttrs := attrNameToString{ "cmd": `"cp $(SRCS) $(OUTS)"`, "outs": `[ "foo_tool.out", "foo_tool2.out", ]`, "srcs": `["foo_tool.in"]`, }), } for _, tc := range testCases { 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), } t.Run(tc.moduleType, func(t *testing.T) { runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, bp2buildTestCase{ Loading Loading @@ -221,16 +241,25 @@ func TestGenruleLocationsAbsoluteLabel(t *testing.T) { bazel_module: { bp2build_available: true }, }` expectedBazelTargets := []string{ makeBazelTarget("genrule", "foo", attrNameToString{ for _, tc := range testCases { moduleAttrs := attrNameToString{ "cmd": `"$(locations //other:foo.tool) -s $(OUTS) $(SRCS)"`, "outs": `["foo.out"]`, "srcs": `["foo.in"]`, "tools": `["//other:foo.tool"]`, }), } for _, tc := range testCases { 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), } t.Run(tc.moduleType, func(t *testing.T) { runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, bp2buildTestCase{ Loading Loading @@ -276,16 +305,25 @@ func TestGenruleSrcsLocationsAbsoluteLabel(t *testing.T) { bazel_module: { bp2build_available: true }, }` expectedBazelTargets := []string{ makeBazelTarget("genrule", "foo", attrNameToString{ for _, tc := range testCases { moduleAttrs := attrNameToString{ "cmd": `"$(locations //other:foo.tool) -s $(OUTS) $(location //other:other.tool)"`, "outs": `["foo.out"]`, "srcs": `["//other:other.tool"]`, "tools": `["//other:foo.tool"]`, }), } for _, tc := range testCases { 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), } t.Run(tc.moduleType, func(t *testing.T) { runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, bp2buildTestCase{ Loading Loading @@ -331,8 +369,8 @@ func TestGenruleLocationLabelShouldSubstituteFirstToolLabel(t *testing.T) { bazel_module: { bp2build_available: true }, }` expectedBazelTargets := []string{ makeBazelTarget("genrule", "foo", attrNameToString{ for _, tc := range testCases { moduleAttrs := attrNameToString{ "cmd": `"$(location //other:foo.tool) -s $(OUTS) $(SRCS)"`, "outs": `["foo.out"]`, "srcs": `["foo.in"]`, Loading @@ -340,9 +378,19 @@ func TestGenruleLocationLabelShouldSubstituteFirstToolLabel(t *testing.T) { "//other:foo.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) { runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, bp2buildTestCase{ Loading Loading @@ -388,8 +436,8 @@ func TestGenruleLocationsLabelShouldSubstituteFirstToolLabel(t *testing.T) { bazel_module: { bp2build_available: true }, }` expectedBazelTargets := []string{ makeBazelTarget("genrule", "foo", attrNameToString{ for _, tc := range testCases { moduleAttrs := attrNameToString{ "cmd": `"$(locations //other:foo.tool) -s $(OUTS) $(SRCS)"`, "outs": `["foo.out"]`, "srcs": `["foo.in"]`, Loading @@ -397,9 +445,19 @@ func TestGenruleLocationsLabelShouldSubstituteFirstToolLabel(t *testing.T) { "//other:foo.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) { runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, bp2buildTestCase{ Loading Loading @@ -444,14 +502,24 @@ func TestGenruleWithoutToolsOrToolFiles(t *testing.T) { bazel_module: { bp2build_available: true }, }` expectedBazelTargets := []string{ makeBazelTarget("genrule", "foo", attrNameToString{ for _, tc := range testCases { moduleAttrs := attrNameToString{ "cmd": `"cp $(SRCS) $(OUTS)"`, "outs": `["foo.out"]`, "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) { runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {}, bp2buildTestCase{ Loading
bp2build/java_binary_host_conversion_test.go +4 −0 Original line number Diff line number Diff line Loading @@ -59,6 +59,10 @@ func TestJavaBinaryHost(t *testing.T) { "deps": `["//other:jni-lib-1"]`, "jvm_flags": `["-Djava.library.path=$${RUNPATH}other"]`, "javacopts": `["-Xdoclint:all/protected"]`, "target_compatible_with": `select({ "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], "//conditions:default": [], })`, }), }, }) Loading
bp2build/java_library_host_conversion_test.go +8 −0 Original line number Diff line number Diff line Loading @@ -48,9 +48,17 @@ java_library_host { makeBazelTarget("java_library", "java-lib-host-1", attrNameToString{ "srcs": `["a.java"]`, "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{ "srcs": `["c.java"]`, "target_compatible_with": `select({ "//build/bazel/platforms/os:android": ["@platforms//:incompatible"], "//conditions:default": [], })`, }), }, }) Loading