Provide reason for unconverted bp2build modules
This also changes the expectation of ConvertWithBp2build. Each implementation must either create one or more Bazel target modules, or mark the module as unconvertible (with a specific reason). Manually verified no runtime hit in AOSP In AOSP, the metrics file size increases from 252K to 1.6M This changes some effective module counts in bp2build metrics: - Removes "package" modules from the module count list in metrics, as these will not be converted like regular modules. - Counts Handcrafted modules as being "unconverted", as bp2build is not responsible for them. Bug: 285631638 Test: Verified generated BUILD.bazel files are bit-for-bit identical with this change Test: Manually verified one case of each implemented reasonType Change-Id: I308dd451d8f28379b15671dae9f931bd0446f5c1
This commit is contained in:
@@ -30,6 +30,7 @@ import (
|
||||
"text/scanner"
|
||||
|
||||
"android/soong/bazel"
|
||||
"android/soong/ui/metrics/bp2build_metrics_proto"
|
||||
|
||||
"github.com/google/blueprint"
|
||||
"github.com/google/blueprint/proptools"
|
||||
@@ -565,6 +566,8 @@ type Module interface {
|
||||
|
||||
// IsConvertedByBp2build returns whether this module was converted via bp2build
|
||||
IsConvertedByBp2build() bool
|
||||
GetUnconvertedReason() *UnconvertedReason
|
||||
|
||||
// Bp2buildTargets returns the target(s) generated for Bazel via bp2build for this module
|
||||
Bp2buildTargets() []bp2buildInfo
|
||||
GetUnconvertedBp2buildDeps() []string
|
||||
@@ -1591,14 +1594,31 @@ func (b bp2buildInfo) BazelAttributes() []interface{} {
|
||||
}
|
||||
|
||||
func (m *ModuleBase) addBp2buildInfo(info bp2buildInfo) {
|
||||
if m.commonProperties.BazelConversionStatus.UnconvertedReason != nil {
|
||||
panic(fmt.Errorf("bp2build: module '%s' marked unconvertible and also is converted", m.Name()))
|
||||
}
|
||||
m.commonProperties.BazelConversionStatus.Bp2buildInfo = append(m.commonProperties.BazelConversionStatus.Bp2buildInfo, info)
|
||||
}
|
||||
|
||||
func (m *ModuleBase) setBp2buildUnconvertible(reasonType bp2build_metrics_proto.UnconvertedReasonType, detail string) {
|
||||
if len(m.commonProperties.BazelConversionStatus.Bp2buildInfo) > 0 {
|
||||
panic(fmt.Errorf("bp2build: module '%s' marked unconvertible and also is converted", m.Name()))
|
||||
}
|
||||
m.commonProperties.BazelConversionStatus.UnconvertedReason = &UnconvertedReason{
|
||||
ReasonType: int(reasonType),
|
||||
Detail: detail,
|
||||
}
|
||||
}
|
||||
|
||||
// IsConvertedByBp2build returns whether this module was converted via bp2build.
|
||||
func (m *ModuleBase) IsConvertedByBp2build() bool {
|
||||
return len(m.commonProperties.BazelConversionStatus.Bp2buildInfo) > 0
|
||||
}
|
||||
|
||||
func (m *ModuleBase) GetUnconvertedReason() *UnconvertedReason {
|
||||
return m.commonProperties.BazelConversionStatus.UnconvertedReason
|
||||
}
|
||||
|
||||
// Bp2buildTargets returns the Bazel targets bp2build generated for this module.
|
||||
func (m *ModuleBase) Bp2buildTargets() []bp2buildInfo {
|
||||
return m.commonProperties.BazelConversionStatus.Bp2buildInfo
|
||||
|
Reference in New Issue
Block a user