Skip to content

Commit

Permalink
chore: copy .pb.go generation macro
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle authored and gregmagolan committed Mar 7, 2024
1 parent 7acf23d commit 660b39c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Empty file added bazel/go/BUILD.bazel
Empty file.
39 changes: 39 additions & 0 deletions bazel/go/write_go_generated_source_files.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Copy files generated by go_proto_library to the source tree.
Workaround https://github.com/bazelbuild/rules_go/issues/3658
"""

load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")
load("@aspect_bazel_lib//lib:directory_path.bzl", "make_directory_path")
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")

# buildifier: disable=function-docstring-args
def write_go_generated_source_files(name, src, output_files, **kwargs):
"""Wrapper around write_source_files that extracts from the "go_generated_srcs" output group.
See here where the output_group gets populated:
https://github.com/bazelbuild/rules_go/blob/f5ae196b9d80f041f813443b08bfe9e6daf51287/proto/def.bzl#L138
"""
files_target = "_{}.filegroup".format(name)
dir_target = "_{}.directory".format(name)

native.filegroup(
name = files_target,
srcs = [src],
output_group = "go_generated_srcs",
)

copy_to_directory(
name = dir_target,
srcs = [files_target],
root_paths = ["**"],
)

write_source_files(
name = name,
files = {
output_file: make_directory_path("_{}_dirpath".format(output_file), dir_target, output_file)
for output_file in output_files
},
**kwargs
)

0 comments on commit 660b39c

Please sign in to comment.