support aidl bp2build changes

- Allowlist an aidl module by package, not name (to support a small
  module name change)
- Implement some unit test framework changes which facilitate better
  aidl bp2build testing
- Support a convenience function to add a load hook for registering a
  module as "has a bazel definition of a given target name"

Bug: 301676937
Test: m bp2build, verified the aidl target was generated before/after
this CL.
Test: Presubmits
Test: Ran bp2build progress and ensured that aidl_interface targets
under frameworks/ continued to appear converted

Change-Id: I62412057d6f61a2ce2bc39488c75af793eb14c94
This commit is contained in:
Chris Parsons
2023-09-25 19:01:40 +00:00
parent ffb9a2af93
commit 2173b5f578
3 changed files with 63 additions and 4 deletions

View File

@@ -218,6 +218,28 @@ func InitBazelModule(module BazelModule) {
module.bazelProps().Bazel_module.CanConvertToBazel = true
}
// BazelHandcraftedHook is a load hook to possibly register the current module as
// a "handcrafted" Bazel target of a given name. If the current module should be
// registered in this way, the hook function should return the target name. If
// it should not be registered in this way, this function should return the empty string.
type BazelHandcraftedHook func(ctx LoadHookContext) string
// AddBazelHandcraftedHook adds a load hook to (maybe) mark the given module so that
// it is treated by bp2build as if it has a handcrafted Bazel target.
func AddBazelHandcraftedHook(module BazelModule, hook BazelHandcraftedHook) {
AddLoadHook(module, func(ctx LoadHookContext) {
var targetName string = hook(ctx)
if len(targetName) > 0 {
moduleDir := ctx.ModuleDir()
if moduleDir == Bp2BuildTopLevel {
moduleDir = ""
}
label := fmt.Sprintf("//%s:%s", moduleDir, targetName)
module.bazelProps().Bazel_module.Label = &label
}
})
}
// bazelProps returns the Bazel properties for the given BazelModuleBase.
func (b *BazelModuleBase) bazelProps() *properties {
return &b.bazelProperties