Add python_library_host -> py_library bp2build support
Bug: 196081770 Test: bp2build/python_library_conversion_test.go Test: build/bazel/ci/mixed_{libc,droid}.sh Change-Id: I4da9938eb0b039f97b83badd2269af153c7edbcc
This commit is contained in:
parent
b37a92ccc8
commit
dc212c0b24
@@ -26,6 +26,7 @@ import (
|
||||
|
||||
func init() {
|
||||
registerPythonLibraryComponents(android.InitRegistrationContext)
|
||||
android.RegisterBp2BuildMutator("python_library_host", PythonLibraryHostBp2Build)
|
||||
android.RegisterBp2BuildMutator("python_library", PythonLibraryBp2Build)
|
||||
}
|
||||
|
||||
@@ -37,6 +38,8 @@ func registerPythonLibraryComponents(ctx android.RegistrationContext) {
|
||||
func PythonLibraryHostFactory() android.Module {
|
||||
module := newModule(android.HostSupported, android.MultilibFirst)
|
||||
|
||||
android.InitBazelModule(module)
|
||||
|
||||
return module.init()
|
||||
}
|
||||
|
||||
@@ -46,14 +49,22 @@ 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 python_library
|
||||
if ctx.ModuleType() != "python_library" {
|
||||
// a Module can be something other than a `modType`
|
||||
if ctx.ModuleType() != modType {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -70,8 +81,8 @@ func PythonLibraryBp2Build(ctx android.TopDownMutatorContext) {
|
||||
python_version = "PY3"
|
||||
} else if !py2Enabled && !py3Enabled {
|
||||
panic(fmt.Errorf(
|
||||
"error for '%s' module: bp2build's python_library converter doesn't understand having "+
|
||||
"neither py2 nor py3 enabled", m.Name()))
|
||||
"error for '%s' module: bp2build's %s converter doesn't understand having "+
|
||||
"neither py2 nor py3 enabled", m.Name(), modType))
|
||||
} else {
|
||||
// do nothing, since python_version defaults to PY2ANDPY3
|
||||
}
|
||||
|
Reference in New Issue
Block a user