summaryrefslogtreecommitdiff
path: root/android/bazel.go
diff options
context:
space:
mode:
Diffstat (limited to 'android/bazel.go')
-rw-r--r--android/bazel.go63
1 files changed, 50 insertions, 13 deletions
diff --git a/android/bazel.go b/android/bazel.go
index 4ef8d7881..40f2917db 100644
--- a/android/bazel.go
+++ b/android/bazel.go
@@ -115,6 +115,27 @@ type Bazelable interface {
SetBaseModuleType(baseModuleType string)
}
+// MixedBuildBuildable is an interface that module types should implement in order
+// to be "handled by Bazel" in a mixed build.
+type MixedBuildBuildable interface {
+ // IsMixedBuildSupported returns true if and only if this module should be
+ // "handled by Bazel" in a mixed build.
+ // This "escape hatch" allows modules with corner-case scenarios to opt out
+ // of being built with Bazel.
+ IsMixedBuildSupported(ctx BaseModuleContext) bool
+
+ // QueueBazelCall invokes request-queueing functions on the BazelContext
+ // so that these requests are handled when Bazel's cquery is invoked.
+ QueueBazelCall(ctx BaseModuleContext)
+
+ // ProcessBazelQueryResponse uses Bazel information (obtained from the BazelContext)
+ // to set module fields and providers to propagate this module's metadata upstream.
+ // This effectively "bridges the gap" between Bazel and Soong in a mixed build.
+ // Soong modules depending on this module should be oblivious to the fact that
+ // this module was handled by Bazel.
+ ProcessBazelQueryResponse(ctx ModuleContext)
+}
+
// BazelModule is a lightweight wrapper interface around Module for Bazel-convertible modules.
type BazelModule interface {
Module
@@ -300,25 +321,31 @@ func (a bp2BuildConversionAllowlist) SetMixedBuildsDisabledList(mixedBuildsDisab
return a
}
-var bp2buildAllowlist = NewBp2BuildAllowlist().
- SetDefaultConfig(allowlists.Bp2buildDefaultConfig).
- SetKeepExistingBuildFile(allowlists.Bp2buildKeepExistingBuildFile).
- SetModuleAlwaysConvertList(allowlists.Bp2buildModuleAlwaysConvertList).
- SetModuleTypeAlwaysConvertList(allowlists.Bp2buildModuleTypeAlwaysConvertList).
- SetModuleDoNotConvertList(allowlists.Bp2buildModuleDoNotConvertList).
- SetCcLibraryStaticOnlyList(allowlists.Bp2buildCcLibraryStaticOnlyList).
- SetMixedBuildsDisabledList(allowlists.MixedBuildsDisabledList)
+var bp2BuildAllowListKey = NewOnceKey("Bp2BuildAllowlist")
+var bp2buildAllowlist OncePer
+
+func getBp2BuildAllowList() bp2BuildConversionAllowlist {
+ return bp2buildAllowlist.Once(bp2BuildAllowListKey, func() interface{} {
+ return NewBp2BuildAllowlist().SetDefaultConfig(allowlists.Bp2buildDefaultConfig).
+ SetKeepExistingBuildFile(allowlists.Bp2buildKeepExistingBuildFile).
+ SetModuleAlwaysConvertList(allowlists.Bp2buildModuleAlwaysConvertList).
+ SetModuleTypeAlwaysConvertList(allowlists.Bp2buildModuleTypeAlwaysConvertList).
+ SetModuleDoNotConvertList(allowlists.Bp2buildModuleDoNotConvertList).
+ SetCcLibraryStaticOnlyList(allowlists.Bp2buildCcLibraryStaticOnlyList).
+ SetMixedBuildsDisabledList(allowlists.MixedBuildsDisabledList)
+ }).(bp2BuildConversionAllowlist)
+}
// GenerateCcLibraryStaticOnly returns whether a cc_library module should only
// generate a static version of itself based on the current global configuration.
func GenerateCcLibraryStaticOnly(moduleName string) bool {
- return bp2buildAllowlist.ccLibraryStaticOnly[moduleName]
+ return getBp2BuildAllowList().ccLibraryStaticOnly[moduleName]
}
// ShouldKeepExistingBuildFileForDir returns whether an existing BUILD file should be
// added to the build symlink forest based on the current global configuration.
func ShouldKeepExistingBuildFileForDir(dir string) bool {
- return shouldKeepExistingBuildFileForDir(bp2buildAllowlist, dir)
+ return shouldKeepExistingBuildFileForDir(getBp2BuildAllowList(), dir)
}
func shouldKeepExistingBuildFileForDir(allowlist bp2BuildConversionAllowlist, dir string) bool {
@@ -338,9 +365,19 @@ func shouldKeepExistingBuildFileForDir(allowlist bp2BuildConversionAllowlist, di
return false
}
-// MixedBuildsEnabled checks that a module is ready to be replaced by a
+// MixedBuildsEnabled returns true if a module is ready to be replaced by a
+// converted or handcrafted Bazel target. As a side effect, calling this
+// method will also log whether this module is mixed build enabled for
+// metrics reporting.
+func MixedBuildsEnabled(ctx BaseModuleContext) bool {
+ mixedBuildEnabled := mixedBuildPossible(ctx)
+ ctx.Config().LogMixedBuild(ctx, mixedBuildEnabled)
+ return mixedBuildEnabled
+}
+
+// mixedBuildPossible returns true if a module is ready to be replaced by a
// converted or handcrafted Bazel target.
-func (b *BazelModuleBase) MixedBuildsEnabled(ctx ModuleContext) bool {
+func mixedBuildPossible(ctx BaseModuleContext) bool {
if ctx.Os() == Windows {
// Windows toolchains are not currently supported.
return false
@@ -361,7 +398,7 @@ func (b *BazelModuleBase) MixedBuildsEnabled(ctx ModuleContext) bool {
// variants of a cc_library.
return false
}
- return !bp2buildAllowlist.mixedBuildsDisabled[ctx.Module().Name()]
+ return !getBp2BuildAllowList().mixedBuildsDisabled[ctx.Module().Name()]
}
// ConvertedToBazel returns whether this module has been converted (with bp2build or manually) to Bazel.