From 53b62098d04b2ca4465d9f4954ff521320ad4310 Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Thu, 12 May 2022 15:37:02 -0700 Subject: Add bp2build converter for python protobuf files Bug: 196084681 Test: b run //build/bazel/examples/python/protobuf:build_bazel_examples_python_protobuf_main --config=linux_x86_64 Change-Id: I4d806902d262351231f64686a5d24513a25d9749 --- python/python.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'python/python.go') diff --git a/python/python.go b/python/python.go index b100cc318..7e4cb837c 100644 --- a/python/python.go +++ b/python/python.go @@ -207,6 +207,29 @@ func (m *Module) makeArchVariantBaseAttributes(ctx android.TopDownMutatorContext } } } + + partitionedSrcs := bazel.PartitionLabelListAttribute(ctx, &attrs.Srcs, bazel.LabelPartitions{ + "proto": android.ProtoSrcLabelPartition, + "py": bazel.LabelPartition{Keep_remainder: true}, + }) + attrs.Srcs = partitionedSrcs["py"] + + if !partitionedSrcs["proto"].IsEmpty() { + protoInfo, _ := android.Bp2buildProtoProperties(ctx, &m.ModuleBase, partitionedSrcs["proto"]) + protoLabel := bazel.Label{Label: ":" + protoInfo.Name} + + pyProtoLibraryName := m.Name() + "_py_proto" + ctx.CreateBazelTargetModule(bazel.BazelTargetModuleProperties{ + Rule_class: "py_proto_library", + Bzl_load_location: "//build/bazel/rules/python:py_proto.bzl", + }, android.CommonAttributes{ + Name: pyProtoLibraryName, + }, &bazelPythonProtoLibraryAttributes{ + Deps: bazel.MakeSingleLabelListAttribute(protoLabel), + }) + + attrs.Deps.Add(bazel.MakeLabelAttribute(":" + pyProtoLibraryName)) + } return attrs } -- cgit v1.2.3-59-g8ed1b