mixed builds: add cc_test bazel handler, and add adbd_test to staging allowlist.

This will allow the test_suites_{arm64, x86_64} CI targets on
git_master-bazel to build adbd_test with bazel in `m`.

This is currently implemented similar to the cc_binary handler to
hydrate the output path field.

The tradefed config is still currently handled by Soong in
testBinary#install, which is called from both ProcessBazelQueryResponse
and GenerateAndroidBuildActions. We'll move the tradefed config path to
a mixed builds handler when it's ready on the cc_test bazel rule side.

Tested with `atest` with cuttlefish. Since `atest` doesn't have a way to pass
--bazel-mode-staging to its internal call to Soong, so I manually tested
this by adding adbt_test to the prod allowlist, and confirmed that the
installed adbd_test is the same binary as the one in bazel-out.

Test: $ showcommands adbd_test | grep bazel-out | tail -n1

```
/bin/bash -c "rm -f
out/target/product/vsoc_x86_64/data/nativetest64/adbd_test/adbd_test &&
cp -f -d
out/bazel/output/execroot/__main__/bazel-out/android_x86_64_silvermont-opt-ST-59d4124ca041/bin/packages/modules/adb/adbd_test
out/target/product/vsoc_x86_64/data/nativetest64/adbd_test/adbd_test"
```

Test: Add adbd_test to prod allowlist and run 'lunch aosp_cf_x86_64_phone-userdebug; atest adbd_test', all tests pass.
Bug: 258426425
Bug: 261692372
Change-Id: I6be329f39d607af8daa1dc772b23e8dd0247418c
This commit is contained in:
Jingwen Chen
2022-12-12 12:20:58 +00:00
parent 328770db88
commit 3952a9039e
5 changed files with 56 additions and 5 deletions

View File

@@ -1367,5 +1367,6 @@ var (
// also be built - do not add them to this list.
StagingMixedBuildsEnabledList = []string{
"com.android.adbd",
"adbd_test",
}
)

View File

@@ -645,10 +645,12 @@ load(":main.bzl", "config_node", "mixed_build_root", "phony_root")
mixed_build_root(name = "buildroot",
deps = [%s],
testonly = True, # Unblocks testonly deps.
)
phony_root(name = "phonyroot",
deps = [":buildroot"],
testonly = True, # Unblocks testonly deps.
)
`
configNodeFormatString := `
@@ -656,6 +658,7 @@ config_node(name = "%s",
arch = "%s",
os = "%s",
deps = [%s],
testonly = True, # Unblocks testonly deps.
)
`

View File

@@ -11,7 +11,7 @@ var (
GetPythonBinary = &getPythonBinaryRequestType{}
GetCcInfo = &getCcInfoType{}
GetApexInfo = &getApexInfoType{}
GetCcUnstrippedInfo = &getCcUnstippedInfoType{}
GetCcUnstrippedInfo = &getCcUnstrippedInfoType{}
)
type CcInfo struct {
@@ -275,13 +275,13 @@ func (g getApexInfoType) ParseResult(rawString string) (ApexInfo, error) {
// getCcUnstrippedInfoType implements cqueryRequest interface. It handles the
// interaction with `bazel cquery` to retrieve CcUnstrippedInfo provided
// by the` cc_binary` and `cc_shared_library` rules.
type getCcUnstippedInfoType struct{}
type getCcUnstrippedInfoType struct{}
func (g getCcUnstippedInfoType) Name() string {
func (g getCcUnstrippedInfoType) Name() string {
return "getCcUnstrippedInfo"
}
func (g getCcUnstippedInfoType) StarlarkFunctionBody() string {
func (g getCcUnstrippedInfoType) StarlarkFunctionBody() string {
return `unstripped_tag = "//build/bazel/rules/cc:stripped_cc_common.bzl%CcUnstrippedInfo"
p = providers(target)
output_path = target.files.to_list()[0].path
@@ -298,7 +298,7 @@ return json_encode({
// ParseResult returns a value obtained by parsing the result of the request's Starlark function.
// The given rawString must correspond to the string output which was created by evaluating the
// Starlark given in StarlarkFunctionBody.
func (g getCcUnstippedInfoType) ParseResult(rawString string) (CcUnstrippedInfo, error) {
func (g getCcUnstrippedInfoType) ParseResult(rawString string) (CcUnstrippedInfo, error) {
var info CcUnstrippedInfo
err := parseJson(rawString, &info)
return info, err

View File

@@ -1858,7 +1858,22 @@ func (c *Module) QueueBazelCall(ctx android.BaseModuleContext) {
c.bazelHandler.QueueBazelCall(ctx, c.getBazelModuleLabel(ctx))
}
var (
mixedBuildSupportedCcTest = []string{
"adbd_test",
}
)
// IsMixedBuildSupported returns true if the module should be analyzed by Bazel
// in any of the --bazel-mode(s). This filters at the module level and takes
// precedence over the allowlists in allowlists/allowlists.go.
func (c *Module) IsMixedBuildSupported(ctx android.BaseModuleContext) bool {
if c.testBinary() && !android.InList(c.Name(), mixedBuildSupportedCcTest) {
// Per-module rollout of mixed-builds for cc_test modules.
return false
}
// Enable mixed builds as long as the cc_* module type has a bazel handler.
return c.bazelHandler != nil
}
@@ -1888,6 +1903,8 @@ func (c *Module) ProcessBazelQueryResponse(ctx android.ModuleContext) {
}
mctx.ctx = mctx
// TODO(b/244432500): Get the tradefed config from the bazel target instead
// of generating it with Soong.
c.maybeInstall(mctx, apexInfo)
}
@@ -2038,6 +2055,9 @@ func (c *Module) maybeUnhideFromMake() {
}
}
// maybeInstall is called at the end of both GenerateAndroidBuildActions and
// ProcessBazelQueryResponse to run the install hooks for installable modules,
// like binaries and tests.
func (c *Module) maybeInstall(ctx ModuleContext, apexInfo android.ApexInfo) {
if !proptools.BoolDefault(c.Installable(), true) {
// If the module has been specifically configure to not be installed then

View File

@@ -23,6 +23,7 @@ import (
"android/soong/android"
"android/soong/bazel"
"android/soong/bazel/cquery"
"android/soong/tradefed"
)
@@ -135,6 +136,7 @@ func init() {
// static_libs dependency on libgtests unless the gtest flag is set to false.
func TestFactory() android.Module {
module := NewTest(android.HostAndDeviceSupported, true)
module.bazelHandler = &ccTestBazelHandler{module: module}
return module.Init()
}
@@ -481,6 +483,7 @@ func (test *testBinary) install(ctx ModuleContext, file android.Path) {
func NewTest(hod android.HostOrDeviceSupported, bazelable bool) *Module {
module, binary := newBinary(hod, bazelable)
module.bazelable = bazelable
module.multilib = android.MultilibBoth
binary.baseInstaller = NewTestInstaller()
@@ -637,6 +640,30 @@ func NewBenchmark(hod android.HostOrDeviceSupported) *Module {
return module
}
type ccTestBazelHandler struct {
module *Module
}
var _ BazelHandler = (*ccTestBazelHandler)(nil)
func (handler *ccTestBazelHandler) QueueBazelCall(ctx android.BaseModuleContext, label string) {
bazelCtx := ctx.Config().BazelContext
bazelCtx.QueueBazelRequest(label, cquery.GetCcUnstrippedInfo, android.GetConfigKey(ctx))
}
func (handler *ccTestBazelHandler) ProcessBazelQueryResponse(ctx android.ModuleContext, label string) {
bazelCtx := ctx.Config().BazelContext
info, err := bazelCtx.GetCcUnstrippedInfo(label, android.GetConfigKey(ctx))
if err != nil {
ctx.ModuleErrorf(err.Error())
return
}
outputFilePath := android.PathForBazelOut(ctx, info.OutputFile)
handler.module.outputFile = android.OptionalPathForPath(outputFilePath)
handler.module.linker.(*testBinary).unstrippedOutputFile = android.PathForBazelOut(ctx, info.UnstrippedOutput)
}
// binaryAttributes contains Bazel attributes corresponding to a cc test
type testBinaryAttributes struct {
binaryAttributes