Skip to content
Merged
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
21 changes: 14 additions & 7 deletions scala_proto/private/scala_proto_aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@ load(
)
load("@bazel_skylib//lib:dicts.bzl", "dicts")

def _import_paths(proto):
def _import_paths(proto, ctx):
# Under Bazel 7.x, direct_sources from generated protos may still contain
# ctx.bin_dir.path, even when proto_source_root does not. proto_source_root
# may also be relative to ctx.bin_dir.path, or it may contain it. So we try
# removing ctx.bin_dir.path from everything.
bin_dir = ctx.bin_dir.path + "/"
source_root = proto.proto_source_root
if "." == source_root:
return [src.path for src in proto.direct_sources]
else:
offset = len(source_root) + 1 # + '/'
return [src.path[offset:] for src in proto.direct_sources]
source_root += "/" if source_root != "." else ""
source_root = source_root.removeprefix(bin_dir)

return [
ds.path.removeprefix(bin_dir).removeprefix(source_root)
for ds in proto.direct_sources
]

def _code_should_be_generated(ctx, toolchain):
# This feels rather hacky and odd, but we can't compare the labels to ignore a target easily
Expand Down Expand Up @@ -56,7 +63,7 @@ def _pack_sources(ctx, src_jars):
)

def _generate_sources(ctx, toolchain, proto):
sources = _import_paths(proto)
sources = _import_paths(proto, ctx)
descriptors = proto.transitive_descriptor_sets
outputs = {
k: ctx.actions.declare_file("%s_%s_scalapb.srcjar" % (ctx.label.name, k))
Expand Down