Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include gen_dir irrespective of sources_dir in protoc_gen #9735

Merged
merged 1 commit into from
Apr 6, 2022

Conversation

perezd
Copy link
Contributor

@perezd perezd commented Apr 4, 2022

This is an attempt at fixing #9731.

This code was introduced Jan 28th of this year in this PR:
#9438

However, there's generated code (via a genrule) may be included in a protoc invocation without a proper source_dir.

@perezd
Copy link
Contributor Author

perezd commented Apr 4, 2022

Hoping @comius can weigh in on this change as I'm less familiar with it, and he was the originator of the code.

@elharo elharo requested a review from anandolee April 5, 2022 11:28
@elharo elharo changed the title include gen_dir irrespsective of sources_dir in protoc_gen include gen_dir irrespective of sources_dir in protoc_gen Apr 5, 2022
Copy link
Contributor

@comius comius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@comius
Copy link
Contributor

comius commented Apr 6, 2022

Envoy is still building with this patched in, integration tests pass.

bazel test --config=remote --override_repository=com_google_protobuf=/.../protobuf  //test/integration:all

@perezd perezd requested review from fowles and removed request for anandolee April 6, 2022 18:24
@perezd perezd merged commit b55c8e4 into main Apr 6, 2022
@perezd perezd deleted the perezd-patch-1 branch April 6, 2022 18:35
@mikex-oss
Copy link

mikex-oss commented Dec 16, 2022

Hi, it looks like this merge breaks our project. I was trying to upgrade from release v3.20.0 (https://github.com/protocolbuffers/protobuf/releases/download/v3.20.0/protobuf-all-3.20.0.tar.gz) to the latest (https://github.com/protocolbuffers/protobuf/releases/download/v21.12/protobuf-all-21.12.tar.gz). Someone from the protobuf team mentioned that this merge was possibly related. I checked by running on this commit (fails) and its parent (passes).

Issue: Bazel build of py_proto_library with generated source fails.

BUILD file:

load("@com_google_protobuf//:protobuf.bzl", "py_proto_library")

#  py_proto_library depend on the source proto being in the same package as the consuming rule
genrule(
    name = "generated_proto",
    srcs = ["@external_repo//path/to:foo.proto"],
    outs = ["foo.proto"],
    cmd = "cp $< $@",
)

py_proto_library(
    name = "foo_py_pb2",
    srcs = ["foo.proto"],
)

Before:

$ bazel build //my_project/proto:foo_py_pb2
INFO: Analyzed target //my_project/proto:foo_py_pb2 (42 packages loaded, 710 targets configured).
INFO: Found 1 target...
...
INFO: From ProtoCompile my_project/proto/foo_pb2.py:
<path>/sandbox/linux-sandbox/1047/execroot/my_project_repo
Target //my_project/proto:foo_py_pb2 up-to-date:
  bazel-bin/my_project/proto/foo_pb2.py
INFO: Elapsed time: 75.079s, Critical Path: 16.77s
INFO: 202 processes: 2 internal, 200 linux-sandbox.
INFO: Build completed successfully, 202 total actions

After this merge:

ERROR: <path>/my_project/proto/BUILD:206:17: ProtoCompile my_project/proto/foo_pb2.py failed: (Exit 1): bash failed: error executing command /bin/bash -c ... (remaining 1 argument skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
foo.proto: File does not reside within any path specified using --proto_path (or -I).  You must specify a --proto_path which encompasses this file.  Note that the proto_path must be an exact prefix of the .proto file names -- protoc is too dumb to figure out when two paths (e.g. absolute and relative) are equivalent (it's harder than you think).
mv: cannot stat 'bazel-out/k8-fastbuild/bin/foo_pb2.py': No such file or directory
<path>/sandbox/linux-sandbox/510/execroot/my_project_repo
Target //my_project/proto:foo_py_pb2 failed to build

Can someone take a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants