1# Copyright 2022 Code Intelligence GmbH 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 15def _strip_jar(ctx): 16 out_jar = ctx.outputs.out 17 if out_jar == None: 18 out_jar = ctx.actions.declare_file(ctx.attr.name + ".jar") 19 20 args = ctx.actions.args() 21 args.add(ctx.file.jar) 22 args.add(out_jar) 23 args.add_all(ctx.attr.paths_to_strip) 24 ctx.actions.run( 25 outputs = [out_jar], 26 inputs = [ctx.file.jar], 27 arguments = [args], 28 executable = ctx.executable._jar_stripper, 29 ) 30 31 return [ 32 DefaultInfo( 33 files = depset([out_jar]), 34 # Workaround for https://github.com/bazelbuild/bazel/issues/15043. 35 runfiles = ctx.runfiles(files = [out_jar]), 36 ), 37 coverage_common.instrumented_files_info( 38 ctx, 39 dependency_attributes = ["jar"], 40 ), 41 ] 42 43strip_jar = rule( 44 implementation = _strip_jar, 45 attrs = { 46 "out": attr.output(), 47 "jar": attr.label( 48 mandatory = True, 49 allow_single_file = [".jar"], 50 ), 51 "paths_to_strip": attr.string_list(), 52 "_jar_stripper": attr.label( 53 default = "//bazel/tools/java:JarStripper", 54 cfg = "exec", 55 executable = True, 56 ), 57 }, 58) 59