blob: 6615ec91839004324135edfbbfcda6818bc64883 [file] [log] [blame]
Ray Milkey522a3bd2019-04-25 17:32:57 -07001# 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
15def _impl(ctx):
Carmelo Casconed33d3b42019-06-18 12:12:36 -070016 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 Milkey522a3bd2019-04-25 17:32:57 -070020
21 cmd = [
Carmelo Casconed33d3b42019-06-18 12:12:36 -070022 "mkdir readme && touch readme/README && %s cf %s readme/README" % (jar_exe_path, outjar.path),
Ray Milkey522a3bd2019-04-25 17:32:57 -070023 ]
24
25 ctx.action(
Carmelo Casconed33d3b42019-06-18 12:12:36 -070026 outputs = [outjar],
Ray Milkey24ba24a2019-04-26 11:53:02 -070027 progress_message = "Generating minimal jar for %s" % ctx.attr.name,
Ray Milkey522a3bd2019-04-25 17:32:57 -070028 command = ";\n".join(cmd),
Carmelo Casconed33d3b42019-06-18 12:12:36 -070029 tools = java_runtime.files,
Ray Milkey522a3bd2019-04-25 17:32:57 -070030 )
31
Ray Milkey24ba24a2019-04-26 11:53:02 -070032minimal_jar = rule(
Carmelo Casconed33d3b42019-06-18 12:12:36 -070033 attrs = {
34 "_jdk": attr.label(
35 default = Label("@bazel_tools//tools/jdk:current_java_runtime"),
36 providers = [java_common.JavaRuntimeInfo],
37 ),
38 },
Ray Milkey522a3bd2019-04-25 17:32:57 -070039 implementation = _impl,
40 outputs = {"jar": "%{name}.jar"},
41)