github.com/bazelbuild/rules_webtesting@v0.2.0/web/internal/web_test_config.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 """web_test_config.bzl defines the web_test_config rule. 15 16 The web_test_config rules provides configuration information 17 such as additional capabilities. 18 19 DO NOT load this file. Use "@io_bazel_rules_web//web:web.bzl". 20 """ 21 22 load(":metadata.bzl", "metadata") 23 load(":provider.bzl", "WebTestInfo") 24 25 def _web_test_config_impl(ctx): 26 """Implementation of the web_test_config rule.""" 27 metadata_files = [] 28 29 if ctx.attr.metadata: 30 metadata_files = [ctx.file.metadata] 31 32 metadata_files += [dep[WebTestInfo].metadata for dep in ctx.attr.deps] 33 34 if metadata_files: 35 metadata.merge_files( 36 ctx = ctx, 37 merger = ctx.executable.merger, 38 output = ctx.outputs.web_test_metadata, 39 inputs = metadata_files, 40 ) 41 else: 42 metadata.create_file(ctx = ctx, output = ctx.outputs.web_test_metadata) 43 44 return [ 45 DefaultInfo( 46 runfiles = ctx.runfiles(collect_data = True, collect_default = True), 47 ), 48 WebTestInfo(metadata = ctx.outputs.web_test_metadata), 49 ] 50 51 web_test_config = rule( 52 attrs = { 53 "data": attr.label_list( 54 doc = "Runtime dependencies for this configuration.", 55 allow_files = True, 56 cfg = "data", 57 ), 58 "deps": attr.label_list( 59 doc = "Other web_test-related rules that this rule depends on.", 60 providers = [WebTestInfo], 61 ), 62 "merger": attr.label( 63 doc = "Metadata merger executable.", 64 executable = True, 65 cfg = "host", 66 default = Label("//go/metadata/main"), 67 ), 68 "metadata": attr.label( 69 doc = "A web_test metadata file.", 70 allow_single_file = [".json"], 71 ), 72 }, 73 doc = "A configuration that can be used across multiple web_tests.", 74 outputs = {"web_test_metadata": "%{name}.gen.json"}, 75 implementation = _web_test_config_impl, 76 )