blob: 14e5aa2b53f32931651dfbd631db2730a24ac26e [file] [log] [blame]
Carmelo Casconed33d3b42019-06-18 12:12:36 -07001"""
2 Copyright 2018-present Open Networking Foundation
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15"""
16
17"""
18Extension to genrule that has the JDK bin directory in the PATH, thus allowing
19to invoke commands like jar directly in the genrule "cmd" attribute.
20This allows using JDK-related tools on a host system that does not have the JDK
21installed, instead using the current JDK used by Bazel, e.g. the embedded or
22remote one.
23"""
24
25def jdk_genrule(
26 cmd,
27 tools = [],
28 toolchains = [],
29 **kwargs):
30 new_tools = tools + ["@bazel_tools//tools/jdk:current_java_runtime"]
31 new_toolchains = toolchains + ["@bazel_tools//tools/jdk:current_java_runtime"]
32 new_cmd = "echo \"export PATH=$$PWD/$(JAVABASE)/bin:$$PATH:\" > jdk_genrule_setup.sh; " + \
33 "source jdk_genrule_setup.sh; " + cmd
34
35 native.genrule(
36 cmd = new_cmd,
37 tools = new_tools,
38 toolchains = new_toolchains,
39 **kwargs
40 )