kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/proto/go.bzl (about)

     1  load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_file")
     2  load("@io_bazel_rules_go//proto:def.bzl", _go_proto_library = "go_proto_library")
     3  
     4  KYTHE_IMPORT_BASE = "kythe.io/kythe/proto"
     5  
     6  def go_proto_library(
     7          name = None,
     8          proto = None,
     9          deps = [],
    10          importpath = None,
    11          visibility = None,
    12          compilers = None,
    13          suggested_update_target = "//{package}:update"):
    14      """Helper for go_proto_library for kythe project.
    15  
    16      A shorthand for a go_proto_library with its import path set to the
    17      expected default for the Kythe project, e.g.,
    18  
    19        go_kythe_proto(
    20           proto = ":some_proto",
    21           deps = ["x", "y", "z"],
    22        )
    23  
    24      is equivalent in meaning to
    25  
    26        go_proto_library(
    27           name = "some_go_proto"
    28           proto = ":some_proto"
    29           importpath = "kythe.io/kythe/proto/some_proto"
    30           deps = ["x", "y", "z"],
    31        )
    32  
    33      Args:
    34        proto: the proto lib to build a _go_proto lib for
    35        deps: the deps for the proto lib
    36      """
    37      if suggested_update_target != None:
    38          suggested_update_target = suggested_update_target.format(package = native.package_name())
    39  
    40      base = proto.rsplit(":", 2)[-1]
    41      filename = "_".join(base.split("_")[:-1]) + ".pb.go"
    42      if name == None:
    43          if base.endswith("_proto"):
    44              name = base[:-len("proto")] + "go_proto"
    45          else:
    46              name = base + "_go_proto"
    47  
    48      if not importpath:
    49          importpath = KYTHE_IMPORT_BASE + "/" + name
    50      _go_proto_library(
    51          name = name,
    52          deps = deps,
    53          importpath = importpath,
    54          proto = proto,
    55          visibility = visibility,
    56      )
    57      native.filegroup(
    58          name = name + "_src",
    59          output_group = "go_generated_srcs",
    60          srcs = [name],
    61      )
    62      write_source_file(
    63          name = name + "_sync",
    64          in_file = name + "_src",
    65          out_file = name + "/" + filename,
    66          suggested_update_target = suggested_update_target,
    67      )