Use one mutator for all bp2build conversion.
Each conversion required defining a separate mutator, which will each operate on _all_ modules and requires each to repeat checks whether the mutator should operator. Instead, we introduce a single mutator and modules can define a ConvertWithBp2build to implement bp2build conversion for that module. Test: bp2build.sh Bug: 183079158 Change-Id: I99d4b51f441c2903879092c5b56313d606d4338d
This commit is contained in:
@@ -17,8 +17,6 @@ package python
|
||||
// This file contains the module types for building Python library.
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
|
||||
@@ -27,8 +25,6 @@ import (
|
||||
|
||||
func init() {
|
||||
registerPythonLibraryComponents(android.InitRegistrationContext)
|
||||
android.RegisterBp2BuildMutator("python_library_host", PythonLibraryHostBp2Build)
|
||||
android.RegisterBp2BuildMutator("python_library", PythonLibraryBp2Build)
|
||||
}
|
||||
|
||||
func registerPythonLibraryComponents(ctx android.RegistrationContext) {
|
||||
@@ -50,25 +46,7 @@ type bazelPythonLibraryAttributes struct {
|
||||
Srcs_version *string
|
||||
}
|
||||
|
||||
func PythonLibraryHostBp2Build(ctx android.TopDownMutatorContext) {
|
||||
pythonLibBp2Build(ctx, "python_library_host")
|
||||
}
|
||||
|
||||
func PythonLibraryBp2Build(ctx android.TopDownMutatorContext) {
|
||||
pythonLibBp2Build(ctx, "python_library")
|
||||
}
|
||||
|
||||
func pythonLibBp2Build(ctx android.TopDownMutatorContext, modType string) {
|
||||
m, ok := ctx.Module().(*Module)
|
||||
if !ok || !m.ConvertWithBp2build(ctx) {
|
||||
return
|
||||
}
|
||||
|
||||
// a Module can be something other than a `modType`
|
||||
if ctx.ModuleType() != modType {
|
||||
return
|
||||
}
|
||||
|
||||
func pythonLibBp2Build(ctx android.TopDownMutatorContext, m *Module) {
|
||||
// TODO(b/182306917): this doesn't fully handle all nested props versioned
|
||||
// by the python version, which would have been handled by the version split
|
||||
// mutator. This is sufficient for very simple python_library modules under
|
||||
@@ -81,9 +59,7 @@ func pythonLibBp2Build(ctx android.TopDownMutatorContext, modType string) {
|
||||
} else if !py2Enabled && py3Enabled {
|
||||
python_version = &pyVersion3
|
||||
} else if !py2Enabled && !py3Enabled {
|
||||
panic(fmt.Errorf(
|
||||
"error for '%s' module: bp2build's %s converter doesn't understand having "+
|
||||
"neither py2 nor py3 enabled", m.Name(), modType))
|
||||
ctx.ModuleErrorf("bp2build converter doesn't understand having neither py2 nor py3 enabled")
|
||||
} else {
|
||||
// do nothing, since python_version defaults to PY2ANDPY3
|
||||
}
|
||||
|
Reference in New Issue
Block a user