python_{binary,library}{,_host} handle lib property
Have binary and library bp2build convert `libs` to
`deps` for bazel
Bug: 196083751
Test: python_{binary,library}_conversion_test.go
Test: build/bazel/ci/mixed_{libc,droid}.sh
Change-Id: I2d5f6ef2e83dd608910edb7adb2eb9a56d25293c
diff --git a/bp2build/python_binary_conversion_test.go b/bp2build/python_binary_conversion_test.go
index cf46322..6f6fc11 100644
--- a/bp2build/python_binary_conversion_test.go
+++ b/bp2build/python_binary_conversion_test.go
@@ -3,11 +3,19 @@
import (
"testing"
+ "android/soong/android"
"android/soong/python"
)
+func runBp2BuildTestCaseWithLibs(t *testing.T, tc bp2buildTestCase) {
+ runBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
+ ctx.RegisterModuleType("python_library", python.PythonLibraryFactory)
+ ctx.RegisterModuleType("python_library_host", python.PythonLibraryHostFactory)
+ }, tc)
+}
+
func TestPythonBinaryHostSimple(t *testing.T) {
- runBp2BuildTestCaseSimple(t, bp2buildTestCase{
+ runBp2BuildTestCaseWithLibs(t, bp2buildTestCase{
description: "simple python_binary_host converts to a native py_binary",
moduleTypeUnderTest: "python_binary_host",
moduleTypeUnderTestFactory: python.PythonBinaryHostFactory,
@@ -25,12 +33,18 @@
srcs: ["**/*.py"],
exclude_srcs: ["b/e.py"],
data: ["files/data.txt",],
+ libs: ["bar"],
bazel_module: { bp2build_available: true },
}
-`,
+ python_library_host {
+ name: "bar",
+ srcs: ["b/e.py"],
+ bazel_module: { bp2build_available: true },
+ }`,
expectedBazelTargets: []string{`py_binary(
name = "foo",
data = ["files/data.txt"],
+ deps = [":bar"],
main = "a.py",
srcs = [
"a.py",
diff --git a/bp2build/python_library_conversion_test.go b/bp2build/python_library_conversion_test.go
index b8659c6..b6f45e5 100644
--- a/bp2build/python_library_conversion_test.go
+++ b/bp2build/python_library_conversion_test.go
@@ -13,19 +13,24 @@
func TestPythonLibrary(t *testing.T) {
testPythonLib(t, "python_library",
- python.PythonLibraryFactory, python.PythonLibraryBp2Build)
+ python.PythonLibraryFactory, python.PythonLibraryBp2Build,
+ func(ctx android.RegistrationContext) {})
}
func TestPythonLibraryHost(t *testing.T) {
testPythonLib(t, "python_library_host",
- python.PythonLibraryHostFactory, python.PythonLibraryHostBp2Build)
+ python.PythonLibraryHostFactory, python.PythonLibraryHostBp2Build,
+ func(ctx android.RegistrationContext) {
+ ctx.RegisterModuleType("python_library", python.PythonLibraryFactory)
+ })
}
func testPythonLib(t *testing.T, modType string,
- factory android.ModuleFactory, mutator PythonLibBp2Build) {
+ factory android.ModuleFactory, mutator PythonLibBp2Build,
+ registration func(ctx android.RegistrationContext)) {
t.Helper()
// Simple
- runBp2BuildTestCaseSimple(t, bp2buildTestCase{
+ runBp2BuildTestCase(t, registration, bp2buildTestCase{
description: fmt.Sprintf("simple %s converts to a native py_library", modType),
moduleTypeUnderTest: modType,
moduleTypeUnderTestFactory: factory,
@@ -42,11 +47,18 @@
srcs: ["**/*.py"],
exclude_srcs: ["b/e.py"],
data: ["files/data.txt",],
+ libs: ["bar"],
bazel_module: { bp2build_available: true },
-}`, modType),
+}
+ python_library {
+ name: "bar",
+ srcs: ["b/e.py"],
+ bazel_module: { bp2build_available: false },
+ }`, modType),
expectedBazelTargets: []string{`py_library(
name = "foo",
data = ["files/data.txt"],
+ deps = [":bar"],
srcs = [
"a.py",
"b/c.py",
diff --git a/bp2build/testing.go b/bp2build/testing.go
index 3a77d0e..a549a93 100644
--- a/bp2build/testing.go
+++ b/bp2build/testing.go
@@ -101,7 +101,8 @@
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
bazelTargets := generateBazelTargetsForDir(codegenCtx, checkDir)
if actualCount, expectedCount := len(bazelTargets), len(tc.expectedBazelTargets); actualCount != expectedCount {
- t.Errorf("%s: Expected %d bazel target, got %d", tc.description, expectedCount, actualCount)
+ t.Errorf("%s: Expected %d bazel target, got %d; %v",
+ tc.description, expectedCount, actualCount, bazelTargets)
} else {
for i, target := range bazelTargets {
if w, g := tc.expectedBazelTargets[i], target.content; w != g {
diff --git a/python/binary.go b/python/binary.go
index b106536..bc2768c 100644
--- a/python/binary.go
+++ b/python/binary.go
@@ -38,6 +38,7 @@
Main string
Srcs bazel.LabelListAttribute
Data bazel.LabelListAttribute
+ Deps bazel.LabelListAttribute
Python_version string
}
@@ -81,11 +82,13 @@
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,
}
diff --git a/python/library.go b/python/library.go
index 45fc002..a132216 100644
--- a/python/library.go
+++ b/python/library.go
@@ -46,6 +46,7 @@
type bazelPythonLibraryAttributes struct {
Srcs bazel.LabelListAttribute
Data bazel.LabelListAttribute
+ Deps bazel.LabelListAttribute
Srcs_version string
}
@@ -89,10 +90,12 @@
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,
}