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

     1  # Copyright 2016 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  """The browser rule is used to define web_test browsers.
    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  load(":runfiles.bzl", "runfiles")
    22  
    23  def _browser_impl(ctx):
    24      """Implementation of the browser rule."""
    25      patch = ctx.actions.declare_file("%s.tmp.json" % ctx.label.name)
    26      metadata.create_file(ctx = ctx, output = patch, browser_label = ctx.label)
    27      metadata_files = [
    28          patch,
    29          ctx.file.metadata,
    30      ] + [dep[WebTestInfo].metadata for dep in ctx.attr.deps]
    31  
    32      metadata.merge_files(
    33          ctx = ctx,
    34          merger = ctx.executable.merger,
    35          output = ctx.outputs.web_test_metadata,
    36          inputs = metadata_files,
    37      )
    38  
    39      return [
    40          DefaultInfo(runfiles = runfiles.collect(ctx)),
    41          WebTestInfo(
    42              disabled = ctx.attr.disabled,
    43              environment = ctx.attr.environment,
    44              execution_requirements = ctx.attr.execution_requirements,
    45              metadata = ctx.outputs.web_test_metadata,
    46              required_tags = ctx.attr.required_tags,
    47          ),
    48      ]
    49  
    50  browser = rule(
    51      attrs = {
    52          "data": attr.label_list(
    53              doc = "Runtime dependencies for this configuration.",
    54              allow_files = True,
    55              cfg = "data",
    56          ),
    57          "deps": attr.label_list(
    58              doc = "Other web_test-related rules that this rule depends on.",
    59              providers = [WebTestInfo],
    60          ),
    61          "disabled": attr.string(
    62              doc =
    63                  "If set then a no-op test will be run when using this browser.",
    64          ),
    65          "environment": attr.string_dict(doc = "Map of environment variables-values to set."),
    66          "execution_requirements": attr.string_dict(
    67              doc = "Map of execution requirements for this browser.",
    68          ),
    69          "merger": attr.label(
    70              doc = "Metadata merger executable.",
    71              default = Label("//go/metadata/main"),
    72              executable = True,
    73              cfg = "host",
    74          ),
    75          "metadata": attr.label(
    76              doc = "The web_test metadata file that defines how this browser is " +
    77                    "launched and default capabilities for this browser.",
    78              mandatory = True,
    79              allow_single_file = [".json"],
    80          ),
    81          "required_tags": attr.string_list(
    82              doc =
    83                  "A list of tags that web_tests using this browser should have.",
    84          ),
    85      },
    86      doc = "Defines a browser configuration for use with web_test.",
    87      outputs = {"web_test_metadata": "%{name}.gen.json"},
    88      implementation = _browser_impl,
    89  )