Skip to content

Commit ee6af94

Browse files
committed
bazel: handle generated protos from external repos
When pyprotoc is used through an external repository, generated proto files can arrive with a path/short_path mismatch: - path: bazel-out/.../external/<repo>/... - short_path: ../<repo>/... The previous logic in `rules.bzl` did not match this shape and fell through to "Handling this type of (generated?) .proto file was not forseen". This commit adds a narrow branch in the existing proto loop to normalize this short_path form to a repo-relative path and emit the corresponding `-I` + input proto args. This keeps existing behavior for local files, external source files, and `_virtual_imports`, while fixing generated protos from external repos.
1 parent 2e54d83 commit ee6af94

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

rules.bzl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ def _protoc_plugin_rule_implementation(context):
101101
proto_files = unique_proto_files
102102

103103
for proto_file in proto_files:
104+
# Handle generated files in external repositories where Bazel surfaces
105+
# short paths like "../<repo>/<repo-relative-path>.proto".
106+
if proto_file.short_path.startswith("../"):
107+
short_path = proto_file.short_path.removeprefix("../")
108+
if "/" in short_path:
109+
short_path = short_path.split("/", 1)[1]
110+
if proto_file.path.endswith(short_path):
111+
import_path = proto_file.path[:-len(short_path)]
112+
args.append("-I" + import_path)
113+
args.append(short_path)
114+
continue
115+
104116
if len(proto_file.owner.workspace_root) == 0:
105117
# Handle case where `proto_file` is a local file.
106118
# This includes both source files in the workspace and files

0 commit comments

Comments
 (0)