github.com/bazelbuild/rules_webtesting@v0.2.0/web/internal/web_test_named_file.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 """A rule for defining files that can be located by name. 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_named_file_impl(ctx): 23 name = ctx.attr.alt_name or ctx.label.name 24 25 metadata.create_file( 26 ctx = ctx, 27 output = ctx.outputs.web_test_metadata, 28 web_test_files = [ 29 metadata.web_test_files(ctx = ctx, named_files = {name: ctx.file.file}), 30 ], 31 ) 32 33 return [ 34 DefaultInfo( 35 runfiles = ctx.runfiles( 36 collect_data = True, 37 collect_default = True, 38 files = [ctx.file.file], 39 ), 40 ), 41 WebTestInfo(metadata = ctx.outputs.web_test_metadata), 42 ] 43 44 web_test_named_file = rule( 45 attrs = { 46 "alt_name": attr.string(doc = "If supplied, is used instead of name."), 47 "file": attr.label( 48 doc = "The file that will be returned for name.", 49 allow_single_file = True, 50 mandatory = True, 51 ), 52 }, 53 doc = "Defines a file that can be located by name.", 54 outputs = {"web_test_metadata": "%{name}.gen.json"}, 55 implementation = _web_test_named_file_impl, 56 )