def METHOD_NAME(ctx):
    resource_dir = ctx.actions.declare_directory(ctx.label.name + ".d")
    primary_output = "{name}.html".format(name = ctx.label.name)
    # Declared as an output, but not saved as part of the default output group.
    # Build with --output_groups=+asciidoc_logfile to retain.
    logfile = ctx.actions.declare_file(ctx.label.name + ".logfile")
    # Locate the asciidoc binary from the toolchain and construct its args.
    asciidoc = ctx.toolchains[_toolchain_type].asciidoc
    args = ["--backend", "html", "--no-header-footer"]
    for key, value in ctx.attr.attrs.items():
        if value:
            args.append("--attribute=%s=%s" % (key, value))
        else:
            args.append("--attribute=%s!" % (key,))
    if ctx.attr.example_script:
        args.append("--attribute=example_script=" + ctx.file.example_script.path)
    args += ["--conf-file=%s" % c.path for c in ctx.files.confs]
    args += ["-o", paths.join(resource_dir.path, primary_output)]
    args.append(ctx.file.src.path)
    # Get the path where all our necessary tools are located so it can be set
    # to PATH in our run_shell command.
    tool_path = ctx.toolchains[_toolchain_type].path
    # Resolve data targets to get input files and runfiles manifests.
    data, _, manifests = ctx.resolve_command(tools = ctx.attr.data)
    # Run asciidoc and capture stderr to logfile. If it succeeds, look in the
    # captured log for error messages and fail if we find any.
    ctx.actions.run_shell(
        inputs = ([ctx.file.src] +
                  ctx.files.confs +
                  ([ctx.file.example_script] if ctx.file.example_script else []) +
                  data),
        input_manifests = manifests,
        outputs = [resource_dir, logfile],
        arguments = args,
        command = "\n".join([
            "set -e",
            "mkdir -p {resource_dir}".format(resource_dir = shell.quote(resource_dir.path)),
            # Run asciidoc itself, and fail if it returns nonzero.
            "{asciidoc} \"$@\" 2> >(tee -a {logfile} >&2)".format(
                logfile = shell.quote(logfile.path),
                asciidoc = shell.quote(asciidoc),
            ),
            # The tool succeeded, but now check for error diagnostics.
            'if grep -q -e "filter non-zero exit code" -e "no output from filter" {logfile}; then'.format(
                logfile = shell.quote(logfile.path),
            ),
            "exit 1",
            "fi",
            # Move SVGs to the appropriate directory.
            "find . -name '*.svg' -maxdepth 1 -exec mv '{{}}' {out}/ \\;".format(out = shell.quote(resource_dir.path)),
        ]),
        env = {"PATH": tool_path},
        mnemonic = "RunAsciidoc",
    )
    return [
        DefaultInfo(files = depset([resource_dir])),
        OutputGroupInfo(asciidoc_logfile = depset([logfile])),
        AsciidocInfo(primary_output_path = primary_output, resource_dir = resource_dir),
    ]