1*33edd672SMark# Copyright 2022 Code Intelligence GmbH 2*33edd672SMark# 3*33edd672SMark# Licensed under the Apache License, Version 2.0 (the "License"); 4*33edd672SMark# you may not use this file except in compliance with the License. 5*33edd672SMark# You may obtain a copy of the License at 6*33edd672SMark# 7*33edd672SMark# http://www.apache.org/licenses/LICENSE-2.0 8*33edd672SMark# 9*33edd672SMark# Unless required by applicable law or agreed to in writing, software 10*33edd672SMark# distributed under the License is distributed on an "AS IS" BASIS, 11*33edd672SMark# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*33edd672SMark# See the License for the specific language governing permissions and 13*33edd672SMark# limitations under the License. 14*33edd672SMark 15*33edd672SMarkdef _strip_jar(ctx): 16*33edd672SMark out_jar = ctx.outputs.out 17*33edd672SMark if out_jar == None: 18*33edd672SMark out_jar = ctx.actions.declare_file(ctx.attr.name + ".jar") 19*33edd672SMark 20*33edd672SMark args = ctx.actions.args() 21*33edd672SMark args.add(ctx.file.jar) 22*33edd672SMark args.add(out_jar) 23*33edd672SMark args.add_all(ctx.attr.paths_to_strip) 24*33edd672SMark args.add_all(ctx.attr.paths_to_keep, format_each = "+%s") 25*33edd672SMark ctx.actions.run( 26*33edd672SMark outputs = [out_jar], 27*33edd672SMark inputs = [ctx.file.jar], 28*33edd672SMark arguments = [args], 29*33edd672SMark executable = ctx.executable._jar_stripper, 30*33edd672SMark ) 31*33edd672SMark 32*33edd672SMark return [ 33*33edd672SMark DefaultInfo( 34*33edd672SMark files = depset([out_jar]), 35*33edd672SMark ), 36*33edd672SMark coverage_common.instrumented_files_info( 37*33edd672SMark ctx, 38*33edd672SMark dependency_attributes = ["jar"], 39*33edd672SMark ), 40*33edd672SMark ] 41*33edd672SMark 42*33edd672SMarkstrip_jar = rule( 43*33edd672SMark implementation = _strip_jar, 44*33edd672SMark attrs = { 45*33edd672SMark "out": attr.output(), 46*33edd672SMark "jar": attr.label( 47*33edd672SMark mandatory = True, 48*33edd672SMark allow_single_file = [".jar"], 49*33edd672SMark ), 50*33edd672SMark "paths_to_strip": attr.string_list(), 51*33edd672SMark "paths_to_keep": attr.string_list(), 52*33edd672SMark "_jar_stripper": attr.label( 53*33edd672SMark default = "//bazel/tools/java:JarStripper", 54*33edd672SMark cfg = "exec", 55*33edd672SMark executable = True, 56*33edd672SMark ), 57*33edd672SMark }, 58*33edd672SMark) 59