• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
17load("@rules_java//java:defs.bzl", "JavaInfo")
18
19def _jar_jar_impl(ctx):
20    ctx.actions.run(
21        inputs = [ctx.file.rules, ctx.file.input_jar],
22        outputs = [ctx.outputs.jar],
23        executable = ctx.executable._jarjar,
24        progress_message = "jarjar %s" % ctx.label,
25        arguments = ["process", ctx.file.rules.path, ctx.file.input_jar.path, ctx.outputs.jar.path],
26    )
27
28    return [
29        JavaInfo(
30            output_jar = ctx.outputs.jar,
31            compile_jar = ctx.outputs.jar,
32        ),
33        DefaultInfo(files = depset([ctx.outputs.jar])),
34    ]
35
36jar_jar = rule(
37    implementation = _jar_jar_impl,
38    attrs = {
39        "input_jar": attr.label(allow_single_file = True),
40        "rules": attr.label(allow_single_file = True),
41        "_jarjar": attr.label(executable = True, cfg = "exec", default = Label("//tools:jarjar")),
42    },
43    outputs = {
44        "jar": "%{name}.jar",
45    },
46    provides = [JavaInfo],
47)
48