-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7acf23d
commit 660b39c
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |