diff options
Diffstat (limited to 'python')
-rw-r--r-- | python/binary.go | 13 | ||||
-rw-r--r-- | python/library.go | 28 | ||||
-rw-r--r-- | python/python.go | 28 |
3 files changed, 25 insertions, 44 deletions
diff --git a/python/binary.go b/python/binary.go index af02de63d..99c625916 100644 --- a/python/binary.go +++ b/python/binary.go @@ -27,7 +27,6 @@ import ( func init() { registerPythonBinaryComponents(android.InitRegistrationContext) - android.RegisterBp2BuildMutator("python_binary_host", PythonBinaryBp2Build) } func registerPythonBinaryComponents(ctx android.RegistrationContext) { @@ -41,17 +40,7 @@ type bazelPythonBinaryAttributes struct { Python_version *string } -func PythonBinaryBp2Build(ctx android.TopDownMutatorContext) { - m, ok := ctx.Module().(*Module) - if !ok || !m.ConvertWithBp2build(ctx) { - return - } - - // a Module can be something other than a python_binary_host - if ctx.ModuleType() != "python_binary_host" { - return - } - +func pythonBinaryBp2Build(ctx android.TopDownMutatorContext, m *Module) { var main *string for _, propIntf := range m.GetProperties() { if props, ok := propIntf.(*BinaryProperties); ok { diff --git a/python/library.go b/python/library.go index 9c92ebd5c..d026c1323 100644 --- a/python/library.go +++ b/python/library.go @@ -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 } diff --git a/python/python.go b/python/python.go index 401d91fe3..734ac57f1 100644 --- a/python/python.go +++ b/python/python.go @@ -23,6 +23,7 @@ import ( "strings" "android/soong/bazel" + "github.com/google/blueprint" "github.com/google/blueprint/proptools" @@ -667,18 +668,25 @@ func (p *Module) createSrcsZip(ctx android.ModuleContext, pkgPath string) androi } // isPythonLibModule returns whether the given module is a Python library Module or not -// This is distinguished by the fact that Python libraries are not installable, while other Python -// modules are. func isPythonLibModule(module blueprint.Module) bool { if m, ok := module.(*Module); ok { - // Python library has no bootstrapper or installer - if m.bootstrapper == nil && m.installer == nil { - return true - } + return m.isLibrary() } return false } +// This is distinguished by the fact that Python libraries are not installable, while other Python +// modules are. +func (p *Module) isLibrary() bool { + // Python library has no bootstrapper or installer + return p.bootstrapper == nil && p.installer == nil +} + +func (p *Module) isBinary() bool { + _, ok := p.bootstrapper.(*binaryDecorator) + return ok +} + // collectPathsFromTransitiveDeps checks for source/data files for duplicate paths // for module and its transitive dependencies and collects list of data/source file // zips for transitive dependencies. @@ -752,6 +760,14 @@ func (p *Module) InstallInData() bool { return true } +func (p *Module) ConvertWithBp2build(ctx android.TopDownMutatorContext) { + if p.isLibrary() { + pythonLibBp2Build(ctx, p) + } else if p.isBinary() { + pythonBinaryBp2Build(ctx, p) + } +} + var Bool = proptools.Bool var BoolDefault = proptools.BoolDefault var String = proptools.String |