blob: 6ac735b77d4db5ce80136bcc9adf3c8be1d714c7 [file] [log] [blame]
ilistde450652021-07-22 04:30:10 -07001# Copyright 2021 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"""
16Java Semantics
17"""
18
ilist1b5cf292021-08-20 06:23:32 -070019java_common = _builtins.toplevel.java_common
20JavaPluginInfo = _builtins.toplevel.JavaPluginInfo
hvd0a13dd62021-11-24 06:13:11 -080021JavaInfo = _builtins.toplevel.JavaInfo
ilist1b5cf292021-08-20 06:23:32 -070022
ilist70211eb2021-08-13 11:49:32 -070023def _macro_preprocess(kwargs):
24 pass
ilistde450652021-07-22 04:30:10 -070025
ilist70211eb2021-08-13 11:49:32 -070026def _check_rule(ctx):
27 pass
ilistde450652021-07-22 04:30:10 -070028
ilist70211eb2021-08-13 11:49:32 -070029def _check_dependency_rule_kinds(ctx):
30 pass
31
32def _preprocess(ctx):
33 return []
34
35def _postprocess(ctx, base_info):
36 return base_info.java_info
37
ilist654410d2021-09-20 01:09:35 -070038def _postprocess_plugin(ctx, base_info):
iliste3c5a932021-09-17 06:39:23 -070039 return base_info.java_info, base_info.default_info
ilista0b82fa2021-09-17 06:35:56 -070040
hvd7b8f7472021-11-24 06:09:18 -080041def _check_proto_registry_collision(ctx):
42 pass
43
hvd0a13dd62021-11-24 06:13:11 -080044def _get_coverage_runner(ctx):
45 runner = ctx.attr._java_toolchain[java_common.JavaToolchainInfo].jacocorunner
46 if not runner:
47 fail("jacocorunner not set in java_toolchain")
48 runner_jar = runner.executable
49 # wrap the jar in JavaInfo so we can add it to deps for java_common.compile()
50 return JavaInfo(output_jar = runner_jar, compile_jar = runner_jar)
51
ilist70211eb2021-08-13 11:49:32 -070052semantics = struct(
ilist1fdd1592021-08-20 06:26:53 -070053 EXPERIMENTAL_USE_FILEGROUPS_IN_JAVALIBRARY = False,
ilist3b9dec82021-09-14 08:31:16 -070054 EXPERIMENTAL_USE_OUTPUTATTR_IN_JAVALIBRARY = False,
ilist70211eb2021-08-13 11:49:32 -070055 COLLECT_SRCS_FROM_PROTO_LIBRARY = False,
ilist932d9dc2021-08-24 05:58:29 -070056 JAVA_TOOLCHAIN_LABEL = "@bazel_tools//tools/jdk:current_java_toolchain",
ilistd5b4d2c2021-11-19 05:07:13 -080057 JAVA_LITE_PROTO_TOOLCHAIN_LABEL = "@//tools/proto/toolchains:javalite",
ilist932d9dc2021-08-24 05:58:29 -070058 JAVA_PLUGINS_FLAG_ALIAS_LABEL = "@bazel_tools//tools/jdk:java_plugins_flag_alias",
59 PROGUARD_ALLOWLISTER_LABEL = "@bazel_tools//tools/jdk:proguard_whitelister",
ilist70211eb2021-08-13 11:49:32 -070060 EXTRA_SRCS_TYPES = [],
ilist1b5cf292021-08-20 06:23:32 -070061 EXTRA_ATTRIBUTES = {
ilistcd3c5a02021-08-24 04:59:57 -070062 "resource_strip_prefix": attr.string(),
ilist1b5cf292021-08-20 06:23:32 -070063 },
ilista0b82fa2021-09-17 06:35:56 -070064 EXTRA_PLUGIN_ATTRIBUTES = {
65 "resource_strip_prefix": attr.string(),
66 },
ilist70211eb2021-08-13 11:49:32 -070067 EXTRA_DEPS = [],
ilista0b82fa2021-09-17 06:35:56 -070068 EXTRA_PLUGIN_DEPS = [],
ilist70211eb2021-08-13 11:49:32 -070069 ALLOWED_RULES_IN_DEPS = [
70 "cc_binary", # NB: linkshared=1
71 "cc_library",
72 "genrule",
73 "genproto", # TODO(bazel-team): we should filter using providers instead (starlark rule).
74 "java_import",
75 "java_library",
76 "java_proto_library",
77 "java_lite_proto_library",
78 "proto_library",
79 "sh_binary",
80 "sh_library",
81 ],
82 ALLOWED_RULES_IN_DEPS_WITH_WARNING = [],
ilist0f726e62021-09-07 04:15:57 -070083 LINT_PROGRESS_MESSAGE = "Running Android Lint for: %{label}",
ilist70211eb2021-08-13 11:49:32 -070084 macro_preprocess = _macro_preprocess,
85 check_rule = _check_rule,
86 check_dependency_rule_kinds = _check_dependency_rule_kinds,
87 preprocess = _preprocess,
88 postprocess = _postprocess,
ilista0b82fa2021-09-17 06:35:56 -070089 postprocess_plugin = _postprocess_plugin,
hvd0a13dd62021-11-24 06:13:11 -080090 check_proto_registry_collision = _check_proto_registry_collision,
91 get_coverage_runner = _get_coverage_runner,
ilista0b82fa2021-09-17 06:35:56 -070092)