bp2build: split Bazel conversion context into smaller ones,

and change TopDownMutatorContext signatures to use Bazel conversion context.

This minimizes the context interfaces/functions actually needed to
convert a module, and makes such interfaces easier to mock/test.

Test: CI
Change-Id: Id573d97023d59e06ef70e1f54437024d3f7aadbd
This commit is contained in:
Jingwen Chen
2021-11-02 06:40:51 +00:00
parent 80b6b64db5
commit 55bc820d66
4 changed files with 76 additions and 64 deletions

View File

@@ -60,8 +60,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
ConvertWithBp2build(ctx BazelConversionPathContext) bool ConvertWithBp2build(ctx BazelConversionContext) bool
convertWithBp2build(ctx BazelConversionPathContext, module blueprint.Module) bool convertWithBp2build(ctx BazelConversionContext, module blueprint.Module) bool
GetBazelBuildFileContents(c Config, path, name string) (string, error) GetBazelBuildFileContents(c Config, path, name string) (string, error)
} }
@@ -377,7 +377,7 @@ func (b *BazelModuleBase) MixedBuildsEnabled(ctx BazelConversionPathContext) boo
} }
// ConvertedToBazel returns whether this module has been converted (with bp2build or manually) to Bazel. // ConvertedToBazel returns whether this module has been converted (with bp2build or manually) to Bazel.
func convertedToBazel(ctx BazelConversionPathContext, module blueprint.Module) bool { func convertedToBazel(ctx BazelConversionContext, module blueprint.Module) bool {
b, ok := module.(Bazelable) b, ok := module.(Bazelable)
if !ok { if !ok {
return false return false
@@ -386,11 +386,11 @@ func convertedToBazel(ctx BazelConversionPathContext, module blueprint.Module) b
} }
// ConvertWithBp2build returns whether the given BazelModuleBase should be converted with bp2build. // ConvertWithBp2build returns whether the given BazelModuleBase should be converted with bp2build.
func (b *BazelModuleBase) ConvertWithBp2build(ctx BazelConversionPathContext) bool { func (b *BazelModuleBase) ConvertWithBp2build(ctx BazelConversionContext) bool {
return b.convertWithBp2build(ctx, ctx.Module()) return b.convertWithBp2build(ctx, ctx.Module())
} }
func (b *BazelModuleBase) convertWithBp2build(ctx BazelConversionPathContext, module blueprint.Module) bool { func (b *BazelModuleBase) convertWithBp2build(ctx BazelConversionContext, module blueprint.Module) bool {
if bp2buildModuleDoNotConvert[module.Name()] { if bp2buildModuleDoNotConvert[module.Name()] {
return false return false
} }

View File

@@ -68,24 +68,36 @@ import (
// cannot be resolved,the function will panic. This is often due to the dependency not being added // cannot be resolved,the function will panic. This is often due to the dependency not being added
// via an AddDependency* method. // via an AddDependency* method.
// A subset of the ModuleContext methods which are sufficient to resolve references to paths/deps in // A minimal context interface to check if a module should be converted by bp2build,
// order to form a Bazel-compatible label for conversion. // with functions containing information to match against allowlists and denylists.
type BazelConversionPathContext interface { // If a module is deemed to be convertible by bp2build, then it should rely on a
EarlyModulePathContext // BazelConversionPathContext for more functions for dep/path features.
type BazelConversionContext interface {
Config() Config
GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
ModuleFromName(name string) (blueprint.Module, bool)
Module() Module Module() Module
OtherModuleType(m blueprint.Module) string OtherModuleType(m blueprint.Module) string
OtherModuleName(m blueprint.Module) string OtherModuleName(m blueprint.Module) string
OtherModuleDir(m blueprint.Module) string OtherModuleDir(m blueprint.Module) string
}
// A subset of the ModuleContext methods which are sufficient to resolve references to paths/deps in
// order to form a Bazel-compatible label for conversion.
type BazelConversionPathContext interface {
EarlyModulePathContext
BazelConversionContext
ModuleErrorf(fmt string, args ...interface{})
PropertyErrorf(property, fmt string, args ...interface{})
GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag)
ModuleFromName(name string) (blueprint.Module, bool)
AddUnconvertedBp2buildDep(string) AddUnconvertedBp2buildDep(string)
} }
// BazelLabelForModuleDeps expects a list of reference to other modules, ("<module>" // BazelLabelForModuleDeps expects a list of reference to other modules, ("<module>"
// or ":<module>") and returns a Bazel-compatible label which corresponds to dependencies on the // or ":<module>") and returns a Bazel-compatible label which corresponds to dependencies on the
// module within the given ctx. // module within the given ctx.
func BazelLabelForModuleDeps(ctx TopDownMutatorContext, modules []string) bazel.LabelList { func BazelLabelForModuleDeps(ctx BazelConversionPathContext, modules []string) bazel.LabelList {
return BazelLabelForModuleDepsWithFn(ctx, modules, BazelModuleLabel) return BazelLabelForModuleDepsWithFn(ctx, modules, BazelModuleLabel)
} }
@@ -95,15 +107,15 @@ func BazelLabelForModuleDeps(ctx TopDownMutatorContext, modules []string) bazel.
// list which corresponds to dependencies on the module within the given ctx, and the excluded // list which corresponds to dependencies on the module within the given ctx, and the excluded
// dependencies. Prebuilt dependencies will be appended with _alwayslink so they can be handled as // dependencies. Prebuilt dependencies will be appended with _alwayslink so they can be handled as
// whole static libraries. // whole static libraries.
func BazelLabelForModuleDepsExcludes(ctx TopDownMutatorContext, modules, excludes []string) bazel.LabelList { func BazelLabelForModuleDepsExcludes(ctx BazelConversionPathContext, modules, excludes []string) bazel.LabelList {
return BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, BazelModuleLabel) return BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, BazelModuleLabel)
} }
// BazelLabelForModuleDepsWithFn expects a list of reference to other modules, ("<module>" // BazelLabelForModuleDepsWithFn expects a list of reference to other modules, ("<module>"
// or ":<module>") and applies moduleToLabelFn to determine and return a Bazel-compatible label // or ":<module>") and applies moduleToLabelFn to determine and return a Bazel-compatible label
// which corresponds to dependencies on the module within the given ctx. // which corresponds to dependencies on the module within the given ctx.
func BazelLabelForModuleDepsWithFn(ctx TopDownMutatorContext, modules []string, func BazelLabelForModuleDepsWithFn(ctx BazelConversionPathContext, modules []string,
moduleToLabelFn func(TopDownMutatorContext, blueprint.Module) string) bazel.LabelList { moduleToLabelFn func(BazelConversionPathContext, blueprint.Module) string) bazel.LabelList {
var labels bazel.LabelList var labels bazel.LabelList
// In some cases, a nil string list is different than an explicitly empty list. // In some cases, a nil string list is different than an explicitly empty list.
if len(modules) == 0 && modules != nil { if len(modules) == 0 && modules != nil {
@@ -131,8 +143,8 @@ func BazelLabelForModuleDepsWithFn(ctx TopDownMutatorContext, modules []string,
// to other modules, ("<module>" or ":<module>"). It applies moduleToLabelFn to determine and return a // to other modules, ("<module>" or ":<module>"). It applies moduleToLabelFn to determine and return a
// Bazel-compatible label list which corresponds to dependencies on the module within the given ctx, and // Bazel-compatible label list which corresponds to dependencies on the module within the given ctx, and
// the excluded dependencies. // the excluded dependencies.
func BazelLabelForModuleDepsExcludesWithFn(ctx TopDownMutatorContext, modules, excludes []string, func BazelLabelForModuleDepsExcludesWithFn(ctx BazelConversionPathContext, modules, excludes []string,
moduleToLabelFn func(TopDownMutatorContext, blueprint.Module) string) bazel.LabelList { moduleToLabelFn func(BazelConversionPathContext, blueprint.Module) string) bazel.LabelList {
moduleLabels := BazelLabelForModuleDepsWithFn(ctx, RemoveListFromList(modules, excludes), moduleToLabelFn) moduleLabels := BazelLabelForModuleDepsWithFn(ctx, RemoveListFromList(modules, excludes), moduleToLabelFn)
if len(excludes) == 0 { if len(excludes) == 0 {
return moduleLabels return moduleLabels
@@ -144,11 +156,11 @@ func BazelLabelForModuleDepsExcludesWithFn(ctx TopDownMutatorContext, modules, e
} }
} }
func BazelLabelForModuleSrcSingle(ctx TopDownMutatorContext, path string) bazel.Label { func BazelLabelForModuleSrcSingle(ctx BazelConversionPathContext, path string) bazel.Label {
return BazelLabelForModuleSrcExcludes(ctx, []string{path}, []string(nil)).Includes[0] return BazelLabelForModuleSrcExcludes(ctx, []string{path}, []string(nil)).Includes[0]
} }
func BazelLabelForModuleDepSingle(ctx TopDownMutatorContext, path string) bazel.Label { func BazelLabelForModuleDepSingle(ctx BazelConversionPathContext, path string) bazel.Label {
return BazelLabelForModuleDepsExcludes(ctx, []string{path}, []string(nil)).Includes[0] return BazelLabelForModuleDepsExcludes(ctx, []string{path}, []string(nil)).Includes[0]
} }
@@ -158,7 +170,7 @@ func BazelLabelForModuleDepSingle(ctx TopDownMutatorContext, path string) bazel.
// relative if within the same package). // relative if within the same package).
// Properties must have been annotated with struct tag `android:"path"` so that dependencies modules // Properties must have been annotated with struct tag `android:"path"` so that dependencies modules
// will have already been handled by the path_deps mutator. // will have already been handled by the path_deps mutator.
func BazelLabelForModuleSrc(ctx TopDownMutatorContext, paths []string) bazel.LabelList { func BazelLabelForModuleSrc(ctx BazelConversionPathContext, paths []string) bazel.LabelList {
return BazelLabelForModuleSrcExcludes(ctx, paths, []string(nil)) return BazelLabelForModuleSrcExcludes(ctx, paths, []string(nil))
} }
@@ -168,7 +180,7 @@ func BazelLabelForModuleSrc(ctx TopDownMutatorContext, paths []string) bazel.Lab
// (absolute if in a different package or relative if within the same package). // (absolute if in a different package or relative if within the same package).
// Properties must have been annotated with struct tag `android:"path"` so that dependencies modules // Properties must have been annotated with struct tag `android:"path"` so that dependencies modules
// will have already been handled by the path_deps mutator. // will have already been handled by the path_deps mutator.
func BazelLabelForModuleSrcExcludes(ctx TopDownMutatorContext, paths, excludes []string) bazel.LabelList { func BazelLabelForModuleSrcExcludes(ctx BazelConversionPathContext, paths, excludes []string) bazel.LabelList {
excludeLabels := expandSrcsForBazel(ctx, excludes, []string(nil)) excludeLabels := expandSrcsForBazel(ctx, excludes, []string(nil))
excluded := make([]string, 0, len(excludeLabels.Includes)) excluded := make([]string, 0, len(excludeLabels.Includes))
for _, e := range excludeLabels.Includes { for _, e := range excludeLabels.Includes {
@@ -288,7 +300,7 @@ func transformSubpackagePaths(ctx BazelConversionPathContext, paths bazel.LabelL
// Properties passed as the paths or excludes argument must have been annotated with struct tag // Properties passed as the paths or excludes argument must have been annotated with struct tag
// `android:"path"` so that dependencies on other modules will have already been handled by the // `android:"path"` so that dependencies on other modules will have already been handled by the
// path_deps mutator. // path_deps mutator.
func expandSrcsForBazel(ctx TopDownMutatorContext, paths, expandedExcludes []string) bazel.LabelList { func expandSrcsForBazel(ctx BazelConversionPathContext, paths, expandedExcludes []string) bazel.LabelList {
if paths == nil { if paths == nil {
return bazel.LabelList{} return bazel.LabelList{}
} }
@@ -336,8 +348,8 @@ func expandSrcsForBazel(ctx TopDownMutatorContext, paths, expandedExcludes []str
// getOtherModuleLabel returns a bazel.Label for the given dependency/tag combination for the // getOtherModuleLabel returns a bazel.Label for the given dependency/tag combination for the
// module. The label will be relative to the current directory if appropriate. The dependency must // module. The label will be relative to the current directory if appropriate. The dependency must
// already be resolved by either deps mutator or path deps mutator. // already be resolved by either deps mutator or path deps mutator.
func getOtherModuleLabel(ctx TopDownMutatorContext, dep, tag string, func getOtherModuleLabel(ctx BazelConversionPathContext, dep, tag string,
labelFromModule func(TopDownMutatorContext, blueprint.Module) string) bazel.Label { labelFromModule func(BazelConversionPathContext, blueprint.Module) string) bazel.Label {
m, _ := ctx.ModuleFromName(dep) m, _ := ctx.ModuleFromName(dep)
if m == nil { if m == nil {
panic(fmt.Errorf("No module named %q found, but was a direct dep of %q", dep, ctx.Module().Name())) panic(fmt.Errorf("No module named %q found, but was a direct dep of %q", dep, ctx.Module().Name()))
@@ -359,7 +371,7 @@ func getOtherModuleLabel(ctx TopDownMutatorContext, dep, tag string,
} }
} }
func BazelModuleLabel(ctx TopDownMutatorContext, module blueprint.Module) string { func BazelModuleLabel(ctx BazelConversionPathContext, module blueprint.Module) string {
// TODO(b/165114590): Convert tag (":name{.tag}") to corresponding Bazel implicit output targets. // TODO(b/165114590): Convert tag (":name{.tag}") to corresponding Bazel implicit output targets.
if !convertedToBazel(ctx, module) { if !convertedToBazel(ctx, module) {
return bp2buildModuleLabel(ctx, module) return bp2buildModuleLabel(ctx, module)
@@ -388,7 +400,7 @@ func samePackage(label1, label2 string) bool {
return bazelPackage(label1) == bazelPackage(label2) return bazelPackage(label1) == bazelPackage(label2)
} }
func bp2buildModuleLabel(ctx BazelConversionPathContext, module blueprint.Module) string { func bp2buildModuleLabel(ctx BazelConversionContext, module blueprint.Module) string {
moduleName := ctx.OtherModuleName(module) moduleName := ctx.OtherModuleName(module)
moduleDir := ctx.OtherModuleDir(module) moduleDir := ctx.OtherModuleDir(module)
return fmt.Sprintf("//%s:%s", moduleDir, moduleName) return fmt.Sprintf("//%s:%s", moduleDir, moduleName)

View File

@@ -498,7 +498,7 @@ type ProductConfigProperties map[string]map[string]ProductConfigProperty
// ProductVariableProperties returns a ProductConfigProperties containing only the properties which // ProductVariableProperties returns a ProductConfigProperties containing only the properties which
// have been set for the module in the given context. // have been set for the module in the given context.
func ProductVariableProperties(ctx BaseMutatorContext) ProductConfigProperties { func ProductVariableProperties(ctx BazelConversionPathContext) ProductConfigProperties {
module := ctx.Module() module := ctx.Module()
moduleBase := module.base() moduleBase := module.base()

View File

@@ -50,7 +50,7 @@ type staticOrSharedAttributes struct {
System_dynamic_deps bazel.LabelListAttribute System_dynamic_deps bazel.LabelListAttribute
} }
func groupSrcsByExtension(ctx android.TopDownMutatorContext, srcs bazel.LabelListAttribute) bazel.PartitionToLabelListAttribute { func groupSrcsByExtension(ctx android.BazelConversionPathContext, srcs bazel.LabelListAttribute) bazel.PartitionToLabelListAttribute {
// Check that a module is a filegroup type named <label>. // Check that a module is a filegroup type named <label>.
isFilegroupNamed := func(m android.Module, fullLabel string) bool { isFilegroupNamed := func(m android.Module, fullLabel string) bool {
if ctx.OtherModuleType(m) != "filegroup" { if ctx.OtherModuleType(m) != "filegroup" {
@@ -93,7 +93,7 @@ func groupSrcsByExtension(ctx android.TopDownMutatorContext, srcs bazel.LabelLis
} }
// bp2BuildParseLibProps returns the attributes for a variant of a cc_library. // bp2BuildParseLibProps returns the attributes for a variant of a cc_library.
func bp2BuildParseLibProps(ctx android.TopDownMutatorContext, module *Module, isStatic bool) staticOrSharedAttributes { func bp2BuildParseLibProps(ctx android.BazelConversionPathContext, module *Module, isStatic bool) staticOrSharedAttributes {
lib, ok := module.compiler.(*libraryDecorator) lib, ok := module.compiler.(*libraryDecorator)
if !ok { if !ok {
return staticOrSharedAttributes{} return staticOrSharedAttributes{}
@@ -102,12 +102,12 @@ func bp2BuildParseLibProps(ctx android.TopDownMutatorContext, module *Module, is
} }
// bp2buildParseSharedProps returns the attributes for the shared variant of a cc_library. // bp2buildParseSharedProps returns the attributes for the shared variant of a cc_library.
func bp2BuildParseSharedProps(ctx android.TopDownMutatorContext, module *Module) staticOrSharedAttributes { func bp2BuildParseSharedProps(ctx android.BazelConversionPathContext, module *Module) staticOrSharedAttributes {
return bp2BuildParseLibProps(ctx, module, false) return bp2BuildParseLibProps(ctx, module, false)
} }
// bp2buildParseStaticProps returns the attributes for the static variant of a cc_library. // bp2buildParseStaticProps returns the attributes for the static variant of a cc_library.
func bp2BuildParseStaticProps(ctx android.TopDownMutatorContext, module *Module) staticOrSharedAttributes { func bp2BuildParseStaticProps(ctx android.BazelConversionPathContext, module *Module) staticOrSharedAttributes {
return bp2BuildParseLibProps(ctx, module, true) return bp2BuildParseLibProps(ctx, module, true)
} }
@@ -116,9 +116,9 @@ type depsPartition struct {
implementation bazel.LabelList implementation bazel.LabelList
} }
type bazelLabelForDepsFn func(android.TopDownMutatorContext, []string) bazel.LabelList type bazelLabelForDepsFn func(android.BazelConversionPathContext, []string) bazel.LabelList
func maybePartitionExportedAndImplementationsDeps(ctx android.TopDownMutatorContext, exportsDeps bool, allDeps, exportedDeps []string, fn bazelLabelForDepsFn) depsPartition { func maybePartitionExportedAndImplementationsDeps(ctx android.BazelConversionPathContext, exportsDeps bool, allDeps, exportedDeps []string, fn bazelLabelForDepsFn) depsPartition {
if !exportsDeps { if !exportsDeps {
return depsPartition{ return depsPartition{
implementation: fn(ctx, allDeps), implementation: fn(ctx, allDeps),
@@ -133,9 +133,9 @@ func maybePartitionExportedAndImplementationsDeps(ctx android.TopDownMutatorCont
} }
} }
type bazelLabelForDepsExcludesFn func(android.TopDownMutatorContext, []string, []string) bazel.LabelList type bazelLabelForDepsExcludesFn func(android.BazelConversionPathContext, []string, []string) bazel.LabelList
func maybePartitionExportedAndImplementationsDepsExcludes(ctx android.TopDownMutatorContext, exportsDeps bool, allDeps, excludes, exportedDeps []string, fn bazelLabelForDepsExcludesFn) depsPartition { func maybePartitionExportedAndImplementationsDepsExcludes(ctx android.BazelConversionPathContext, exportsDeps bool, allDeps, excludes, exportedDeps []string, fn bazelLabelForDepsExcludesFn) depsPartition {
if !exportsDeps { if !exportsDeps {
return depsPartition{ return depsPartition{
implementation: fn(ctx, allDeps, excludes), implementation: fn(ctx, allDeps, excludes),
@@ -149,7 +149,7 @@ func maybePartitionExportedAndImplementationsDepsExcludes(ctx android.TopDownMut
} }
} }
func bp2buildParseStaticOrSharedProps(ctx android.TopDownMutatorContext, module *Module, lib *libraryDecorator, isStatic bool) staticOrSharedAttributes { func bp2buildParseStaticOrSharedProps(ctx android.BazelConversionPathContext, module *Module, lib *libraryDecorator, isStatic bool) staticOrSharedAttributes {
attrs := staticOrSharedAttributes{} attrs := staticOrSharedAttributes{}
setAttrs := func(axis bazel.ConfigurationAxis, config string, props StaticOrSharedProperties) { setAttrs := func(axis bazel.ConfigurationAxis, config string, props StaticOrSharedProperties) {
@@ -204,7 +204,7 @@ type prebuiltAttributes struct {
} }
// NOTE: Used outside of Soong repo project, in the clangprebuilts.go bootstrap_go_package // NOTE: Used outside of Soong repo project, in the clangprebuilts.go bootstrap_go_package
func Bp2BuildParsePrebuiltLibraryProps(ctx android.TopDownMutatorContext, module *Module) prebuiltAttributes { func Bp2BuildParsePrebuiltLibraryProps(ctx android.BazelConversionPathContext, module *Module) prebuiltAttributes {
var srcLabelAttribute bazel.LabelAttribute var srcLabelAttribute bazel.LabelAttribute
for axis, configToProps := range module.GetArchVariantProperties(ctx, &prebuiltLinkerProperties{}) { for axis, configToProps := range module.GetArchVariantProperties(ctx, &prebuiltLinkerProperties{}) {
@@ -269,7 +269,7 @@ func parseCommandLineFlags(soongFlags []string) []string {
return result return result
} }
func (ca *compilerAttributes) bp2buildForAxisAndConfig(ctx android.TopDownMutatorContext, axis bazel.ConfigurationAxis, config string, props *BaseCompilerProperties) { func (ca *compilerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversionPathContext, axis bazel.ConfigurationAxis, config string, props *BaseCompilerProperties) {
// If there's arch specific srcs or exclude_srcs, generate a select entry for it. // If there's arch specific srcs or exclude_srcs, generate a select entry for it.
// TODO(b/186153868): do this for OS specific srcs and exclude_srcs too. // TODO(b/186153868): do this for OS specific srcs and exclude_srcs too.
if srcsList, ok := parseSrcs(ctx, props); ok { if srcsList, ok := parseSrcs(ctx, props); ok {
@@ -295,7 +295,7 @@ func (ca *compilerAttributes) bp2buildForAxisAndConfig(ctx android.TopDownMutato
ca.rtti.SetSelectValue(axis, config, props.Rtti) ca.rtti.SetSelectValue(axis, config, props.Rtti)
} }
func (ca *compilerAttributes) convertStlProps(ctx android.TopDownMutatorContext, module *Module) { func (ca *compilerAttributes) convertStlProps(ctx android.ArchVariantContext, module *Module) {
stlPropsByArch := module.GetArchVariantProperties(ctx, &StlProperties{}) stlPropsByArch := module.GetArchVariantProperties(ctx, &StlProperties{})
for _, configToProps := range stlPropsByArch { for _, configToProps := range stlPropsByArch {
for _, props := range configToProps { for _, props := range configToProps {
@@ -313,7 +313,7 @@ func (ca *compilerAttributes) convertStlProps(ctx android.TopDownMutatorContext,
} }
} }
func (ca *compilerAttributes) convertProductVariables(ctx android.TopDownMutatorContext, productVariableProps android.ProductConfigProperties) { func (ca *compilerAttributes) convertProductVariables(ctx android.BazelConversionPathContext, productVariableProps android.ProductConfigProperties) {
productVarPropNameToAttribute := map[string]*bazel.StringListAttribute{ productVarPropNameToAttribute := map[string]*bazel.StringListAttribute{
"Cflags": &ca.copts, "Cflags": &ca.copts,
"Asflags": &ca.asFlags, "Asflags": &ca.asFlags,
@@ -333,7 +333,7 @@ func (ca *compilerAttributes) convertProductVariables(ctx android.TopDownMutator
} }
} }
func (ca *compilerAttributes) finalize(ctx android.TopDownMutatorContext, implementationHdrs bazel.LabelListAttribute) { func (ca *compilerAttributes) finalize(ctx android.BazelConversionPathContext, implementationHdrs bazel.LabelListAttribute) {
ca.srcs.ResolveExcludes() ca.srcs.ResolveExcludes()
partitionedSrcs := groupSrcsByExtension(ctx, ca.srcs) partitionedSrcs := groupSrcsByExtension(ctx, ca.srcs)
@@ -355,7 +355,7 @@ func (ca *compilerAttributes) finalize(ctx android.TopDownMutatorContext, implem
} }
// Parse srcs from an arch or OS's props value. // Parse srcs from an arch or OS's props value.
func parseSrcs(ctx android.TopDownMutatorContext, props *BaseCompilerProperties) (bazel.LabelList, bool) { func parseSrcs(ctx android.BazelConversionPathContext, props *BaseCompilerProperties) (bazel.LabelList, bool) {
anySrcs := false anySrcs := false
// Add srcs-like dependencies such as generated files. // Add srcs-like dependencies such as generated files.
// First create a LabelList containing these dependencies, then merge the values with srcs. // First create a LabelList containing these dependencies, then merge the values with srcs.
@@ -392,7 +392,7 @@ func bp2buildResolveCppStdValue(cpp_std *string, gnu_extensions *bool) *string {
} }
// bp2BuildParseCompilerProps returns copts, srcs and hdrs and other attributes. // bp2BuildParseCompilerProps returns copts, srcs and hdrs and other attributes.
func bp2BuildParseBaseProps(ctx android.TopDownMutatorContext, module *Module) baseAttributes { func bp2BuildParseBaseProps(ctx android.BazelConversionPathContext, module *Module) baseAttributes {
archVariantCompilerProps := module.GetArchVariantProperties(ctx, &BaseCompilerProperties{}) archVariantCompilerProps := module.GetArchVariantProperties(ctx, &BaseCompilerProperties{})
archVariantLinkerProps := module.GetArchVariantProperties(ctx, &BaseLinkerProperties{}) archVariantLinkerProps := module.GetArchVariantProperties(ctx, &BaseLinkerProperties{})
@@ -475,7 +475,7 @@ type linkerAttributes struct {
features bazel.StringListAttribute features bazel.StringListAttribute
} }
func (la *linkerAttributes) bp2buildForAxisAndConfig(ctx android.TopDownMutatorContext, isBinary bool, axis bazel.ConfigurationAxis, config string, props *BaseLinkerProperties) { func (la *linkerAttributes) bp2buildForAxisAndConfig(ctx android.BazelConversionPathContext, isBinary bool, axis bazel.ConfigurationAxis, config string, props *BaseLinkerProperties) {
// Use a single variable to capture usage of nocrt in arch variants, so there's only 1 error message for this module // Use a single variable to capture usage of nocrt in arch variants, so there's only 1 error message for this module
var axisFeatures []string var axisFeatures []string
@@ -548,7 +548,7 @@ func (la *linkerAttributes) bp2buildForAxisAndConfig(ctx android.TopDownMutatorC
} }
} }
func (la *linkerAttributes) convertStripProps(ctx android.TopDownMutatorContext, module *Module) { func (la *linkerAttributes) convertStripProps(ctx android.BazelConversionPathContext, module *Module) {
for axis, configToProps := range module.GetArchVariantProperties(ctx, &StripProperties{}) { for axis, configToProps := range module.GetArchVariantProperties(ctx, &StripProperties{}) {
for config, props := range configToProps { for config, props := range configToProps {
if stripProperties, ok := props.(*StripProperties); ok { if stripProperties, ok := props.(*StripProperties); ok {
@@ -562,7 +562,7 @@ func (la *linkerAttributes) convertStripProps(ctx android.TopDownMutatorContext,
} }
} }
func (la *linkerAttributes) convertProductVariables(ctx android.TopDownMutatorContext, productVariableProps android.ProductConfigProperties) { func (la *linkerAttributes) convertProductVariables(ctx android.BazelConversionPathContext, productVariableProps android.ProductConfigProperties) {
type productVarDep struct { type productVarDep struct {
// the name of the corresponding excludes field, if one exists // the name of the corresponding excludes field, if one exists
@@ -570,14 +570,14 @@ func (la *linkerAttributes) convertProductVariables(ctx android.TopDownMutatorCo
// reference to the bazel attribute that should be set for the given product variable config // reference to the bazel attribute that should be set for the given product variable config
attribute *bazel.LabelListAttribute attribute *bazel.LabelListAttribute
depResolutionFunc func(ctx android.TopDownMutatorContext, modules, excludes []string) bazel.LabelList depResolutionFunc func(ctx android.BazelConversionPathContext, modules, excludes []string) bazel.LabelList
} }
productVarToDepFields := map[string]productVarDep{ productVarToDepFields := map[string]productVarDep{
// product variables do not support exclude_shared_libs // product variables do not support exclude_shared_libs
"Shared_libs": productVarDep{attribute: &la.implementationDynamicDeps, depResolutionFunc: bazelLabelForSharedDepsExcludes}, "Shared_libs": {attribute: &la.implementationDynamicDeps, depResolutionFunc: bazelLabelForSharedDepsExcludes},
"Static_libs": productVarDep{"Exclude_static_libs", &la.implementationDeps, bazelLabelForStaticDepsExcludes}, "Static_libs": {"Exclude_static_libs", &la.implementationDeps, bazelLabelForStaticDepsExcludes},
"Whole_static_libs": productVarDep{"Exclude_static_libs", &la.wholeArchiveDeps, bazelLabelForWholeDepsExcludes}, "Whole_static_libs": {"Exclude_static_libs", &la.wholeArchiveDeps, bazelLabelForWholeDepsExcludes},
} }
for name, dep := range productVarToDepFields { for name, dep := range productVarToDepFields {
@@ -655,14 +655,14 @@ type BazelIncludes struct {
SystemIncludes bazel.StringListAttribute SystemIncludes bazel.StringListAttribute
} }
func bp2BuildParseExportedIncludes(ctx android.TopDownMutatorContext, module *Module) BazelIncludes { func bp2BuildParseExportedIncludes(ctx android.BazelConversionPathContext, module *Module) BazelIncludes {
libraryDecorator := module.linker.(*libraryDecorator) libraryDecorator := module.linker.(*libraryDecorator)
return bp2BuildParseExportedIncludesHelper(ctx, module, libraryDecorator) return bp2BuildParseExportedIncludesHelper(ctx, module, libraryDecorator)
} }
// Bp2buildParseExportedIncludesForPrebuiltLibrary returns a BazelIncludes with Bazel-ified values // Bp2buildParseExportedIncludesForPrebuiltLibrary returns a BazelIncludes with Bazel-ified values
// to export includes from the underlying module's properties. // to export includes from the underlying module's properties.
func Bp2BuildParseExportedIncludesForPrebuiltLibrary(ctx android.TopDownMutatorContext, module *Module) BazelIncludes { func Bp2BuildParseExportedIncludesForPrebuiltLibrary(ctx android.BazelConversionPathContext, module *Module) BazelIncludes {
prebuiltLibraryLinker := module.linker.(*prebuiltLibraryLinker) prebuiltLibraryLinker := module.linker.(*prebuiltLibraryLinker)
libraryDecorator := prebuiltLibraryLinker.libraryDecorator libraryDecorator := prebuiltLibraryLinker.libraryDecorator
return bp2BuildParseExportedIncludesHelper(ctx, module, libraryDecorator) return bp2BuildParseExportedIncludesHelper(ctx, module, libraryDecorator)
@@ -670,7 +670,7 @@ func Bp2BuildParseExportedIncludesForPrebuiltLibrary(ctx android.TopDownMutatorC
// bp2BuildParseExportedIncludes creates a string list attribute contains the // bp2BuildParseExportedIncludes creates a string list attribute contains the
// exported included directories of a module. // exported included directories of a module.
func bp2BuildParseExportedIncludesHelper(ctx android.TopDownMutatorContext, module *Module, libraryDecorator *libraryDecorator) BazelIncludes { func bp2BuildParseExportedIncludesHelper(ctx android.BazelConversionPathContext, module *Module, libraryDecorator *libraryDecorator) BazelIncludes {
exported := BazelIncludes{} exported := BazelIncludes{}
for axis, configToProps := range module.GetArchVariantProperties(ctx, &FlagExporterProperties{}) { for axis, configToProps := range module.GetArchVariantProperties(ctx, &FlagExporterProperties{}) {
for config, props := range configToProps { for config, props := range configToProps {
@@ -690,7 +690,7 @@ func bp2BuildParseExportedIncludesHelper(ctx android.TopDownMutatorContext, modu
return exported return exported
} }
func bazelLabelForStaticModule(ctx android.TopDownMutatorContext, m blueprint.Module) string { func bazelLabelForStaticModule(ctx android.BazelConversionPathContext, m blueprint.Module) string {
label := android.BazelModuleLabel(ctx, m) label := android.BazelModuleLabel(ctx, m)
if aModule, ok := m.(android.Module); ok { if aModule, ok := m.(android.Module); ok {
if ctx.OtherModuleType(aModule) == "cc_library" && !android.GenerateCcLibraryStaticOnly(m.Name()) { if ctx.OtherModuleType(aModule) == "cc_library" && !android.GenerateCcLibraryStaticOnly(m.Name()) {
@@ -700,13 +700,13 @@ func bazelLabelForStaticModule(ctx android.TopDownMutatorContext, m blueprint.Mo
return label return label
} }
func bazelLabelForSharedModule(ctx android.TopDownMutatorContext, m blueprint.Module) string { func bazelLabelForSharedModule(ctx android.BazelConversionPathContext, m blueprint.Module) string {
// cc_library, at it's root name, propagates the shared library, which depends on the static // cc_library, at it's root name, propagates the shared library, which depends on the static
// library. // library.
return android.BazelModuleLabel(ctx, m) return android.BazelModuleLabel(ctx, m)
} }
func bazelLabelForStaticWholeModuleDeps(ctx android.TopDownMutatorContext, m blueprint.Module) string { func bazelLabelForStaticWholeModuleDeps(ctx android.BazelConversionPathContext, m blueprint.Module) string {
label := bazelLabelForStaticModule(ctx, m) label := bazelLabelForStaticModule(ctx, m)
if aModule, ok := m.(android.Module); ok { if aModule, ok := m.(android.Module); ok {
if android.IsModulePrebuilt(aModule) { if android.IsModulePrebuilt(aModule) {
@@ -716,33 +716,33 @@ func bazelLabelForStaticWholeModuleDeps(ctx android.TopDownMutatorContext, m blu
return label return label
} }
func bazelLabelForWholeDeps(ctx android.TopDownMutatorContext, modules []string) bazel.LabelList { func bazelLabelForWholeDeps(ctx android.BazelConversionPathContext, modules []string) bazel.LabelList {
return android.BazelLabelForModuleDepsWithFn(ctx, modules, bazelLabelForStaticWholeModuleDeps) return android.BazelLabelForModuleDepsWithFn(ctx, modules, bazelLabelForStaticWholeModuleDeps)
} }
func bazelLabelForWholeDepsExcludes(ctx android.TopDownMutatorContext, modules, excludes []string) bazel.LabelList { func bazelLabelForWholeDepsExcludes(ctx android.BazelConversionPathContext, modules, excludes []string) bazel.LabelList {
return android.BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, bazelLabelForStaticWholeModuleDeps) return android.BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, bazelLabelForStaticWholeModuleDeps)
} }
func bazelLabelForStaticDepsExcludes(ctx android.TopDownMutatorContext, modules, excludes []string) bazel.LabelList { func bazelLabelForStaticDepsExcludes(ctx android.BazelConversionPathContext, modules, excludes []string) bazel.LabelList {
return android.BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, bazelLabelForStaticModule) return android.BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, bazelLabelForStaticModule)
} }
func bazelLabelForStaticDeps(ctx android.TopDownMutatorContext, modules []string) bazel.LabelList { func bazelLabelForStaticDeps(ctx android.BazelConversionPathContext, modules []string) bazel.LabelList {
return android.BazelLabelForModuleDepsWithFn(ctx, modules, bazelLabelForStaticModule) return android.BazelLabelForModuleDepsWithFn(ctx, modules, bazelLabelForStaticModule)
} }
func bazelLabelForSharedDeps(ctx android.TopDownMutatorContext, modules []string) bazel.LabelList { func bazelLabelForSharedDeps(ctx android.BazelConversionPathContext, modules []string) bazel.LabelList {
return android.BazelLabelForModuleDepsWithFn(ctx, modules, bazelLabelForSharedModule) return android.BazelLabelForModuleDepsWithFn(ctx, modules, bazelLabelForSharedModule)
} }
func bazelLabelForHeaderDeps(ctx android.TopDownMutatorContext, modules []string) bazel.LabelList { func bazelLabelForHeaderDeps(ctx android.BazelConversionPathContext, modules []string) bazel.LabelList {
// This is not elegant, but bp2build's shared library targets only propagate // This is not elegant, but bp2build's shared library targets only propagate
// their header information as part of the normal C++ provider. // their header information as part of the normal C++ provider.
return bazelLabelForSharedDeps(ctx, modules) return bazelLabelForSharedDeps(ctx, modules)
} }
func bazelLabelForSharedDepsExcludes(ctx android.TopDownMutatorContext, modules, excludes []string) bazel.LabelList { func bazelLabelForSharedDepsExcludes(ctx android.BazelConversionPathContext, modules, excludes []string) bazel.LabelList {
return android.BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, bazelLabelForSharedModule) return android.BazelLabelForModuleDepsExcludesWithFn(ctx, modules, excludes, bazelLabelForSharedModule)
} }
@@ -750,7 +750,7 @@ type binaryLinkerAttrs struct {
Linkshared *bool Linkshared *bool
} }
func bp2buildBinaryLinkerProps(ctx android.TopDownMutatorContext, m *Module) binaryLinkerAttrs { func bp2buildBinaryLinkerProps(ctx android.BazelConversionPathContext, m *Module) binaryLinkerAttrs {
attrs := binaryLinkerAttrs{} attrs := binaryLinkerAttrs{}
archVariantProps := m.GetArchVariantProperties(ctx, &BinaryLinkerProperties{}) archVariantProps := m.GetArchVariantProperties(ctx, &BinaryLinkerProperties{})
for axis, configToProps := range archVariantProps { for axis, configToProps := range archVariantProps {