Merge "Support apex_test." am: 2ff53da9f8
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2265965 Change-Id: I13c1017e5c91f83c649933c0cdf33a38c0f225ec Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
99416d29a6
3 changed files with 49 additions and 6 deletions
|
@ -928,6 +928,8 @@ type CommonAttributes struct {
|
|||
Tags bazel.StringListAttribute
|
||||
|
||||
Applicable_licenses bazel.LabelListAttribute
|
||||
|
||||
Testonly *bool
|
||||
}
|
||||
|
||||
// constraintAttributes represents Bazel attributes pertaining to build constraints,
|
||||
|
|
27
apex/apex.go
27
apex/apex.go
|
@ -17,13 +17,14 @@
|
|||
package apex
|
||||
|
||||
import (
|
||||
"android/soong/bazel/cquery"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"android/soong/bazel/cquery"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
"github.com/google/blueprint/bootstrap"
|
||||
"github.com/google/blueprint/proptools"
|
||||
|
@ -47,7 +48,7 @@ func init() {
|
|||
|
||||
func registerApexBuildComponents(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("apex", BundleFactory)
|
||||
ctx.RegisterModuleType("apex_test", testApexBundleFactory)
|
||||
ctx.RegisterModuleType("apex_test", TestApexBundleFactory)
|
||||
ctx.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
|
||||
ctx.RegisterModuleType("apex_defaults", defaultsFactory)
|
||||
ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
|
||||
|
@ -2563,7 +2564,7 @@ func ApexBundleFactory(testApex bool) android.Module {
|
|||
|
||||
// apex_test is an APEX for testing. The difference from the ordinary apex module type is that
|
||||
// certain compatibility checks such as apex_available are not done for apex_test.
|
||||
func testApexBundleFactory() android.Module {
|
||||
func TestApexBundleFactory() android.Module {
|
||||
bundle := newApexBundle()
|
||||
bundle.testApex = true
|
||||
return bundle
|
||||
|
@ -3335,6 +3336,7 @@ type bazelApexBundleAttributes struct {
|
|||
Compressible bazel.BoolAttribute
|
||||
Package_name *string
|
||||
Logging_parent *string
|
||||
Tests bazel.LabelListAttribute
|
||||
}
|
||||
|
||||
type convertedNativeSharedLibs struct {
|
||||
|
@ -3344,13 +3346,19 @@ type convertedNativeSharedLibs struct {
|
|||
|
||||
// ConvertWithBp2build performs bp2build conversion of an apex
|
||||
func (a *apexBundle) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
|
||||
// We do not convert apex_test modules at this time
|
||||
if ctx.ModuleType() != "apex" {
|
||||
// We only convert apex and apex_test modules at this time
|
||||
if ctx.ModuleType() != "apex" && ctx.ModuleType() != "apex_test" {
|
||||
return
|
||||
}
|
||||
|
||||
attrs, props := convertWithBp2build(a, ctx)
|
||||
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: a.Name()}, &attrs)
|
||||
commonAttrs := android.CommonAttributes{
|
||||
Name: a.Name(),
|
||||
}
|
||||
if a.testApex {
|
||||
commonAttrs.Testonly = proptools.BoolPtr(a.testApex)
|
||||
}
|
||||
ctx.CreateBazelTargetModule(props, commonAttrs, &attrs)
|
||||
}
|
||||
|
||||
func convertWithBp2build(a *apexBundle, ctx android.TopDownMutatorContext) (bazelApexBundleAttributes, bazel.BazelTargetModuleProperties) {
|
||||
|
@ -3417,6 +3425,12 @@ func convertWithBp2build(a *apexBundle, ctx android.TopDownMutatorContext) (baze
|
|||
binaries := android.BazelLabelForModuleDeps(ctx, a.properties.ApexNativeDependencies.Binaries)
|
||||
binariesLabelListAttribute := bazel.MakeLabelListAttribute(binaries)
|
||||
|
||||
var testsAttrs bazel.LabelListAttribute
|
||||
if a.testApex && len(a.properties.ApexNativeDependencies.Tests) > 0 {
|
||||
tests := android.BazelLabelForModuleDeps(ctx, a.properties.ApexNativeDependencies.Tests)
|
||||
testsAttrs = bazel.MakeLabelListAttribute(tests)
|
||||
}
|
||||
|
||||
var updatableAttribute bazel.BoolAttribute
|
||||
if a.properties.Updatable != nil {
|
||||
updatableAttribute.Value = a.properties.Updatable
|
||||
|
@ -3459,6 +3473,7 @@ func convertWithBp2build(a *apexBundle, ctx android.TopDownMutatorContext) (baze
|
|||
Compressible: compressibleAttribute,
|
||||
Package_name: packageName,
|
||||
Logging_parent: loggingParent,
|
||||
Tests: testsAttrs,
|
||||
}
|
||||
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
|
|
|
@ -42,6 +42,7 @@ func registerApexModuleTypes(ctx android.RegistrationContext) {
|
|||
ctx.RegisterModuleType("android_app_certificate", java.AndroidAppCertificateFactory)
|
||||
ctx.RegisterModuleType("filegroup", android.FileGroupFactory)
|
||||
ctx.RegisterModuleType("prebuilt_etc", etc.PrebuiltEtcFactory)
|
||||
ctx.RegisterModuleType("cc_test", cc.TestFactory)
|
||||
}
|
||||
|
||||
func runOverrideApexTestCase(t *testing.T, tc Bp2buildTestCase) {
|
||||
|
@ -1249,3 +1250,28 @@ override_apex {
|
|||
}),
|
||||
}})
|
||||
}
|
||||
|
||||
func TestApexTestBundleSimple(t *testing.T) {
|
||||
runApexTestCase(t, Bp2buildTestCase{
|
||||
Description: "apex_test - simple",
|
||||
ModuleTypeUnderTest: "apex_test",
|
||||
ModuleTypeUnderTestFactory: apex.TestApexBundleFactory,
|
||||
Filesystem: map[string]string{},
|
||||
Blueprint: `
|
||||
cc_test { name: "cc_test_1", bazel_module: { bp2build_available: false } }
|
||||
|
||||
apex_test {
|
||||
name: "test_com.android.apogee",
|
||||
file_contexts: "file_contexts_file",
|
||||
tests: ["cc_test_1"],
|
||||
}
|
||||
`,
|
||||
ExpectedBazelTargets: []string{
|
||||
MakeBazelTarget("apex", "test_com.android.apogee", AttrNameToString{
|
||||
"file_contexts": `"file_contexts_file"`,
|
||||
"manifest": `"apex_manifest.json"`,
|
||||
"testonly": `True`,
|
||||
"tests": `[":cc_test_1"]`,
|
||||
}),
|
||||
}})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue