Merge "[bp2build] android_test bp2build." into main am: 088c4b652b am: 3aaf1a80bd

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2727561

Change-Id: I629c0b2f44b1a50cb4f487d077f63036cf96862d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Jingwen Chen
2023-09-19 00:11:04 +00:00
committed by Automerger Merge Worker
5 changed files with 73 additions and 24 deletions

View File

@@ -65,6 +65,7 @@ var (
"build/bazel": Bp2BuildDefaultTrueRecursively, "build/bazel": Bp2BuildDefaultTrueRecursively,
"build/make/target/product/security": Bp2BuildDefaultTrue, "build/make/target/product/security": Bp2BuildDefaultTrue,
"build/make/tools": Bp2BuildDefaultTrue,
"build/make/tools/protos": Bp2BuildDefaultTrue, "build/make/tools/protos": Bp2BuildDefaultTrue,
"build/make/tools/releasetools": Bp2BuildDefaultTrue, "build/make/tools/releasetools": Bp2BuildDefaultTrue,
"build/make/tools/sbom": Bp2BuildDefaultTrue, "build/make/tools/sbom": Bp2BuildDefaultTrue,
@@ -79,7 +80,9 @@ var (
"build/soong/scripts": Bp2BuildDefaultTrueRecursively, "build/soong/scripts": Bp2BuildDefaultTrueRecursively,
"cts/common/device-side/nativetesthelper/jni": Bp2BuildDefaultTrueRecursively, "cts/common/device-side/nativetesthelper/jni": Bp2BuildDefaultTrueRecursively,
"cts/libs/json": Bp2BuildDefaultTrueRecursively, "cts/libs/json": Bp2BuildDefaultTrueRecursively,
"cts/tests/tests/gesture": Bp2BuildDefaultTrueRecursively,
"platform_testing/libraries/annotations": Bp2BuildDefaultTrueRecursively,
"dalvik/tools/dexdeps": Bp2BuildDefaultTrueRecursively, "dalvik/tools/dexdeps": Bp2BuildDefaultTrueRecursively,
@@ -892,9 +895,6 @@ var (
"merge_annotation_zips_test", "merge_annotation_zips_test",
// bouncycastle dep
"platform-test-annotations",
// java_resources with multiple resource_dirs // java_resources with multiple resource_dirs
"emma", "emma",
@@ -904,6 +904,16 @@ var (
"ndk_libc++_static", "ndk_libc++_static",
"ndk_libc++_shared", "ndk_libc++_shared",
"ndk_system", "ndk_system",
// allowlist //prebuilts/common/misc/androidx-test/...
"androidx.test.runner",
"androidx.test.runner-nodeps",
"androidx.test.services.storage",
"androidx.test.services.storage-nodeps",
"androidx.test.monitor",
"androidx.test.monitor-nodeps",
"androidx.test.annotation",
"androidx.test.annotation-nodeps",
} }
Bp2buildModuleTypeAlwaysConvertList = []string{ Bp2buildModuleTypeAlwaysConvertList = []string{
@@ -1649,6 +1659,17 @@ var (
// TODO(b/299974637) Fix linking error // TODO(b/299974637) Fix linking error
"libbinder_rpc_unstable", "libbinder_rpc_unstable",
// TODO(b/297356704) sdk_version is unset.
"VendorAtomCodeGenJavaTest",
// android_test from allowlisted packages, but with unconverted deps
"MtsLibnativehelperLazyTestCases",
"ObjenesisTck",
"DevCodelabTest",
"MtsTimeZoneDataTestCases",
"NanoAndroidTest",
"MtsLibnativehelperTestCases",
} }
// Bazel prod-mode allowlist. Modules in this list are built by Bazel // Bazel prod-mode allowlist. Modules in this list are built by Bazel

View File

@@ -1636,15 +1636,23 @@ func (b bp2buildInfo) BazelAttributes() []interface{} {
} }
func (m *ModuleBase) addBp2buildInfo(info bp2buildInfo) { func (m *ModuleBase) addBp2buildInfo(info bp2buildInfo) {
if m.commonProperties.BazelConversionStatus.UnconvertedReason != nil { reason := m.commonProperties.BazelConversionStatus.UnconvertedReason
panic(fmt.Errorf("bp2build: module '%s' marked unconvertible and also is converted", m.Name())) if reason != nil {
panic(fmt.Errorf("bp2build: internal error trying to convert module '%s' marked unconvertible. Reason type %d: %s",
m.Name(),
reason.ReasonType,
reason.Detail))
} }
m.commonProperties.BazelConversionStatus.Bp2buildInfo = append(m.commonProperties.BazelConversionStatus.Bp2buildInfo, info) m.commonProperties.BazelConversionStatus.Bp2buildInfo = append(m.commonProperties.BazelConversionStatus.Bp2buildInfo, info)
} }
func (m *ModuleBase) setBp2buildUnconvertible(reasonType bp2build_metrics_proto.UnconvertedReasonType, detail string) { func (m *ModuleBase) setBp2buildUnconvertible(reasonType bp2build_metrics_proto.UnconvertedReasonType, detail string) {
if len(m.commonProperties.BazelConversionStatus.Bp2buildInfo) > 0 { if len(m.commonProperties.BazelConversionStatus.Bp2buildInfo) > 0 {
panic(fmt.Errorf("bp2build: module '%s' marked unconvertible and also is converted", m.Name())) fmt.Println(m.commonProperties.BazelConversionStatus.Bp2buildInfo)
panic(fmt.Errorf("bp2build: internal error trying to mark converted module '%s' as unconvertible. Reason type %d: %s",
m.Name(),
reasonType,
detail))
} }
m.commonProperties.BazelConversionStatus.UnconvertedReason = &UnconvertedReason{ m.commonProperties.BazelConversionStatus.UnconvertedReason = &UnconvertedReason{
ReasonType: int(reasonType), ReasonType: int(reasonType),

View File

@@ -17,7 +17,6 @@ package bp2build
import ( import (
"android/soong/android" "android/soong/android"
"android/soong/java" "android/soong/java"
"fmt"
"testing" "testing"
) )
@@ -91,7 +90,6 @@ android_library {
sdk_version: "current", sdk_version: "current",
} }
`, `,
ExpectedErr: fmt.Errorf("Module has direct dependencies but no sources. Bazel will not allow this."),
ExpectedBazelTargets: []string{}, ExpectedBazelTargets: []string{},
}) })
} }

View File

@@ -1340,7 +1340,10 @@ func (a *AndroidLibrary) ConvertWithBp2build(ctx android.TopDownMutatorContext)
if !commonAttrs.Srcs.IsEmpty() { if !commonAttrs.Srcs.IsEmpty() {
deps.Append(depLabels.StaticDeps) // we should only append these if there are sources to use them deps.Append(depLabels.StaticDeps) // we should only append these if there are sources to use them
} else if !depLabels.Deps.IsEmpty() { } else if !depLabels.Deps.IsEmpty() {
ctx.ModuleErrorf("Module has direct dependencies but no sources. Bazel will not allow this.") ctx.MarkBp2buildUnconvertible(
bp2build_metrics_proto.UnconvertedReasonType_UNSUPPORTED,
"Module has direct dependencies but no sources. Bazel will not allow this.")
return
} }
name := a.Name() name := a.Name()
props := AndroidLibraryBazelTargetModuleProperties() props := AndroidLibraryBazelTargetModuleProperties()

View File

@@ -1115,6 +1115,8 @@ type AndroidTest struct {
testConfig android.Path testConfig android.Path
extraTestConfigs android.Paths extraTestConfigs android.Paths
data android.Paths data android.Paths
android.BazelModuleBase
} }
func (a *AndroidTest) InstallInTestcases() bool { func (a *AndroidTest) InstallInTestcases() bool {
@@ -1232,6 +1234,8 @@ func AndroidTestFactory() android.Module {
android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon) android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
android.InitDefaultableModule(module) android.InitDefaultableModule(module)
android.InitOverridableModule(module, &module.overridableAppProperties.Overrides) android.InitOverridableModule(module, &module.overridableAppProperties.Overrides)
android.InitBazelModule(module)
return module return module
} }
@@ -1630,11 +1634,10 @@ type bazelAndroidAppAttributes struct {
Proguard_specs bazel.LabelListAttribute Proguard_specs bazel.LabelListAttribute
} }
// ConvertWithBp2build is used to convert android_app to Bazel. func convertWithBp2build(ctx android.TopDownMutatorContext, a *AndroidApp) (bool, android.CommonAttributes, *bazelAndroidAppAttributes) {
func (a *AndroidApp) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
aapt, supported := a.convertAaptAttrsWithBp2Build(ctx) aapt, supported := a.convertAaptAttrsWithBp2Build(ctx)
if !supported { if !supported {
return return false, android.CommonAttributes{}, &bazelAndroidAppAttributes{}
} }
certificate, certificateName := android.BazelStringOrLabelFromProp(ctx, a.overridableAppProperties.Certificate) certificate, certificateName := android.BazelStringOrLabelFromProp(ctx, a.overridableAppProperties.Certificate)
@@ -1706,18 +1709,13 @@ func (a *AndroidApp) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
commonAttrs, bp2BuildInfo, supported := a.convertLibraryAttrsBp2Build(ctx) commonAttrs, bp2BuildInfo, supported := a.convertLibraryAttrsBp2Build(ctx)
if !supported { if !supported {
return return false, android.CommonAttributes{}, &bazelAndroidAppAttributes{}
} }
depLabels := bp2BuildInfo.DepLabels depLabels := bp2BuildInfo.DepLabels
deps := depLabels.Deps deps := depLabels.Deps
deps.Append(depLabels.StaticDeps) deps.Append(depLabels.StaticDeps)
props := bazel.BazelTargetModuleProperties{
Rule_class: "android_binary",
Bzl_load_location: "//build/bazel/rules/android:android_binary.bzl",
}
if !bp2BuildInfo.hasKotlin { if !bp2BuildInfo.hasKotlin {
appAttrs.javaCommonAttributes = commonAttrs appAttrs.javaCommonAttributes = commonAttrs
appAttrs.bazelAapt = aapt appAttrs.bazelAapt = aapt
@@ -1743,10 +1741,31 @@ func (a *AndroidApp) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
} }
} }
ctx.CreateBazelTargetModule( return true, android.CommonAttributes{Name: a.Name(), SkipData: proptools.BoolPtr(true)}, appAttrs
props, }
android.CommonAttributes{Name: a.Name(), SkipData: proptools.BoolPtr(true)},
appAttrs, // ConvertWithBp2build is used to convert android_app to Bazel.
) func (a *AndroidApp) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
if ok, commonAttrs, appAttrs := convertWithBp2build(ctx, a); ok {
props := bazel.BazelTargetModuleProperties{
Rule_class: "android_binary",
Bzl_load_location: "//build/bazel/rules/android:android_binary.bzl",
}
ctx.CreateBazelTargetModule(props, commonAttrs, appAttrs)
}
}
// ConvertWithBp2build is used to convert android_test to Bazel.
func (at *AndroidTest) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
if ok, commonAttrs, appAttrs := convertWithBp2build(ctx, &at.AndroidApp); ok {
props := bazel.BazelTargetModuleProperties{
Rule_class: "android_test",
Bzl_load_location: "//build/bazel/rules/android:android_test.bzl",
}
ctx.CreateBazelTargetModule(props, commonAttrs, appAttrs)
}
} }