diff options
Diffstat (limited to 'python/library.go')
| -rw-r--r-- | python/library.go | 41 |
1 files changed, 9 insertions, 32 deletions
diff --git a/python/library.go b/python/library.go index d136a4efb..d026c1323 100644 --- a/python/library.go +++ b/python/library.go @@ -17,17 +17,14 @@ package python // This file contains the module types for building Python library. import ( - "fmt" - "android/soong/android" "android/soong/bazel" + "github.com/google/blueprint/proptools" ) func init() { registerPythonLibraryComponents(android.InitRegistrationContext) - android.RegisterBp2BuildMutator("python_library_host", PythonLibraryHostBp2Build) - android.RegisterBp2BuildMutator("python_library", PythonLibraryBp2Build) } func registerPythonLibraryComponents(ctx android.RegistrationContext) { @@ -46,43 +43,23 @@ func PythonLibraryHostFactory() android.Module { type bazelPythonLibraryAttributes struct { Srcs bazel.LabelListAttribute Deps bazel.LabelListAttribute - Srcs_version string -} - -func PythonLibraryHostBp2Build(ctx android.TopDownMutatorContext) { - pythonLibBp2Build(ctx, "python_library_host") -} - -func PythonLibraryBp2Build(ctx android.TopDownMutatorContext) { - pythonLibBp2Build(ctx, "python_library") + Srcs_version *string } -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 // Bionic. py3Enabled := proptools.BoolDefault(m.properties.Version.Py3.Enabled, true) py2Enabled := proptools.BoolDefault(m.properties.Version.Py2.Enabled, false) - var python_version string + var python_version *string if py2Enabled && !py3Enabled { - python_version = "PY2" + python_version = &pyVersion2 } else if !py2Enabled && py3Enabled { - python_version = "PY3" + 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 } @@ -95,8 +72,8 @@ func pythonLibBp2Build(ctx android.TopDownMutatorContext, modType string) { } props := bazel.BazelTargetModuleProperties{ - // Use the native py_library rule. - Rule_class: "py_library", + Rule_class: "py_library", + Bzl_load_location: "//build/bazel/rules/python:library.bzl", } ctx.CreateBazelTargetModule(props, android.CommonAttributes{ |