github.com/bazelbuild/rules_webtesting@v0.2.0/web/internal/web_test_named_executable.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 executables 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 load(":runfiles.bzl", "runfiles") 22 23 def _web_test_named_executable_impl(ctx): 24 name = ctx.attr.alt_name or ctx.label.name 25 26 metadata.create_file( 27 ctx = ctx, 28 output = ctx.outputs.web_test_metadata, 29 web_test_files = [ 30 metadata.web_test_files( 31 ctx = ctx, 32 named_files = {name: ctx.executable.executable}, 33 ), 34 ], 35 ) 36 37 return [ 38 DefaultInfo( 39 runfiles = runfiles.collect(ctx = ctx, targets = [ctx.attr.executable]), 40 ), 41 WebTestInfo(metadata = ctx.outputs.web_test_metadata), 42 ] 43 44 web_test_named_executable = rule( 45 attrs = { 46 "alt_name": attr.string(doc = "If supplied, is used instead of name."), 47 "executable": attr.label( 48 doc = "The executable that will be returned for name.", 49 allow_files = True, 50 executable = True, 51 cfg = "target", 52 mandatory = True, 53 ), 54 "merger": attr.label( 55 doc = "Metadata merger executable.", 56 executable = True, 57 cfg = "host", 58 default = Label("//go/metadata/main"), 59 ), 60 }, 61 doc = "Defines an executable that can be located by name.", 62 outputs = {"web_test_metadata": "%{name}.gen.json"}, 63 implementation = _web_test_named_executable_impl, 64 )