github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/tools/yamltest/defs.bzl (about)

     1  """Tools for testing yaml files against schemas."""
     2  
     3  def _yaml_test_impl(ctx):
     4      """Implementation for yaml_test."""
     5      runner = ctx.actions.declare_file(ctx.label.name)
     6      ctx.actions.write(runner, "\n".join([
     7          "#!/bin/bash",
     8          "set -euo pipefail",
     9          "%s -schema=%s -- %s" % (
    10              ctx.files._tool[0].short_path,
    11              ctx.files.schema[0].short_path,
    12              " ".join([f.short_path for f in ctx.files.srcs]),
    13          ),
    14      ]), is_executable = True)
    15      return [DefaultInfo(
    16          runfiles = ctx.runfiles(files = ctx.files._tool + ctx.files.schema + ctx.files.srcs),
    17          executable = runner,
    18      )]
    19  
    20  yaml_test = rule(
    21      implementation = _yaml_test_impl,
    22      doc = "Tests a yaml file against a schema.",
    23      attrs = {
    24          "srcs": attr.label_list(
    25              doc = "The input yaml files.",
    26              mandatory = True,
    27              allow_files = True,
    28          ),
    29          "schema": attr.label(
    30              doc = "The schema file in JSON schema format.",
    31              allow_single_file = True,
    32              mandatory = True,
    33          ),
    34          "_tool": attr.label(
    35              executable = True,
    36              cfg = "host",
    37              default = Label("//tools/yamltest:yamltest"),
    38          ),
    39      },
    40      test = True,
    41  )