github.com/bazelbuild/rules_webtesting@v0.2.0/web/internal/web_test_files.bzl (about)

     1  # Copyright 2017 Google Inc.
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #      http://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  """A rule for configuring a set of named files.
    15  
    16  DO NOT load this file. Use "@io_bazel_rules_web//web:web.bzl".
    17  """
    18  
    19  load(":metadata.bzl", "metadata")
    20  load(":provider.bzl", "WebTestInfo")
    21  
    22  def _web_test_files_impl(ctx):
    23      named_files = {}
    24      runfiles = depset()
    25  
    26      for target, name in ctx.attr.files.items():
    27          if name in named_files:
    28              fail("%s appears multiple times." % name, "files")
    29          if len(target.files) != 1:
    30              fail("%s refers to multiple files." % target.label, "files")
    31          named_files[name] = target.files.to_list()[0]
    32          runfiles = depset(transitive = [target.files, runfiles])
    33  
    34      metadata.create_file(
    35          ctx = ctx,
    36          output = ctx.outputs.web_test_metadata,
    37          web_test_files = [
    38              metadata.web_test_files(ctx = ctx, named_files = named_files),
    39          ],
    40      )
    41  
    42      return [
    43          DefaultInfo(
    44              runfiles = ctx.runfiles(
    45                  collect_data = True,
    46                  collect_default = True,
    47                  files = runfiles.to_list(),
    48              ),
    49          ),
    50          WebTestInfo(metadata = ctx.outputs.web_test_metadata),
    51      ]
    52  
    53  web_test_files = rule(
    54      attrs = {
    55          "merger": attr.label(
    56              doc = "Metadata merger executable.",
    57              executable = True,
    58              cfg = "host",
    59              default = Label("//go/metadata/main"),
    60          ),
    61          "files": attr.label_keyed_string_dict(
    62              doc = "A map of files to names.",
    63              mandatory = True,
    64              allow_files = True,
    65              allow_empty = False,
    66          ),
    67      },
    68      doc = "Specifies a set of named files.",
    69      outputs = {"web_test_metadata": "%{name}.gen.json"},
    70      implementation = _web_test_files_impl,
    71  )