ilist | de45065 | 2021-07-22 04:30:10 -0700 | [diff] [blame] | 1 | # 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 | """ |
| 16 | Java Semantics |
| 17 | """ |
| 18 | |
ilist | 1b5cf29 | 2021-08-20 06:23:32 -0700 | [diff] [blame] | 19 | java_common = _builtins.toplevel.java_common |
| 20 | JavaPluginInfo = _builtins.toplevel.JavaPluginInfo |
hvd | 0a13dd6 | 2021-11-24 06:13:11 -0800 | [diff] [blame^] | 21 | JavaInfo = _builtins.toplevel.JavaInfo |
ilist | 1b5cf29 | 2021-08-20 06:23:32 -0700 | [diff] [blame] | 22 | |
ilist | 70211eb | 2021-08-13 11:49:32 -0700 | [diff] [blame] | 23 | def _macro_preprocess(kwargs): |
| 24 | pass |
ilist | de45065 | 2021-07-22 04:30:10 -0700 | [diff] [blame] | 25 | |
ilist | 70211eb | 2021-08-13 11:49:32 -0700 | [diff] [blame] | 26 | def _check_rule(ctx): |
| 27 | pass |
ilist | de45065 | 2021-07-22 04:30:10 -0700 | [diff] [blame] | 28 | |
ilist | 70211eb | 2021-08-13 11:49:32 -0700 | [diff] [blame] | 29 | def _check_dependency_rule_kinds(ctx): |
| 30 | pass |
| 31 | |
| 32 | def _preprocess(ctx): |
| 33 | return [] |
| 34 | |
| 35 | def _postprocess(ctx, base_info): |
| 36 | return base_info.java_info |
| 37 | |
ilist | 654410d | 2021-09-20 01:09:35 -0700 | [diff] [blame] | 38 | def _postprocess_plugin(ctx, base_info): |
ilist | e3c5a93 | 2021-09-17 06:39:23 -0700 | [diff] [blame] | 39 | return base_info.java_info, base_info.default_info |
ilist | a0b82fa | 2021-09-17 06:35:56 -0700 | [diff] [blame] | 40 | |
hvd | 7b8f747 | 2021-11-24 06:09:18 -0800 | [diff] [blame] | 41 | def _check_proto_registry_collision(ctx): |
| 42 | pass |
| 43 | |
hvd | 0a13dd6 | 2021-11-24 06:13:11 -0800 | [diff] [blame^] | 44 | def _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 | |
ilist | 70211eb | 2021-08-13 11:49:32 -0700 | [diff] [blame] | 52 | semantics = struct( |
ilist | 1fdd159 | 2021-08-20 06:26:53 -0700 | [diff] [blame] | 53 | EXPERIMENTAL_USE_FILEGROUPS_IN_JAVALIBRARY = False, |
ilist | 3b9dec8 | 2021-09-14 08:31:16 -0700 | [diff] [blame] | 54 | EXPERIMENTAL_USE_OUTPUTATTR_IN_JAVALIBRARY = False, |
ilist | 70211eb | 2021-08-13 11:49:32 -0700 | [diff] [blame] | 55 | COLLECT_SRCS_FROM_PROTO_LIBRARY = False, |
ilist | 932d9dc | 2021-08-24 05:58:29 -0700 | [diff] [blame] | 56 | JAVA_TOOLCHAIN_LABEL = "@bazel_tools//tools/jdk:current_java_toolchain", |
ilist | d5b4d2c | 2021-11-19 05:07:13 -0800 | [diff] [blame] | 57 | JAVA_LITE_PROTO_TOOLCHAIN_LABEL = "@//tools/proto/toolchains:javalite", |
ilist | 932d9dc | 2021-08-24 05:58:29 -0700 | [diff] [blame] | 58 | JAVA_PLUGINS_FLAG_ALIAS_LABEL = "@bazel_tools//tools/jdk:java_plugins_flag_alias", |
| 59 | PROGUARD_ALLOWLISTER_LABEL = "@bazel_tools//tools/jdk:proguard_whitelister", |
ilist | 70211eb | 2021-08-13 11:49:32 -0700 | [diff] [blame] | 60 | EXTRA_SRCS_TYPES = [], |
ilist | 1b5cf29 | 2021-08-20 06:23:32 -0700 | [diff] [blame] | 61 | EXTRA_ATTRIBUTES = { |
ilist | cd3c5a0 | 2021-08-24 04:59:57 -0700 | [diff] [blame] | 62 | "resource_strip_prefix": attr.string(), |
ilist | 1b5cf29 | 2021-08-20 06:23:32 -0700 | [diff] [blame] | 63 | }, |
ilist | a0b82fa | 2021-09-17 06:35:56 -0700 | [diff] [blame] | 64 | EXTRA_PLUGIN_ATTRIBUTES = { |
| 65 | "resource_strip_prefix": attr.string(), |
| 66 | }, |
ilist | 70211eb | 2021-08-13 11:49:32 -0700 | [diff] [blame] | 67 | EXTRA_DEPS = [], |
ilist | a0b82fa | 2021-09-17 06:35:56 -0700 | [diff] [blame] | 68 | EXTRA_PLUGIN_DEPS = [], |
ilist | 70211eb | 2021-08-13 11:49:32 -0700 | [diff] [blame] | 69 | 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 = [], |
ilist | 0f726e6 | 2021-09-07 04:15:57 -0700 | [diff] [blame] | 83 | LINT_PROGRESS_MESSAGE = "Running Android Lint for: %{label}", |
ilist | 70211eb | 2021-08-13 11:49:32 -0700 | [diff] [blame] | 84 | macro_preprocess = _macro_preprocess, |
| 85 | check_rule = _check_rule, |
| 86 | check_dependency_rule_kinds = _check_dependency_rule_kinds, |
| 87 | preprocess = _preprocess, |
| 88 | postprocess = _postprocess, |
ilist | a0b82fa | 2021-09-17 06:35:56 -0700 | [diff] [blame] | 89 | postprocess_plugin = _postprocess_plugin, |
hvd | 0a13dd6 | 2021-11-24 06:13:11 -0800 | [diff] [blame^] | 90 | check_proto_registry_collision = _check_proto_registry_collision, |
| 91 | get_coverage_runner = _get_coverage_runner, |
ilist | a0b82fa | 2021-09-17 06:35:56 -0700 | [diff] [blame] | 92 | ) |