<commit_before>
def _emit_proto_compile(ctx, proto_toolchain, go_proto_toolchain, lib, importpath):
  go_srcs = []
  outpath = None
  for proto in lib.proto.direct_sources:
    out = ctx.new_file(importpath + "/"+ proto.basename[:-len(".proto")] + ".pb.go")
    go_srcs += [out]
    if outpath == None:
        outpath = out.dirname[:-len(importpath)]
  args= [
      "--go_out=" + ",".join(go_proto_toolchain.options) + ":"+outpath,
      "--plugin=protoc-gen-go=" + go_proto_toolchain.plugin.path,
      "--descriptor_set_in", ":".join(
          [s.path for s in lib.proto.transitive_descriptor_sets])
  ]
  args += [proto.short_path for proto in lib.proto.direct_sources]
  ctx.action(
      inputs = [
          proto_toolchain.protoc, 
          go_proto_toolchain.plugin, 
      ] + lib.proto.transitive_descriptor_sets.to_list(),
      outputs = go_srcs,
      progress_message = "Generating into %s" % go_srcs[0].dirname,
      mnemonic = "GoProtocGen",
      executable = proto_toolchain.protoc,
      arguments = args,
  )
  return go_srcs

def _proto_toolchain_impl(ctx):
  return [platform_common.ToolchainInfo(
      protoc = ctx.file._protoc,
  )]

proto_toolchain = rule(
    _proto_toolchain_impl,
    attrs = {
        "_protoc": attr.label(allow_files = True, single_file = True, executable = True, cfg = "host", default=Label("@com_github_google_protobuf//:protoc")),
    },
)

def _go_proto_toolchain_impl(ctx):
  return [platform_common.ToolchainInfo(
      plugin = ctx.file._plugin,
      deps = ctx.attr.deps,
      options = ctx.attr.options,
      compile = _emit_proto_compile,
  )]

go_proto_toolchain = rule(
    _go_proto_toolchain_impl,
    attrs = {
        "deps": attr.label_list(),
        "options": attr.string_list(),
        "_plugin": attr.label(allow_files = True, single_file = True, executable = True, cfg = "host", default=Label("@com_github_golang_protobuf//protoc-gen-go")),
    },
)<commit_msg>Make go proto plugin configurable (#833)<commit_after>
_protoc_prefix = "protoc-gen-"

def _emit_proto_compile(ctx, proto_toolchain, go_proto_toolchain, lib, importpath):
  go_srcs = []
  outpath = None
  for proto in lib.proto.direct_sources:
    out = ctx.new_file(importpath + "/"+ proto.basename[:-len(".proto")] + ".pb.go")
    go_srcs += [out]
    if outpath == None:
        outpath = out.dirname[:-len(importpath)]
  plugin_base_name = go_proto_toolchain.plugin.basename
  if plugin_base_name.startswith(_protoc_prefix):
    plugin_base_name = plugin_base_name[len(_protoc_prefix):]
  args= [
      "--{}_out={}:{}".format(plugin_base_name, ",".join(go_proto_toolchain.options), outpath),
      "--plugin={}={}".format(go_proto_toolchain.plugin.basename, go_proto_toolchain.plugin.path),
      "--descriptor_set_in", ":".join(
          [s.path for s in lib.proto.transitive_descriptor_sets])
  ]
  args += [proto.short_path for proto in lib.proto.direct_sources]
  ctx.action(
      inputs = [
          proto_toolchain.protoc, 
          go_proto_toolchain.plugin, 
      ] + lib.proto.transitive_descriptor_sets.to_list(),
      outputs = go_srcs,
      progress_message = "Generating into %s" % go_srcs[0].dirname,
      mnemonic = "GoProtocGen",
      executable = proto_toolchain.protoc,
      arguments = args,
  )
  return go_srcs

def _proto_toolchain_impl(ctx):
  return [platform_common.ToolchainInfo(
      protoc = ctx.file._protoc,
  )]

proto_toolchain = rule(
    _proto_toolchain_impl,
    attrs = {
        "_protoc": attr.label(allow_files = True, single_file = True, executable = True, cfg = "host", default=Label("@com_github_google_protobuf//:protoc")),
    },
)

def _go_proto_toolchain_impl(ctx):
  return [platform_common.ToolchainInfo(
      plugin = ctx.file.plugin,
      deps = ctx.attr.deps,
      options = ctx.attr.options,
      compile = _emit_proto_compile,
  )]

go_proto_toolchain = rule(
    _go_proto_toolchain_impl,
    attrs = {
        "deps": attr.label_list(),
        "options": attr.string_list(),
        "plugin": attr.label(allow_files = True, single_file = True, executable = True, cfg = "host", default=Label("@com_github_golang_protobuf//protoc-gen-go")),
    },
)
{'fraction_non_alphanumeric': 0.13634181469035045, 'fraction_numerical': 0.001200192030724916, 'mean_word_length': 3.471030042918455, 'pattern_counts': {'":': 11, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7015787', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1420, 'n_words': 241}