Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .mergequeue/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: 1.0.0
merge_rules:
labels:
trigger: mergequeue-ready
skip_line: ""
merge_failed: ""
skip_delete_branch: ""
update_latest: true
delete_branch: false
use_rebase: true
enable_comments: true
ci_timeout_mins: 0
preconditions:
number_of_approvals: 1
required_checks: []
use_github_mergeability: false
conversation_resolution_required: true
merge_mode:
type: default
parallel_mode: null
auto_update:
enabled: false
label: ""
max_runs_for_update: 0
merge_commit:
use_title_and_body: false
merge_strategy:
name: squash
override_labels:
squash: ""
merge: ""
rebase: mergequeue-rebase
39 changes: 29 additions & 10 deletions rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,35 @@ def _protoc_plugin_rule_implementation(context):
proto_files = unique_proto_files

for proto_file in proto_files:
# If Bazel gives us a `_virtual_imports` path, that path is already the
# canonical import view for `protoc` (import root + import-relative
# filename). We must use it as-is and skip all other path handling.
#
# Important: do not fall through to local/external logic for these
# files. That logic computes a different `-I` root from physical paths,
# which can disagree with the virtual import view and break imports.
# Local/external branches below are only for non-virtual paths.
if _virtual_imports in proto_file.path:
before, after = proto_file.path.split(_virtual_imports)
import_path = before + _virtual_imports + after.split("/")[0] + "/"
args += [
"-I" + import_path,
proto_file.path.replace(import_path, ""),
]
continue

# Handle generated files in external repositories where Bazel surfaces
# short paths like "../<repo>/<repo-relative-path>.proto".
if proto_file.short_path.startswith("../"):
short_path = proto_file.short_path.removeprefix("../")
if "/" in short_path:
short_path = short_path.split("/", 1)[1]
if proto_file.path.endswith(short_path):
import_path = proto_file.path[:-len(short_path)]
args.append("-I" + import_path)
args.append(short_path)
continue

if len(proto_file.owner.workspace_root) == 0:
# Handle case where `proto_file` is a local file.
# This includes both source files in the workspace and files
Expand All @@ -109,7 +138,6 @@ def _protoc_plugin_rule_implementation(context):
# determine the import path correctly for that case. For
# files which are part of the workspace, the `import_path`
# will be empty and we will set it to `./`.
elements = proto_file.path.split("/")
import_path = proto_file.path[:-len(proto_file.short_path)]

if import_path == "":
Expand All @@ -130,15 +158,6 @@ def _protoc_plugin_rule_implementation(context):
"-I" + import_path,
proto_file.path.replace(import_path, ""),
]
elif _virtual_imports in proto_file.path:
# Handle case where `proto_file` is a generated file file in
# `_virtual_imports`.
before, after = proto_file.path.split(_virtual_imports)
import_path = before + _virtual_imports + after.split("/")[0] + "/"
args += [
"-I" + import_path,
proto_file.path.replace(import_path, ""),
]
else:
fail(
"Handling this type of (generated?) .proto file " +
Expand Down