• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2022 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"""Macro encapsulating the java_binary implementation
16
17This is needed since the `executable` nature of the target must be computed from
18the supplied value of the `create_executable` attribute.
19"""
20
21load("//java/common:java_semantics.bzl", "semantics")
22
23# copybara: default visibility
24
25def register_legacy_java_binary_rules(
26        rule_exec,
27        rule_nonexec,
28        **kwargs):
29    """Registers the correct java_binary rule and deploy jar rule
30
31    Args:
32        rule_exec: (Rule) The executable java_binary rule
33        rule_nonexec: (Rule) The non-executable java_binary rule
34        **kwargs: Actual args to instantiate the rule
35    """
36
37    create_executable = "create_executable" not in kwargs or kwargs["create_executable"]
38
39    # TODO(hvd): migrate depot to integers / maybe use decompose_select_list()
40    if "stamp" in kwargs and type(kwargs["stamp"]) == type(True):
41        kwargs["stamp"] = 1 if kwargs["stamp"] else 0
42    if not create_executable:
43        rule_nonexec(**kwargs)
44    else:
45        if "use_launcher" in kwargs and not kwargs["use_launcher"]:
46            kwargs["launcher"] = None
47        else:
48            # If launcher is not set or None, set it to config flag
49            if "launcher" not in kwargs or not kwargs["launcher"]:
50                kwargs["launcher"] = semantics.LAUNCHER_FLAG_LABEL
51        rule_exec(**kwargs)
52
53def register_java_binary_rules(
54        java_binary,
55        **kwargs):
56    """Creates a java_binary rule and a deploy jar rule
57
58    Args:
59        java_binary: (Rule) The executable java_binary rule
60        **kwargs: Actual args to instantiate the rule
61    """
62
63    # TODO(hvd): migrate depot to integers / maybe use decompose_select_list()
64    if "stamp" in kwargs and type(kwargs["stamp"]) == type(True):
65        kwargs["stamp"] = 1 if kwargs["stamp"] else 0
66
67    if "use_launcher" in kwargs and not kwargs["use_launcher"]:
68        kwargs["launcher"] = None
69    else:
70        # If launcher is not set or None, set it to config flag
71        if "launcher" not in kwargs or not kwargs["launcher"]:
72            kwargs["launcher"] = semantics.LAUNCHER_FLAG_LABEL
73    java_binary(**kwargs)
74