kythe.io@v0.0.68-0.20240422202219-7225dbc01741/tools/build_rules/extraction.bzl (about) 1 # Copyright 2019 The Kythe Authors. All rights reserved. 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 15 # TODO(schroederc): move reusable chunks of verifier_test.bzl here 16 17 def _merge_kzips_impl(ctx): 18 output = ctx.outputs.kzip 19 ctx.actions.run( 20 outputs = [output], 21 inputs = ctx.files.srcs, 22 executable = ctx.executable._kzip, 23 mnemonic = "MergeKZips", 24 arguments = ["merge", "--ignore_duplicate_cus", "--output", output.path] + [f.path for f in ctx.files.srcs], 25 ) 26 return [DefaultInfo(files = depset([output]))] 27 28 merge_kzips = rule( 29 attrs = { 30 "srcs": attr.label_list( 31 allow_files = True, 32 ), 33 "_kzip": attr.label( 34 default = Label("//kythe/go/platform/tools/kzip"), 35 executable = True, 36 cfg = "exec", 37 ), 38 }, 39 outputs = {"kzip": "%{name}.kzip"}, 40 implementation = _merge_kzips_impl, 41 ) 42 43 def _filter_kzip_impl(ctx): 44 output = ctx.outputs.kzip 45 args = ctx.actions.args() 46 args.add("filter") 47 args.add("--input", ctx.file.src.path) 48 args.add_joined("--languages", ctx.attr.languages, join_with = ",") 49 args.add("--output", output.path) 50 ctx.actions.run( 51 outputs = [output], 52 inputs = [ctx.file.src], 53 executable = ctx.executable._kzip, 54 mnemonic = "FilterKZips", 55 arguments = [args], 56 ) 57 return [DefaultInfo(files = depset([output]))] 58 59 filter_kzip = rule( 60 attrs = { 61 "src": attr.label( 62 allow_single_file = True, 63 mandatory = True, 64 ), 65 "languages": attr.string_list( 66 doc = "List of languages to retain from the input kzip.", 67 mandatory = True, 68 ), 69 "_kzip": attr.label( 70 default = Label("//kythe/go/platform/tools/kzip"), 71 executable = True, 72 cfg = "exec", 73 ), 74 }, 75 outputs = {"kzip": "%{name}.kzip"}, 76 implementation = _filter_kzip_impl, 77 )