<commit_before>compile_args = {
    "opt": [],
    "fastbuild": [],
    "dbg": ["-race"],
}

build_args = {
    "opt": [],
    "fastbuild": [],
    "dbg": ["-race"],
}

link_args = {
    "opt": [
        "-w",
        "-s",
    ],
    "fastbuild": [
        "-w",
        "-s",
    ],
    "dbg": ["-race"],
}

def go_compile(ctx, pkg, srcs, archive, setupGOPATH=False, extra_archives=[]):
  gotool = ctx.file._go
  goroot = ctx.file._goroot

  archives = []
  recursive_deps = set()
  include_paths = ""
  for dep in ctx.attr.deps:
    include_paths += "-I \"" + dep.go_archive.path + "_gopath\" "
    archives += [dep.go_archive]
    recursive_deps += dep.go_recursive_deps

  for a in extra_archives:
    include_paths += "-I \"" + a.path + "_gopath\" "
  archives += list(extra_archives)
  recursive_deps += archives

  if setupGOPATH:
    symlink = ctx.new_file(ctx.configuration.bin_dir, ctx.label.name + ".a_gopath/" + pkg + ".a")
    symlink_content = ctx.label.name + ".a"
    for component in pkg.split("/"):
      symlink_content = "../" + symlink_content

  if ctx.attr.go_build:
    # Cheat and build the package non-hermetically (usually because there is a cgo dependency)
    # TODO(schroederc): add -a flag to regain some hermeticity
    args = build_args[ctx.var['COMPILATION_MODE']]
    cmd = (
        "export PATH;" +
        "GOROOT=" + goroot.path + " " +
        "GOPATH=\"$PWD/" + ctx.label.package + "\" " +
        gotool.path + " build " + ' '.join(args) + " -o " + archive.path + " " + ctx.attr.package)
    mnemonic = 'GoBuild'
  else:
    args = compile_args[ctx.var['COMPILATION_MODE']]
    cmd = (
        "GOROOT=" + goroot.path + " " +
        gotool.path + " tool 6g " + ' '.join(args) + " -p " + pkg + " -complete -pack -o " + archive.path + " " +
        include_paths + " " + cmd_helper.join_paths(" ", set(srcs)))
    mnemonic = 'GoCompile'

  outs = [archive]
  cmd = "set -e;" + cmd + "\n"
  if setupGOPATH:
    cmd += "ln -sf " + symlink_content + " " + symlink.path + ";"
    outs += [symlink]

  ctx.action(
      inputs = srcs + archives + [gotool, goroot],
      outputs = outs,
      mnemonic = mnemonic,
      command = cmd,
      use_default_shell_env = True)

  return recursive_deps

def link_binary(ctx, binary, archive, recursive_deps):
  gotool = ctx.file._go
  goroot = ctx.file._goroot

  include_paths = ""
  for a in recursive_deps + [archive]:
    include_paths += "-L \"" + a.path + "_gopath\" "

  args = link_args[ctx.var['COMPILATION_MODE']]
  cmd = (
      "set -e;" +
      "export PATH;" +
      "GOROOT=" + goroot.path + " " +
      gotool.path + " tool 6l " + ' '.join(args) +
      " " + include_paths + " -o " + binary.path + " " +
      " " + archive.path + ";")

  ctx.action(
      inputs = list(recursive_deps) + [archive, gotool, goroot],
      outputs = [binary],
      mnemonic = 'GoLink',
      command = cmd,
      use_default_shell_env = True)

def go_library_impl(ctx):
  archive = ctx.outputs.archive
  pkg = ctx.attr.go_package_prefix + ctx.label.package
  if ctx.attr.package != "":<commit_msg>Updated the build rules to handle go > 1.5<commit_after>compile_args = {
    "opt": [],
    "fastbuild": [],
    "dbg": ["-race"],
}

build_args = {
    "opt": [],
    "fastbuild": [],
    "dbg": ["-race"],
}

link_args = {
    "opt": [
        "-w",
        "-s",
    ],
    "fastbuild": [
        "-w",
        "-s",
    ],
    "dbg": ["-race"],
}

def go_compile(ctx, pkg, srcs, archive, setupGOPATH=False, extra_archives=[]):
  gotool = ctx.file._go
  goroot = ctx.file._goroot

  archives = []
  recursive_deps = set()
  include_paths = ""
  for dep in ctx.attr.deps:
    include_paths += "-I \"" + dep.go_archive.path + "_gopath\" "
    archives += [dep.go_archive]
    recursive_deps += dep.go_recursive_deps

  for a in extra_archives:
    include_paths += "-I \"" + a.path + "_gopath\" "
  archives += list(extra_archives)
  recursive_deps += archives

  if setupGOPATH:
    symlink = ctx.new_file(ctx.configuration.bin_dir, ctx.label.name + ".a_gopath/" + pkg + ".a")
    symlink_content = ctx.label.name + ".a"
    for component in pkg.split("/"):
      symlink_content = "../" + symlink_content

  if ctx.attr.go_build:
    # Cheat and build the package non-hermetically (usually because there is a cgo dependency)
    # TODO(schroederc): add -a flag to regain some hermeticity
    args = build_args[ctx.var['COMPILATION_MODE']]
    cmd = (
        "export PATH;" +
        "GOROOT=" + goroot.path + " " +
        "GOPATH=\"$PWD/" + ctx.label.package + "\" " +
        gotool.path + " build " + ' '.join(args) + " -o " + archive.path + " " + ctx.attr.package)
    mnemonic = 'GoBuild'
  else:
    args = compile_args[ctx.var['COMPILATION_MODE']]
    cmd = "\n".join([
        "GOROOT=" + goroot.path,
        'if ' + gotool.path + ' tool | grep -q 6g; then',
        '  TOOL=6g',
        'else',
        '  TOOL=compile',
        'fi',
        gotool.path + " tool $TOOL " + ' '.join(args) + " -p " + pkg + " -complete -pack -o " + archive.path + " " +
        include_paths + " " + cmd_helper.join_paths(" ", set(srcs)),
    ])
    mnemonic = 'GoCompile'

  outs = [archive]
  cmd = "set -e;" + cmd + "\n"
  if setupGOPATH:
    cmd += "ln -sf " + symlink_content + " " + symlink.path + ";"
    outs += [symlink]

  ctx.action(
      inputs = srcs + archives + [gotool, goroot],
      outputs = outs,
      mnemonic = mnemonic,
      command = cmd,
      use_default_shell_env = True)

  return recursive_deps

def link_binary(ctx, binary, archive, recursive_deps):
  gotool = ctx.file._go
  goroot = ctx.file._goroot

  include_paths = ""
  for a in recursive_deps + [archive]:
    include_paths += "-L \"" + a.path + "_gopath\" "

  args = link_args[ctx.var['COMPILATION_MODE']]
  cmd = "\n".join([
      'set -e',
      'export PATH',
      'if ' + gotool.path + ' tool | grep -q 6l; then',
      '  TOOL=6l',
      'else',
      '  TOOL=link',
      'fi',
      gotool.path + ' tool $TOOL ' + ' '.join(args)
      + ' ' + include_paths + ' -o ' + binary.path + ' '
      + ' ' + archive.path + ';',
  ])
  ctx.action(
      inputs = list(recursive_deps) + [archive, gotool, goroot],
      outputs = [binary],
      mnemonic = 'GoLink',
      command = cmd,
      use_default_shell_env = True)

def go_library_impl(ctx):
  archive = ctx.outputs.archive
  pkg = ctx.attr.go_package_prefix + ctx.label.package
  if ctx.attr.package != "":
{'fraction_non_alphanumeric': 0.17392657125077784, 'fraction_numerical': 0.0012445550715619166, 'mean_word_length': 2.4288, 'pattern_counts': {'":': 20, '<': 3, '<?xml version=': 0, '>': 4, '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': '1275338', 'n_tokens_mistral': 2433, 'n_tokens_neox': 2347, 'n_words': 483}