diff --git a/bp2build/python_binary_conversion_test.go b/bp2build/python_binary_conversion_test.go index cf4632233..6f6fc11e5 100644 --- a/bp2build/python_binary_conversion_test.go +++ b/bp2build/python_binary_conversion_test.go @@ -3,11 +3,19 @@ package bp2build 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 @@ func TestPythonBinaryHostSimple(t *testing.T) { 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 b8659c6bf..b6f45e53e 100644 --- a/bp2build/python_library_conversion_test.go +++ b/bp2build/python_library_conversion_test.go @@ -13,19 +13,24 @@ type PythonLibBp2Build func(ctx android.TopDownMutatorContext) 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 @@ func testPythonLib(t *testing.T, modType string, 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 3a77d0e23..a549a9369 100644 --- a/bp2build/testing.go +++ b/bp2build/testing.go @@ -101,7 +101,8 @@ func runBp2BuildTestCase(t *testing.T, registerModuleTypes func(ctx android.Regi 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 b1065369c..bc2768c72 100644 --- a/python/binary.go +++ b/python/binary.go @@ -38,6 +38,7 @@ type bazelPythonBinaryAttributes struct { Main string Srcs bazel.LabelListAttribute Data bazel.LabelListAttribute + Deps bazel.LabelListAttribute Python_version string } @@ -81,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, } diff --git a/python/library.go b/python/library.go index 45fc00227..a132216f8 100644 --- a/python/library.go +++ b/python/library.go @@ -46,6 +46,7 @@ func PythonLibraryHostFactory() android.Module { type bazelPythonLibraryAttributes struct { Srcs bazel.LabelListAttribute Data bazel.LabelListAttribute + Deps bazel.LabelListAttribute Srcs_version string } @@ -89,10 +90,12 @@ func pythonLibBp2Build(ctx android.TopDownMutatorContext, modType string) { 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, }