kythe.io@v0.0.68-0.20240422202219-7225dbc01741/tools/build_rules/external_tools/external_tools_configure.bzl (about)

     1  """Repository rules for automagically configuring the host toolchain."""
     2  
     3  _BUILD_TEMPLATE = """
     4  package(default_visibility=["//visibility:public"])
     5  
     6  load("@io_kythe//tools/build_rules/external_tools:external_tools_toolchain.bzl", "external_tools_toolchain")
     7  
     8  external_tools_toolchain(
     9    name = "host_toolchain_impl",
    10    asciidoc = "{asciidoc}",
    11    path = "{path}"
    12  )
    13  
    14  toolchain(
    15      name = "host_toolchain",
    16      toolchain = ":host_toolchain_impl",
    17      toolchain_type = "@io_kythe//tools/build_rules/external_tools:external_tools_toolchain_type",
    18  )
    19  """
    20  
    21  def _external_toolchain_autoconf_impl(repository_ctx):
    22      if repository_ctx.os.environ.get("KYTHE_DO_NOT_DETECT_BAZEL_TOOLCHAINS", "0") == "1":
    23          repository_ctx.file("BUILD", "# Toolchain detection disabled by KYTHE_DO_NOT_DETECT_BAZEL_TOOLCHAINS")
    24          return
    25      asciidoc = repository_ctx.which("asciidoc")
    26      if asciidoc == None:
    27          fail("Unable to find 'asciidoc' executable on path.")
    28  
    29      # These are the tools that the doc/schema generation need beyond the
    30      # explicit call to asciidoc.
    31      tools = [
    32          "awk",
    33          "bash",
    34          "cat",
    35          "cut",
    36          "dot",
    37          "env",
    38          "find",
    39          "grep",
    40          "mkdir",
    41          "mktemp",
    42          "mv",
    43          "python3",
    44          "readlink",
    45          "rm",
    46          "sed",
    47          "source-highlight",
    48          "tee",
    49          "touch",
    50          "zip",
    51      ]
    52      for tool in tools:
    53          symlink_command(repository_ctx, tool)
    54  
    55      repository_ctx.file("BUILD", _BUILD_TEMPLATE.format(
    56          asciidoc = asciidoc,
    57          path = repository_ctx.path(""),
    58      ))
    59  
    60  def symlink_command(repository_ctx, command):
    61      binary = repository_ctx.which(command)
    62      if binary == None:
    63          fail("Unable to find '%s' executable on path." % command)
    64      repository_ctx.symlink(binary, command)
    65  
    66  external_toolchain_autoconf = repository_rule(
    67      implementation = _external_toolchain_autoconf_impl,
    68      local = True,
    69      environ = [
    70          "KYTHE_DO_NOT_DETECT_BAZEL_TOOCHAINS",
    71          "PATH",
    72      ],
    73  )
    74  
    75  def external_tools_configure():
    76      external_toolchain_autoconf(name = "local_config_tools")
    77      native.register_toolchains("@local_config_tools//:all")