Ray Milkey | 522a3bd | 2019-04-25 17:32:57 -0700 | [diff] [blame] | 1 | # Copyright 2015 The Bazel 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 | def _impl(ctx): |
Carmelo Cascone | d33d3b4 | 2019-06-18 12:12:36 -0700 | [diff] [blame] | 16 | outjar = ctx.outputs.jar |
| 17 | |
| 18 | java_runtime = ctx.attr._jdk[java_common.JavaRuntimeInfo] |
| 19 | jar_exe_path = "%s/bin/jar" % java_runtime.java_home |
Ray Milkey | 522a3bd | 2019-04-25 17:32:57 -0700 | [diff] [blame] | 20 | |
| 21 | cmd = [ |
Carmelo Cascone | d33d3b4 | 2019-06-18 12:12:36 -0700 | [diff] [blame] | 22 | "mkdir readme && touch readme/README && %s cf %s readme/README" % (jar_exe_path, outjar.path), |
Ray Milkey | 522a3bd | 2019-04-25 17:32:57 -0700 | [diff] [blame] | 23 | ] |
| 24 | |
Brett Bergquist | 2241235 | 2021-01-20 08:30:15 -0500 | [diff] [blame] | 25 | ctx.actions.run_shell( |
Carmelo Cascone | d33d3b4 | 2019-06-18 12:12:36 -0700 | [diff] [blame] | 26 | outputs = [outjar], |
Ray Milkey | 24ba24a | 2019-04-26 11:53:02 -0700 | [diff] [blame] | 27 | progress_message = "Generating minimal jar for %s" % ctx.attr.name, |
Ray Milkey | 522a3bd | 2019-04-25 17:32:57 -0700 | [diff] [blame] | 28 | command = ";\n".join(cmd), |
Carmelo Cascone | d33d3b4 | 2019-06-18 12:12:36 -0700 | [diff] [blame] | 29 | tools = java_runtime.files, |
Ray Milkey | 522a3bd | 2019-04-25 17:32:57 -0700 | [diff] [blame] | 30 | ) |
| 31 | |
Ray Milkey | 24ba24a | 2019-04-26 11:53:02 -0700 | [diff] [blame] | 32 | minimal_jar = rule( |
Carmelo Cascone | d33d3b4 | 2019-06-18 12:12:36 -0700 | [diff] [blame] | 33 | attrs = { |
| 34 | "_jdk": attr.label( |
| 35 | default = Label("@bazel_tools//tools/jdk:current_java_runtime"), |
| 36 | providers = [java_common.JavaRuntimeInfo], |
| 37 | ), |
| 38 | }, |
Ray Milkey | 522a3bd | 2019-04-25 17:32:57 -0700 | [diff] [blame] | 39 | implementation = _impl, |
| 40 | outputs = {"jar": "%{name}.jar"}, |
| 41 | ) |