1# Copyright 2020 Google LLC 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"""starlark rules for jarjar. See https://github.com/pantsbuild/jarjar 15""" 16 17def _jar_jar_impl(ctx): 18 ctx.actions.run( 19 inputs = [ctx.file.rules, ctx.file.input_jar], 20 outputs = [ctx.outputs.jar], 21 executable = ctx.executable._jarjar, 22 progress_message = "jarjar %s" % ctx.label, 23 arguments = ["process", ctx.file.rules.path, ctx.file.input_jar.path, ctx.outputs.jar.path], 24 ) 25 26 return [ 27 JavaInfo( 28 output_jar = ctx.outputs.jar, 29 compile_jar = ctx.outputs.jar, 30 ), 31 DefaultInfo(files = depset([ctx.outputs.jar])), 32 ] 33 34jar_jar = rule( 35 implementation = _jar_jar_impl, 36 attrs = { 37 "input_jar": attr.label(allow_single_file = True), 38 "rules": attr.label(allow_single_file = True), 39 "_jarjar": attr.label(executable = True, cfg = "exec", default = Label("//tools:jarjar")), 40 }, 41 outputs = { 42 "jar": "%{name}.jar", 43 }, 44 provides = [JavaInfo], 45) 46