Merge changes from topic "bazel_module_labels" into main
* changes: Set Bazel_module for (un)converted sysprop libs Make ShouldConvertWithBp2build avail in loadhooks
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"android/soong/ui/metrics/bp2build_metrics_proto"
|
"android/soong/ui/metrics/bp2build_metrics_proto"
|
||||||
|
|
||||||
"github.com/google/blueprint"
|
"github.com/google/blueprint"
|
||||||
"github.com/google/blueprint/bootstrap"
|
"github.com/google/blueprint/bootstrap"
|
||||||
"github.com/google/blueprint/proptools"
|
"github.com/google/blueprint/proptools"
|
||||||
@@ -153,8 +154,8 @@ type Bazelable interface {
|
|||||||
HasHandcraftedLabel() bool
|
HasHandcraftedLabel() bool
|
||||||
HandcraftedLabel() string
|
HandcraftedLabel() string
|
||||||
GetBazelLabel(ctx BazelConversionPathContext, module blueprint.Module) string
|
GetBazelLabel(ctx BazelConversionPathContext, module blueprint.Module) string
|
||||||
ShouldConvertWithBp2build(ctx BazelConversionContext) bool
|
ShouldConvertWithBp2build(ctx ShouldConvertWithBazelContext) bool
|
||||||
shouldConvertWithBp2build(ctx bazelOtherModuleContext, module blueprint.Module) bool
|
shouldConvertWithBp2build(shouldConvertModuleContext, shouldConvertParams) bool
|
||||||
|
|
||||||
// ConvertWithBp2build either converts the module to a Bazel build target or
|
// ConvertWithBp2build either converts the module to a Bazel build target or
|
||||||
// declares the module as unconvertible (for logging and metrics).
|
// declares the module as unconvertible (for logging and metrics).
|
||||||
@@ -448,12 +449,32 @@ func convertedToBazel(ctx BazelConversionContext, module blueprint.Module) bool
|
|||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return b.shouldConvertWithBp2build(ctx, module) || b.HasHandcraftedLabel()
|
|
||||||
|
return b.HasHandcraftedLabel() || b.shouldConvertWithBp2build(ctx, shouldConvertParams{
|
||||||
|
module: module,
|
||||||
|
moduleDir: ctx.OtherModuleDir(module),
|
||||||
|
moduleName: ctx.OtherModuleName(module),
|
||||||
|
moduleType: ctx.OtherModuleType(module),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
type ShouldConvertWithBazelContext interface {
|
||||||
|
ModuleErrorf(format string, args ...interface{})
|
||||||
|
Module() Module
|
||||||
|
Config() Config
|
||||||
|
ModuleType() string
|
||||||
|
ModuleName() string
|
||||||
|
ModuleDir() string
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShouldConvertWithBp2build returns whether the given BazelModuleBase should be converted with bp2build
|
// ShouldConvertWithBp2build returns whether the given BazelModuleBase should be converted with bp2build
|
||||||
func (b *BazelModuleBase) ShouldConvertWithBp2build(ctx BazelConversionContext) bool {
|
func (b *BazelModuleBase) ShouldConvertWithBp2build(ctx ShouldConvertWithBazelContext) bool {
|
||||||
return b.shouldConvertWithBp2build(ctx, ctx.Module())
|
return b.shouldConvertWithBp2build(ctx, shouldConvertParams{
|
||||||
|
module: ctx.Module(),
|
||||||
|
moduleDir: ctx.ModuleDir(),
|
||||||
|
moduleName: ctx.ModuleName(),
|
||||||
|
moduleType: ctx.ModuleType(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type bazelOtherModuleContext interface {
|
type bazelOtherModuleContext interface {
|
||||||
@@ -471,11 +492,24 @@ func isPlatformIncompatible(osType OsType, arch ArchType) bool {
|
|||||||
arch == Riscv64 // TODO(b/262192655) Riscv64 toolchains are not currently supported.
|
arch == Riscv64 // TODO(b/262192655) Riscv64 toolchains are not currently supported.
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BazelModuleBase) shouldConvertWithBp2build(ctx bazelOtherModuleContext, module blueprint.Module) bool {
|
type shouldConvertModuleContext interface {
|
||||||
|
ModuleErrorf(format string, args ...interface{})
|
||||||
|
Config() Config
|
||||||
|
}
|
||||||
|
|
||||||
|
type shouldConvertParams struct {
|
||||||
|
module blueprint.Module
|
||||||
|
moduleType string
|
||||||
|
moduleDir string
|
||||||
|
moduleName string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BazelModuleBase) shouldConvertWithBp2build(ctx shouldConvertModuleContext, p shouldConvertParams) bool {
|
||||||
if !b.bazelProps().Bazel_module.CanConvertToBazel {
|
if !b.bazelProps().Bazel_module.CanConvertToBazel {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module := p.module
|
||||||
// In api_bp2build mode, all soong modules that can provide API contributions should be converted
|
// In api_bp2build mode, all soong modules that can provide API contributions should be converted
|
||||||
// This is irrespective of its presence/absence in bp2build allowlists
|
// This is irrespective of its presence/absence in bp2build allowlists
|
||||||
if ctx.Config().BuildMode == ApiBp2build {
|
if ctx.Config().BuildMode == ApiBp2build {
|
||||||
@@ -484,7 +518,7 @@ func (b *BazelModuleBase) shouldConvertWithBp2build(ctx bazelOtherModuleContext,
|
|||||||
}
|
}
|
||||||
|
|
||||||
propValue := b.bazelProperties.Bazel_module.Bp2build_available
|
propValue := b.bazelProperties.Bazel_module.Bp2build_available
|
||||||
packagePath := moduleDirWithPossibleOverride(ctx, module)
|
packagePath := moduleDirWithPossibleOverride(ctx, module, p.moduleDir)
|
||||||
|
|
||||||
// Modules in unit tests which are enabled in the allowlist by type or name
|
// Modules in unit tests which are enabled in the allowlist by type or name
|
||||||
// trigger this conditional because unit tests run under the "." package path
|
// trigger this conditional because unit tests run under the "." package path
|
||||||
@@ -493,10 +527,10 @@ func (b *BazelModuleBase) shouldConvertWithBp2build(ctx bazelOtherModuleContext,
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
moduleName := moduleNameWithPossibleOverride(ctx, module)
|
moduleName := moduleNameWithPossibleOverride(ctx, module, p.moduleName)
|
||||||
allowlist := ctx.Config().Bp2buildPackageConfig
|
allowlist := ctx.Config().Bp2buildPackageConfig
|
||||||
moduleNameAllowed := allowlist.moduleAlwaysConvert[moduleName]
|
moduleNameAllowed := allowlist.moduleAlwaysConvert[moduleName]
|
||||||
moduleTypeAllowed := allowlist.moduleTypeAlwaysConvert[ctx.OtherModuleType(module)]
|
moduleTypeAllowed := allowlist.moduleTypeAlwaysConvert[p.moduleType]
|
||||||
allowlistConvert := moduleNameAllowed || moduleTypeAllowed
|
allowlistConvert := moduleNameAllowed || moduleTypeAllowed
|
||||||
if moduleNameAllowed && moduleTypeAllowed {
|
if moduleNameAllowed && moduleTypeAllowed {
|
||||||
ctx.ModuleErrorf("A module cannot be in moduleAlwaysConvert and also be in moduleTypeAlwaysConvert")
|
ctx.ModuleErrorf("A module cannot be in moduleAlwaysConvert and also be in moduleTypeAlwaysConvert")
|
||||||
@@ -588,8 +622,21 @@ func bp2buildConversionMutator(ctx TopDownMutatorContext) {
|
|||||||
ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_TYPE_UNSUPPORTED, "")
|
ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_TYPE_UNSUPPORTED, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// There may be cases where the target is created by a macro rather than in a BUILD file, those
|
||||||
|
// should be captured as well.
|
||||||
|
if bModule.HasHandcraftedLabel() {
|
||||||
|
// Defer to the BUILD target. Generating an additional target would
|
||||||
|
// cause a BUILD file conflict.
|
||||||
|
ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_DEFINED_IN_BUILD_FILE, "")
|
||||||
|
return
|
||||||
|
}
|
||||||
// TODO: b/285631638 - Differentiate between denylisted modules and missing bp2build capabilities.
|
// TODO: b/285631638 - Differentiate between denylisted modules and missing bp2build capabilities.
|
||||||
if !bModule.shouldConvertWithBp2build(ctx, ctx.Module()) {
|
if !bModule.shouldConvertWithBp2build(ctx, shouldConvertParams{
|
||||||
|
module: ctx.Module(),
|
||||||
|
moduleDir: ctx.ModuleDir(),
|
||||||
|
moduleName: ctx.ModuleName(),
|
||||||
|
moduleType: ctx.ModuleType(),
|
||||||
|
}) {
|
||||||
ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_UNSUPPORTED, "")
|
ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_UNSUPPORTED, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@@ -88,6 +88,8 @@ type BazelConversionPathContext interface {
|
|||||||
EarlyModulePathContext
|
EarlyModulePathContext
|
||||||
BazelConversionContext
|
BazelConversionContext
|
||||||
|
|
||||||
|
ModuleName() string
|
||||||
|
ModuleType() string
|
||||||
ModuleErrorf(fmt string, args ...interface{})
|
ModuleErrorf(fmt string, args ...interface{})
|
||||||
PropertyErrorf(property, fmt string, args ...interface{})
|
PropertyErrorf(property, fmt string, args ...interface{})
|
||||||
GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
|
GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
|
||||||
@@ -459,8 +461,8 @@ func samePackage(label1, label2 string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func bp2buildModuleLabel(ctx BazelConversionContext, module blueprint.Module) string {
|
func bp2buildModuleLabel(ctx BazelConversionContext, module blueprint.Module) string {
|
||||||
moduleName := moduleNameWithPossibleOverride(ctx, module)
|
moduleName := moduleNameWithPossibleOverride(ctx, module, ctx.OtherModuleName(module))
|
||||||
moduleDir := moduleDirWithPossibleOverride(ctx, module)
|
moduleDir := moduleDirWithPossibleOverride(ctx, module, ctx.OtherModuleDir(module))
|
||||||
if moduleDir == Bp2BuildTopLevel {
|
if moduleDir == Bp2BuildTopLevel {
|
||||||
moduleDir = ""
|
moduleDir = ""
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"android/soong/bazel"
|
"android/soong/bazel"
|
||||||
|
|
||||||
"github.com/google/blueprint"
|
"github.com/google/blueprint"
|
||||||
"github.com/google/blueprint/pathtools"
|
"github.com/google/blueprint/pathtools"
|
||||||
)
|
)
|
||||||
@@ -157,6 +158,14 @@ func (ctx *TestBazelConversionPathContext) ModuleDir() string {
|
|||||||
return ctx.moduleDir
|
return ctx.moduleDir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ctx *TestBazelConversionPathContext) ModuleName() string {
|
||||||
|
panic("Unimplemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ctx *TestBazelConversionPathContext) ModuleType() string {
|
||||||
|
panic("Unimplemented")
|
||||||
|
}
|
||||||
|
|
||||||
func TestTransformSubpackagePath(t *testing.T) {
|
func TestTransformSubpackagePath(t *testing.T) {
|
||||||
cfg := NullConfig("out", "out/soong")
|
cfg := NullConfig("out", "out/soong")
|
||||||
cfg.fs = pathtools.MockFs(map[string][]byte{
|
cfg.fs = pathtools.MockFs(map[string][]byte{
|
||||||
|
@@ -373,7 +373,14 @@ func TestBp2BuildAllowlist(t *testing.T) {
|
|||||||
allowlist: test.allowlist,
|
allowlist: test.allowlist,
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldConvert := test.module.shouldConvertWithBp2build(bcc, test.module.TestModuleInfo)
|
shouldConvert := test.module.shouldConvertWithBp2build(bcc,
|
||||||
|
shouldConvertParams{
|
||||||
|
module: test.module.TestModuleInfo,
|
||||||
|
moduleDir: test.module.TestModuleInfo.Dir,
|
||||||
|
moduleType: test.module.TestModuleInfo.Typ,
|
||||||
|
moduleName: test.module.TestModuleInfo.ModuleName,
|
||||||
|
},
|
||||||
|
)
|
||||||
if test.shouldConvert != shouldConvert {
|
if test.shouldConvert != shouldConvert {
|
||||||
t.Errorf("Module shouldConvert expected to be: %v, but was: %v", test.shouldConvert, shouldConvert)
|
t.Errorf("Module shouldConvert expected to be: %v, but was: %v", test.shouldConvert, shouldConvert)
|
||||||
}
|
}
|
||||||
|
@@ -353,26 +353,26 @@ func replaceDepsOnOverridingModuleMutator(ctx BottomUpMutatorContext) {
|
|||||||
// variant of this OverridableModule, or ctx.ModuleName() if this module is not an OverridableModule
|
// variant of this OverridableModule, or ctx.ModuleName() if this module is not an OverridableModule
|
||||||
// or if this variant is not overridden.
|
// or if this variant is not overridden.
|
||||||
func ModuleNameWithPossibleOverride(ctx BazelConversionContext) string {
|
func ModuleNameWithPossibleOverride(ctx BazelConversionContext) string {
|
||||||
return moduleNameWithPossibleOverride(ctx, ctx.Module())
|
return moduleNameWithPossibleOverride(ctx, ctx.Module(), ctx.OtherModuleName(ctx.Module()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func moduleNameWithPossibleOverride(ctx bazelOtherModuleContext, module blueprint.Module) string {
|
func moduleNameWithPossibleOverride(ctx shouldConvertModuleContext, module blueprint.Module, name string) string {
|
||||||
if overridable, ok := module.(OverridableModule); ok {
|
if overridable, ok := module.(OverridableModule); ok {
|
||||||
if o := overridable.GetOverriddenBy(); o != "" {
|
if o := overridable.GetOverriddenBy(); o != "" {
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ctx.OtherModuleName(module)
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
// moduleDirWithPossibleOverride returns the dir of the OverrideModule that overrides the current
|
// moduleDirWithPossibleOverride returns the dir of the OverrideModule that overrides the current
|
||||||
// variant of the given OverridableModule, or ctx.OtherModuleName() if the module is not an
|
// variant of the given OverridableModule, or ctx.OtherModuleName() if the module is not an
|
||||||
// OverridableModule or if the variant is not overridden.
|
// OverridableModule or if the variant is not overridden.
|
||||||
func moduleDirWithPossibleOverride(ctx bazelOtherModuleContext, module blueprint.Module) string {
|
func moduleDirWithPossibleOverride(ctx shouldConvertModuleContext, module blueprint.Module, dir string) string {
|
||||||
if overridable, ok := module.(OverridableModule); ok {
|
if overridable, ok := module.(OverridableModule); ok {
|
||||||
if o := overridable.GetOverriddenByModuleDir(); o != "" {
|
if o := overridable.GetOverriddenByModuleDir(); o != "" {
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ctx.OtherModuleDir(module)
|
return dir
|
||||||
}
|
}
|
||||||
|
@@ -686,6 +686,9 @@ func GenerateBazelTargets(ctx *CodegenContext, generateFilegroups bool) (convers
|
|||||||
//
|
//
|
||||||
// bp2build converters are used for the majority of modules.
|
// bp2build converters are used for the majority of modules.
|
||||||
if b, ok := m.(android.Bazelable); ok && b.HasHandcraftedLabel() {
|
if b, ok := m.(android.Bazelable); ok && b.HasHandcraftedLabel() {
|
||||||
|
if aModule, ok := m.(android.Module); ok && aModule.IsConvertedByBp2build() {
|
||||||
|
panic(fmt.Errorf("module %q [%s] [%s] was both converted with bp2build and has a handcrafted label", bpCtx.ModuleName(m), moduleType, dir))
|
||||||
|
}
|
||||||
// Handle modules converted to handcrafted targets.
|
// Handle modules converted to handcrafted targets.
|
||||||
//
|
//
|
||||||
// Since these modules are associated with some handcrafted
|
// Since these modules are associated with some handcrafted
|
||||||
|
@@ -24,6 +24,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"android/soong/bazel"
|
"android/soong/bazel"
|
||||||
|
|
||||||
"github.com/google/blueprint"
|
"github.com/google/blueprint"
|
||||||
"github.com/google/blueprint/proptools"
|
"github.com/google/blueprint/proptools"
|
||||||
|
|
||||||
@@ -410,7 +411,7 @@ type ccLibraryProperties struct {
|
|||||||
Apex_available []string
|
Apex_available []string
|
||||||
Min_sdk_version *string
|
Min_sdk_version *string
|
||||||
Bazel_module struct {
|
Bazel_module struct {
|
||||||
Bp2build_available *bool
|
Label *string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,6 +429,9 @@ type javaLibraryProperties struct {
|
|||||||
SyspropPublicStub string
|
SyspropPublicStub string
|
||||||
Apex_available []string
|
Apex_available []string
|
||||||
Min_sdk_version *string
|
Min_sdk_version *string
|
||||||
|
Bazel_module struct {
|
||||||
|
Bp2build_available *bool
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
|
func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
|
||||||
@@ -473,6 +477,14 @@ func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
|
|||||||
"Unknown value %s: must be one of Platform, Vendor or Odm", m.Owner())
|
"Unknown value %s: must be one of Platform, Vendor or Odm", m.Owner())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var label *string
|
||||||
|
if b, ok := ctx.Module().(android.Bazelable); ok && b.ShouldConvertWithBp2build(ctx) {
|
||||||
|
// TODO: b/295566168 - this will need to change once build files are checked in to account for
|
||||||
|
// checked in modules in mixed builds
|
||||||
|
label = proptools.StringPtr(
|
||||||
|
fmt.Sprintf("//%s:%s", ctx.ModuleDir(), m.CcImplementationModuleName()))
|
||||||
|
}
|
||||||
|
|
||||||
// Generate a C++ implementation library.
|
// Generate a C++ implementation library.
|
||||||
// cc_library can receive *.sysprop files as their srcs, generating sources itself.
|
// cc_library can receive *.sysprop files as their srcs, generating sources itself.
|
||||||
ccProps := ccLibraryProperties{}
|
ccProps := ccLibraryProperties{}
|
||||||
@@ -492,11 +504,7 @@ func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
|
|||||||
ccProps.Host_supported = m.properties.Host_supported
|
ccProps.Host_supported = m.properties.Host_supported
|
||||||
ccProps.Apex_available = m.ApexProperties.Apex_available
|
ccProps.Apex_available = m.ApexProperties.Apex_available
|
||||||
ccProps.Min_sdk_version = m.properties.Cpp.Min_sdk_version
|
ccProps.Min_sdk_version = m.properties.Cpp.Min_sdk_version
|
||||||
// A Bazel macro handles this, so this module does not need to be handled
|
ccProps.Bazel_module.Label = label
|
||||||
// in bp2build
|
|
||||||
// TODO(b/237810289) perhaps do something different here so that we aren't
|
|
||||||
// also disabling these modules in mixed builds
|
|
||||||
ccProps.Bazel_module.Bp2build_available = proptools.BoolPtr(false)
|
|
||||||
ctx.CreateModule(cc.LibraryFactory, &ccProps)
|
ctx.CreateModule(cc.LibraryFactory, &ccProps)
|
||||||
|
|
||||||
scope := "internal"
|
scope := "internal"
|
||||||
@@ -541,6 +549,11 @@ func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
|
|||||||
SyspropPublicStub: publicStub,
|
SyspropPublicStub: publicStub,
|
||||||
Apex_available: m.ApexProperties.Apex_available,
|
Apex_available: m.ApexProperties.Apex_available,
|
||||||
Min_sdk_version: m.properties.Java.Min_sdk_version,
|
Min_sdk_version: m.properties.Java.Min_sdk_version,
|
||||||
|
Bazel_module: struct {
|
||||||
|
Bp2build_available *bool
|
||||||
|
}{
|
||||||
|
Bp2build_available: proptools.BoolPtr(false),
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
if publicStub != "" {
|
if publicStub != "" {
|
||||||
@@ -558,6 +571,11 @@ func syspropLibraryHook(ctx android.LoadHookContext, m *syspropLibrary) {
|
|||||||
Sdk_version: proptools.StringPtr("core_current"),
|
Sdk_version: proptools.StringPtr("core_current"),
|
||||||
Libs: []string{javaSyspropStub},
|
Libs: []string{javaSyspropStub},
|
||||||
Stem: proptools.StringPtr(m.BaseModuleName()),
|
Stem: proptools.StringPtr(m.BaseModuleName()),
|
||||||
|
Bazel_module: struct {
|
||||||
|
Bp2build_available *bool
|
||||||
|
}{
|
||||||
|
Bp2build_available: proptools.BoolPtr(false),
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user