summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/binary.go23
-rw-r--r--python/library.go74
-rw-r--r--python/python.go2
3 files changed, 79 insertions, 20 deletions
diff --git a/python/binary.go b/python/binary.go
index e955492a6..bc2768c72 100644
--- a/python/binary.go
+++ b/python/binary.go
@@ -38,27 +38,10 @@ type bazelPythonBinaryAttributes struct {
Main string
Srcs bazel.LabelListAttribute
Data bazel.LabelListAttribute
+ Deps bazel.LabelListAttribute
Python_version string
}
-type bazelPythonBinary struct {
- android.BazelTargetModuleBase
- bazelPythonBinaryAttributes
-}
-
-func BazelPythonBinaryFactory() android.Module {
- module := &bazelPythonBinary{}
- module.AddProperties(&module.bazelPythonBinaryAttributes)
- android.InitBazelTargetModule(module)
- return module
-}
-
-func (m *bazelPythonBinary) Name() string {
- return m.BaseModuleName()
-}
-
-func (m *bazelPythonBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) {}
-
func PythonBinaryBp2Build(ctx android.TopDownMutatorContext) {
m, ok := ctx.Module().(*Module)
if !ok || !m.ConvertWithBp2build(ctx) {
@@ -99,11 +82,13 @@ func PythonBinaryBp2Build(ctx android.TopDownMutatorContext) {
srcs := android.BazelLabelForModuleSrcExcludes(ctx, m.properties.Srcs, m.properties.Exclude_srcs)
data := android.BazelLabelForModuleSrc(ctx, m.properties.Data)
+ deps := android.BazelLabelForModuleDeps(ctx, m.properties.Libs)
attrs := &bazelPythonBinaryAttributes{
Main: main,
Srcs: bazel.MakeLabelListAttribute(srcs),
Data: bazel.MakeLabelListAttribute(data),
+ Deps: bazel.MakeLabelListAttribute(deps),
Python_version: python_version,
}
@@ -112,7 +97,7 @@ func PythonBinaryBp2Build(ctx android.TopDownMutatorContext) {
Rule_class: "py_binary",
}
- ctx.CreateBazelTargetModule(BazelPythonBinaryFactory, m.Name(), props, attrs)
+ ctx.CreateBazelTargetModule(m.Name(), props, attrs)
}
type BinaryProperties struct {
diff --git a/python/library.go b/python/library.go
index 9663b3c75..a132216f8 100644
--- a/python/library.go
+++ b/python/library.go
@@ -17,11 +17,17 @@ 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) {
@@ -32,11 +38,79 @@ func registerPythonLibraryComponents(ctx android.RegistrationContext) {
func PythonLibraryHostFactory() android.Module {
module := newModule(android.HostSupported, android.MultilibFirst)
+ android.InitBazelModule(module)
+
return module.init()
}
+type bazelPythonLibraryAttributes struct {
+ Srcs bazel.LabelListAttribute
+ Data 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")
+}
+
+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
+ }
+
+ // 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
+ if py2Enabled && !py3Enabled {
+ python_version = "PY2"
+ } else if !py2Enabled && py3Enabled {
+ python_version = "PY3"
+ } 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))
+ } else {
+ // do nothing, since python_version defaults to PY2ANDPY3
+ }
+
+ srcs := android.BazelLabelForModuleSrcExcludes(ctx, m.properties.Srcs, m.properties.Exclude_srcs)
+ data := android.BazelLabelForModuleSrc(ctx, m.properties.Data)
+ deps := android.BazelLabelForModuleDeps(ctx, m.properties.Libs)
+
+ attrs := &bazelPythonLibraryAttributes{
+ Srcs: bazel.MakeLabelListAttribute(srcs),
+ Data: bazel.MakeLabelListAttribute(data),
+ Deps: bazel.MakeLabelListAttribute(deps),
+ Srcs_version: python_version,
+ }
+
+ props := bazel.BazelTargetModuleProperties{
+ // Use the native py_library rule.
+ Rule_class: "py_library",
+ }
+
+ ctx.CreateBazelTargetModule(m.Name(), props, attrs)
+}
+
func PythonLibraryFactory() android.Module {
module := newModule(android.HostAndDeviceSupported, android.MultilibBoth)
+ android.InitBazelModule(module)
+
return module.init()
}
diff --git a/python/python.go b/python/python.go
index 2a848ca9c..a35a1ac9c 100644
--- a/python/python.go
+++ b/python/python.go
@@ -678,7 +678,7 @@ func (p *Module) collectPathsFromTransitiveDeps(ctx android.ModuleContext) {
if !isPythonLibModule(child) {
ctx.PropertyErrorf("libs",
"the dependency %q of module %q is not Python library!",
- ctx.ModuleName(), ctx.OtherModuleName(child))
+ ctx.OtherModuleName(child), ctx.ModuleName())
}
// collect source and data paths, checking that there are no duplicate output file conflicts
if dep, ok := child.(pythonDependency); ok {