pubref/rules_protobuf

py_proto_library fails when taking input from a genrule

ghostwriternr opened this issue · 1 comments

Problem

py_proto_library fails with errors

ERROR: <path>/BUILD:15:1: output '<path>/health_pb2.py' was not created
ERROR: <path>/BUILD:15:1: output '<path>/health_pb2_grpc.py' was not created
ERROR: <path>/BUILD:15:1: not all outputs were created or valid

when input protos come from a genrule's outs. But works well if I directly use the protos filename directly in protos (I'm not in a position to do so because the .proto is in a different directory, so I tried doing this by manually copying the .proto file to my current working directory for testing).

UPDATE: The rule works works ONLY IF I also completely comment out/remove the genrule and use filename directly as described.

Steps to reproduce:

I have a setup that can be minimally described as such:

- protos/
-- health/
--- health.proto
--- BUILD
- src
-- py_health
--- health.py
--- BUILD

health.py uses health.proto as follows:

from src.py_health import health_pb2
from src.py_health import health_pb2_grpc

So, I bundled the proto file with a filegroup as follows:

filegroup(
    name = "health_proto_file",
    srcs = [
        "health.proto",
    ],
)

And the BUILD file for src/py_health looks like this:

genrule(
    name = "mv_health_proto",
    srcs = [
        "//protos/health:health_proto_file",
    ],
    outs = ["health.proto",],
    cmd = "cp $< $@",
)

py_proto_library(
    name = "py_health_proto",
    protos = [":mv_health_proto",],
    with_grpc = True,
    deps = [
        requirement('protobuf'),
    ],
)

py_library(
    name = "grpc_health",
    srcs = ["health.py",],
    deps = [
        ":py_health_proto",
        "//src/python/grpcio/grpc:grpcio",
    ],
    imports=["../../",],
)

What works?

For the same setup described above, if I temporarily copy health.proto to src/py_health and modify the py_proto_library to:

py_proto_library(
    name = "py_health_proto",
    protos = ["health.proto",],
    with_grpc = True,
    deps = [
        requirement('protobuf'),
    ],
)

and also completely comment out/remove the genrule, it works.

pcj commented

Note: these rules have been re-written and migrated to https://github.com/stackb/rules_proto. Please re-open there if issue persists, thanks.

Cleaning up all issues on this repo, apologies in advance for closing without proper response.