aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-10-04 14:42:52 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-10-04 14:42:52 +0000
commitbbeae5cf27822ca5301b4a80dec5c521bbc18f63 (patch)
tree7880dc42ef77eed2b7787cf32b693c52a14113bd
parenta04192131566a882fe52db7b57456878e36fc41c (diff)
parent960043796bbda173c40b1381338117749ba7b589 (diff)
downloadbazelbuild-kotlin-rules-bbeae5cf27822ca5301b4a80dec5c521bbc18f63.tar.gz
Snap for 10900817 from 960043796bbda173c40b1381338117749ba7b589 to sdk-releaseplatform-tools-34.0.5
Change-Id: I9498339726e37f385e1fe707ef64329e3ec1c9a7
-rw-r--r--.bazeliskrc2
-rw-r--r--METADATA4
-rw-r--r--WORKSPACE14
-rw-r--r--copy.bara.sky2
-rw-r--r--kokoro/presubmit.cfg2
-rw-r--r--kotlin/common.bzl71
-rw-r--r--kotlin/common/BUILD33
-rw-r--r--kotlin/common/is_eligible_friend.bzl63
-rw-r--r--kotlin/compiler_plugin.bzl5
-rw-r--r--kotlin/jvm/internal_do_not_use/traverse_exports/BUILD5
-rw-r--r--kotlin/jvm/internal_do_not_use/traverse_exports/friend_jars.bzl62
-rw-r--r--kotlin/jvm/internal_do_not_use/traverse_exports/friend_labels.bzl31
-rw-r--r--kotlin/jvm/internal_do_not_use/traverse_exports/traverse_exports.bzl7
-rw-r--r--kotlin/jvm/internal_do_not_use/util/BUILD5
-rw-r--r--kotlin/jvm/internal_do_not_use/util/class_file_selectors.bzl2
-rw-r--r--kotlin/jvm_compile.bzl37
-rw-r--r--kotlin/jvm_import.bzl2
-rw-r--r--kotlin/jvm_library.internal.bzl10
-rw-r--r--tests/analysis/jvm_compile_test.bzl2
-rw-r--r--tests/analysis/jvm_library/data/BUILD16
-rw-r--r--tests/analysis/jvm_library/deps/BUILD4
-rw-r--r--tests/analysis/jvm_library/no_java_srcs/BUILD4
-rw-r--r--tests/analysis/jvm_library/no_kt_srcs/BUILD4
-rw-r--r--tests/analysis/jvm_library/nodeps/BUILD4
-rw-r--r--tests/analysis/jvm_library/only_common_srcs/BUILD4
-rw-r--r--tests/analysis/jvm_library/runtime_deps/BUILD4
-rw-r--r--tests/analysis/jvm_library/treeartifacts_srcs/BUILD4
-rw-r--r--tests/analysis/jvm_library_test.bzl100
-rw-r--r--tests/analysis/util.bzl25
-rw-r--r--tests/jvm/java/functions/car/BUILD4
-rw-r--r--tests/jvm/java/ijar/BUILD4
-rw-r--r--tests/jvm/java/jni/BUILD10
-rw-r--r--tests/jvm/java/junit/BUILD4
-rw-r--r--tests/jvm/java/mockito/BUILD4
-rw-r--r--tests/jvm/java/srcartifacts/BUILD4
-rw-r--r--toolchains/kotlin_jvm/BUILD49
-rw-r--r--toolchains/kotlin_jvm/kt_jvm_toolchains.bzl49
-rw-r--r--tools/BUILD4
-rwxr-xr-xtools/bin/source_jar_zipper_deploy.jarbin2077285 -> 2149157 bytes
-rw-r--r--tools/java/com/google/devtools/kotlin/BUILD4
-rw-r--r--tools/java/com/google/devtools/kotlin/SourceJarZipper.kt22
41 files changed, 440 insertions, 246 deletions
diff --git a/.bazeliskrc b/.bazeliskrc
index 1797a0f..e4f5c60 100644
--- a/.bazeliskrc
+++ b/.bazeliskrc
@@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-USE_BAZEL_VERSION=5.1.0
+USE_BAZEL_VERSION=6.1.1
diff --git a/METADATA b/METADATA
index f0d76c2..c1a975a 100644
--- a/METADATA
+++ b/METADATA
@@ -11,8 +11,8 @@ third_party {
type: GIT
value: "https://team.googlesource.com/kotlin-rules/rules"
}
- version: "6c074b6ce60b1ccfdc17bcf5e0566f497a869790"
- last_upgrade_date { year: 2023 month: 3 day: 13}
+ version: "4effec817231742ccf4ee377790bf42426ef612e"
+ last_upgrade_date { year: 2023 month: 7 day: 25}
license_type: NOTICE
}
diff --git a/WORKSPACE b/WORKSPACE
index bf7ad0f..40db7f4 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -18,9 +18,9 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "rules_jvm_external",
- strip_prefix = "rules_jvm_external-4.2",
- sha256 = "cd1a77b7b02e8e008439ca76fd34f5b07aecb8c752961f9640dea15e9e5ba1ca",
- url = "https://github.com/bazelbuild/rules_jvm_external/archive/4.2.zip",
+ strip_prefix = "rules_jvm_external-5.2",
+ sha256 = "3824ac95d9edf8465c7a42b7fcb88a5c6b85d2bac0e98b941ba13f235216f313",
+ url = "https://github.com/bazelbuild/rules_jvm_external/archive/5.2.zip",
)
load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")
rules_jvm_external_deps()
@@ -49,10 +49,10 @@ http_archive(
http_archive(
name = "rules_java",
urls = [
- "https://mirror.bazel.build/github.com/bazelbuild/rules_java/releases/download/5.0.0/rules_java-5.0.0.tar.gz",
- "https://github.com/bazelbuild/rules_java/releases/download/5.0.0/rules_java-5.0.0.tar.gz",
+ "https://mirror.bazel.build/github.com/bazelbuild/rules_java/releases/download/5.5.0/rules_java-5.5.0.tar.gz",
+ "https://github.com/bazelbuild/rules_java/releases/download/5.5.0/rules_java-5.5.0.tar.gz",
],
- sha256 = "8c376f1e4ab7d7d8b1880e4ef8fc170862be91b7c683af97ca2768df546bb073",
+ sha256 = "bcfabfb407cb0c8820141310faa102f7fb92cc806b0f0e26a625196101b0b57e",
)
load("@rules_java//java:repositories.bzl", "java_tools_repos")
java_tools_repos()
@@ -70,7 +70,7 @@ load("@//toolchains/kotlin_jvm:kt_jvm_toolchains.bzl", "KT_VERSION")
http_archive(
name = "kotlinc",
build_file = "@//bazel:kotlinc.BUILD",
- sha256 = "4c3fa7bc1bb9ef3058a2319d8bcc3b7196079f88e92fdcd8d304a46f4b6b5787",
+ sha256 = "1fc50d805f9809e92de43e91f089cc8618567c1a350faebdabf8a40c5048bee8",
strip_prefix = "kotlinc",
urls = [
"https://github.com/JetBrains/kotlin/releases/download/v{0}/kotlin-compiler-{0}.zip".format(KT_VERSION[1:].replace("_", ".")),
diff --git a/copy.bara.sky b/copy.bara.sky
index a386f99..aff4a12 100644
--- a/copy.bara.sky
+++ b/copy.bara.sky
@@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-1217989423 \ No newline at end of file
+-1392002248 \ No newline at end of file
diff --git a/kokoro/presubmit.cfg b/kokoro/presubmit.cfg
index 07e57e4..ca64f8c 100644
--- a/kokoro/presubmit.cfg
+++ b/kokoro/presubmit.cfg
@@ -19,7 +19,7 @@
# Update this as newer versions of bazel are released.
build_params {
key: "bazel_version"
- value: "5.1.0"
+ value: "6.1.1"
}
env_vars {
diff --git a/kotlin/common.bzl b/kotlin/common.bzl
index 65dd2ba..0e3b77d 100644
--- a/kotlin/common.bzl
+++ b/kotlin/common.bzl
@@ -18,6 +18,7 @@
load("//kotlin/jvm/internal_do_not_use/util:file_factory.bzl", "FileFactory")
load("//kotlin/jvm/internal_do_not_use/util:srcjars.bzl", "kt_srcjars")
load("//toolchains/kotlin_jvm:androidlint_toolchains.bzl", "androidlint_toolchains")
+load("//toolchains/kotlin_jvm:kt_jvm_toolchains.bzl", "kt_jvm_toolchains")
load("//:visibility.bzl", "RULES_DEFS_THAT_COMPILE_KOTLIN")
load("@bazel_skylib//lib:sets.bzl", "sets")
load("//bazel:stubs.bzl", "lint_actions")
@@ -86,8 +87,7 @@ def _get_common_and_user_kotlinc_args(ctx, toolchain, extra_kotlinc_args):
] + extra_kotlinc_args
def _kt_plugins_map(
- android_lint_singlejar_plugins = depset(),
- android_lint_libjar_plugin_infos = [],
+ android_lint_rulesets = [],
java_plugin_datas = depset(),
java_plugin_infos = [],
kt_codegen_plugin_infos = depset(),
@@ -95,18 +95,15 @@ def _kt_plugins_map(
"""A struct containing all the plugin types understood by rules_kotlin.
Args:
- android_lint_singlejar_plugins: (depset[File]) Android Lint checkers.
+ android_lint_rulesets: (list[lint_actions.AndroidLintRulesInfo]) Android Lint checkers.
Each JAR is self-contained and should be loaded in an isolated classloader.
- android_lint_libjar_plugin_infos: (list[JavaInfo]) Android Lint checkers.
- All infos share transitive dependencies and should be loaded in a combined classloader.
java_plugin_datas: (depset[JavaPluginData]) for KtCodegenProcessing.
java_plugin_infos: (list[JavaPluginInfo])
kt_codegen_plugin_infos: (depset[KtCodegenPluginInfo]) for KtCodegenProcessing.
kt_compiler_plugin_infos: (list[KtCompilerPluginInfo])
"""
return struct(
- android_lint_singlejar_plugins = android_lint_singlejar_plugins,
- android_lint_libjar_plugin_infos = android_lint_libjar_plugin_infos,
+ android_lint_rulesets = android_lint_rulesets,
java_plugin_datas = java_plugin_datas,
java_plugin_infos = java_plugin_infos,
kt_codegen_plugin_infos = kt_codegen_plugin_infos,
@@ -142,6 +139,12 @@ def _run_kotlinc(
kotlinc_args.use_param_file("@%s", use_always = True) # Use params file to handle long classpaths (b/76185759)
kotlinc_args.set_param_file_format("multiline") # kotlinc only supports double-quotes ("): https://youtrack.jetbrains.com/issue/KT-24472
+ # Args to the kotlinc JVM
+ #
+ # These cannot use a param file because the file wouldn't be read until after the JVM launches.
+ # Values will be prepended with --jvm_flag= for detection.
+ jvm_args = []
+
kotlinc_args.add_joined("-cp", classpath, join_with = ":")
transitive_inputs.append(classpath)
kotlinc_args.add_all(_get_common_and_user_kotlinc_args(ctx, toolchain, kotlincopts))
@@ -187,14 +190,17 @@ def _run_kotlinc(
# (b/112439843).
ctx.actions.run(
executable = toolchain.kotlin_compiler,
- arguments = [kotlinc_args],
+ arguments = ["--jvm_flag=" + x for x in jvm_args] + [kotlinc_args],
inputs = depset(direct = direct_inputs, transitive = transitive_inputs),
outputs = outputs,
mnemonic = mnemonic,
progress_message = message_prefix + str(_get_original_kt_target_label(ctx)),
execution_requirements = {
+ "local": "1", # Ensure comparable results across runs (cold builds, same machine)
+ } if toolchain.is_profiling_enabled(ctx.label) else {
"worker-key-mnemonic": "Kt2JavaCompile",
},
+ toolchain = kt_jvm_toolchains.type,
)
return struct(
@@ -237,7 +243,7 @@ def _kt_compile(
enforce_strict_deps = enforce_strict_deps,
enforce_complete_jdeps = enforce_complete_jdeps,
mnemonic = "Kt2JavaCompile",
- message_prefix = "Compiling for Java runtime: ",
+ message_prefix = "Compiling Kotlin For Java Runtime: ",
)
srcjar = kt_srcjars.zip(
@@ -307,13 +313,14 @@ def _derive_headers(
outputs = [output_dir],
mnemonic = "KtDeriveHeaders",
progress_message = "Deriving %s: %s" % (output_dir.basename, _get_original_kt_target_label(ctx)),
+ toolchain = kt_jvm_toolchains.type,
)
return [output_dir]
def _get_original_kt_target_label(ctx):
label = ctx.label
if label.name.find("_DO_NOT_DEPEND") > 0:
- # Remove rule suffix added by kt_android_library
+ # Remove rule suffix added by android_library(
label = label.relative(":%s" % label.name[0:label.name.find("_DO_NOT_DEPEND")])
elif hasattr(ctx.attr, "_kt_codegen_plugin_build_tool") and label.name.endswith("_processed_srcs"):
# Remove rule suffix added by kt_codegen_filegroup. b/259984258
@@ -377,6 +384,7 @@ def _offline_instrument_jar(ctx, toolchain, jar, srcs = []):
outputs = [output],
mnemonic = "KtJaCoCoInstrument",
progress_message = "Instrumenting Kotlin for coverage collection: %s" % _get_original_kt_target_label(ctx),
+ toolchain = kt_jvm_toolchains.type,
)
return output
@@ -412,6 +420,7 @@ def _singlejar(
outputs = [output],
mnemonic = mnemonic,
progress_message = "Merging %s: %s" % (content, label),
+ toolchain = "@bazel_tools//tools/jdk:toolchain_type",
)
def _merge_jdeps(ctx, kt_jvm_toolchain, jdeps_files, file_factory):
@@ -430,6 +439,7 @@ def _merge_jdeps(ctx, kt_jvm_toolchain, jdeps_files, file_factory):
arguments = [args],
mnemonic = "KtMergeJdeps",
progress_message = "Merging jdeps files %{output}",
+ toolchain = kt_jvm_toolchains.type,
)
return merged_jdeps_file
@@ -464,6 +474,24 @@ def _split_srcs_by_language(srcs, common_srcs, java_syncer):
return (kt_srcs, java_srcs)
+def _merge_exported_plugins(exported_plugins_map):
+ for field in ["java_plugin_datas", "kt_codegen_plugin_infos", "kt_compiler_plugin_infos"]:
+ if getattr(exported_plugins_map, field):
+ fail("exported_plugins doesn't support %s. These are propagated with aspects" % field)
+
+ android_lint_ruleset_jars = []
+
+ return exported_plugins_map.java_plugin_infos + [
+ JavaPluginInfo(
+ processor_class = None,
+ runtime_deps = [
+ # Assume this list is short
+ JavaInfo(output_jar = jar, compile_jar = jar)
+ for jar in android_lint_ruleset_jars
+ ],
+ ),
+ ]
+
# TODO: Streamline API to generate less actions.
def _kt_jvm_library(
ctx,
@@ -482,7 +510,7 @@ def _kt_jvm_library(
runtime_deps = [], # passthrough for JavaInfo constructor
native_libraries = [], # passthrough of CcInfo for JavaInfo constructor
plugins = _kt_plugins_map(),
- exported_plugins = [],
+ exported_plugins = _kt_plugins_map(),
javacopts = [],
kotlincopts = [],
compile_jdeps = depset(),
@@ -534,6 +562,7 @@ def _kt_jvm_library(
# Includes generative deps from codegen.
extended_deps = static_deps + generative_deps
full_classpath = _create_classpath(java_toolchain, extended_deps)
+ exported_plugins = _merge_exported_plugins(exported_plugins)
# Collect all plugin data, including processors to run and all plugin classpaths,
# whether they have processors or not (b/120995492).
@@ -715,14 +744,9 @@ def _kt_jvm_library(
resource_files = resource_files,
baseline_file = androidlint_toolchains.get_baseline(ctx),
config = kt_toolchain.android_lint_config,
- android_lint_plugins_depset = depset(
- order = "preorder",
- transitive = [legacy_java_plugin_classpaths] + [
- dep.transitive_runtime_jars
- for dep in plugins.android_lint_libjar_plugin_infos
- ],
- ),
- android_lint_rules = plugins.android_lint_singlejar_plugins,
+ android_lint_rules = plugins.android_lint_rulesets + [
+ lint_actions.AndroidLintRulesetInfo(singlejars = legacy_java_plugin_classpaths),
+ ],
lint_flags = lint_flags,
extra_input_depsets = [p.processor_data for p in java_plugin_datas_legacy] + [depset([java_genjar] if java_genjar else [])],
testonly = testonly,
@@ -746,7 +770,7 @@ def _kt_jvm_library(
use_validation = ctx.var.get("kt_use_validations", use_validation)
# Include marker file in runtime Jar so we can reliably identify 1P Kotlin code
- # TODO: consider only doing this for kt_android_library
+ # TODO: consider only doing this for android_library(
_singlejar(
ctx,
out_jars + ([kt_toolchain.build_marker] if kt_srcs and ctx.label.package.startswith("java/") else []),
@@ -816,7 +840,12 @@ def _kt_jvm_import(
java_info = java_common.merge([
JavaInfo(
output_jar = jar,
- compile_jar = jar,
+ compile_jar = java_common.run_ijar(
+ actions = ctx.actions,
+ jar = jar,
+ target_label = _get_original_kt_target_label(ctx),
+ java_toolchain = java_toolchain,
+ ),
source_jar = srcjar,
deps = [deps],
runtime_deps = runtime_deps,
diff --git a/kotlin/common/BUILD b/kotlin/common/BUILD
new file mode 100644
index 0000000..d75adbc
--- /dev/null
+++ b/kotlin/common/BUILD
@@ -0,0 +1,33 @@
+# Copyright 2022 Google LLC. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the License);
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
+
+package(
+ default_applicable_licenses = ["//:license"],
+ default_visibility = ["//:internal"],
+)
+
+licenses(["notice"])
+
+bzl_library(
+ name = "common_bzl",
+ srcs = glob(["*.bzl"]),
+ visibility = [
+ "//:internal",
+ ],
+ deps = [
+ "//:visibility_bzl",
+ ],
+)
diff --git a/kotlin/common/is_eligible_friend.bzl b/kotlin/common/is_eligible_friend.bzl
new file mode 100644
index 0000000..1e5e814
--- /dev/null
+++ b/kotlin/common/is_eligible_friend.bzl
@@ -0,0 +1,63 @@
+# Copyright 2022 Google LLC. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the License);
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""is_eligible_friend"""
+
+load("//:visibility.bzl", "RULES_DEFS_THAT_COMPILE_KOTLIN")
+
+def is_eligible_friend(target, friend):
+ """
+ Determines if `target` is allowed to use `internal` members of `friend`
+
+ To be eligible, one of:
+ 1. `target` and `friend` in same pkg
+ 2. `target` in `testing/` subpkg of `friend` pkg
+ 3. `target` in `javatests/` pkg, `friend` in parallel `java/` pkg
+ 4. `target` in `test/java/` pkg, `friend` in parallel `main/java/` pkg
+
+ Args:
+ target: (Target) The current target
+ friend: (Target) A potential friend of `target`
+
+ Returns:
+ True if `friend` is an eligible friend of `target`.
+ """
+
+ target_pkg = target.label.package + "/"
+ friend_pkg = friend.label.package + "/"
+
+ if target_pkg == friend_pkg:
+ # Case 1
+ return True
+
+ if target_pkg.removesuffix("testing/") == friend_pkg:
+ # Case 2
+ return True
+
+ if "javatests/" in target_pkg and "java/" in friend_pkg:
+ # Case 3
+ target_java_pkg = target_pkg.rsplit("javatests/", 1)[1]
+ friend_java_pkg = friend_pkg.rsplit("java/", 1)[1]
+ if target_java_pkg == friend_java_pkg:
+ return True
+
+ if ("test/java/" in target_pkg and "main/java/" in friend_pkg and
+ True):
+ # Case 4
+ target_split = target_pkg.rsplit("test/java/", 1)
+ friend_split = friend_pkg.rsplit("main/java/", 1)
+ if target_split == friend_split:
+ return True
+
+ return False
diff --git a/kotlin/compiler_plugin.bzl b/kotlin/compiler_plugin.bzl
index 15b7ff7..5df6e68 100644
--- a/kotlin/compiler_plugin.bzl
+++ b/kotlin/compiler_plugin.bzl
@@ -16,17 +16,16 @@
load("//:visibility.bzl", "RULES_KOTLIN")
-_KtCompilerPluginInfo = provider(
+KtCompilerPluginInfo, _make_kt_compiler_plugin_info = provider(
doc = "Info for running a plugin that directly registers itself to kotlinc extension points",
fields = dict(
plugin_id = "string",
jar = "File",
args = "list[string]",
),
+ init = fail,
)
-KtCompilerPluginInfo, _make_kt_compiler_plugin_info = (_KtCompilerPluginInfo, _KtCompilerPluginInfo)
-
def _kt_compiler_plugin_impl(ctx):
return [
diff --git a/kotlin/jvm/internal_do_not_use/traverse_exports/BUILD b/kotlin/jvm/internal_do_not_use/traverse_exports/BUILD
index 6db3c1e..0f39dbe 100644
--- a/kotlin/jvm/internal_do_not_use/traverse_exports/BUILD
+++ b/kotlin/jvm/internal_do_not_use/traverse_exports/BUILD
@@ -14,7 +14,9 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
-package(default_visibility = ["//:internal"])
+package(
+ default_visibility = ["//:internal"],
+)
licenses(["notice"])
@@ -24,6 +26,7 @@ bzl_library(
deps = [
"//:visibility_bzl",
"//kotlin:for_traverse_exports_bzl",
+ "//kotlin/common:common_bzl",
"@bazel_skylib//lib:sets",
],
)
diff --git a/kotlin/jvm/internal_do_not_use/traverse_exports/friend_jars.bzl b/kotlin/jvm/internal_do_not_use/traverse_exports/friend_jars.bzl
index 68cf1a6..3f89905 100644
--- a/kotlin/jvm/internal_do_not_use/traverse_exports/friend_jars.bzl
+++ b/kotlin/jvm/internal_do_not_use/traverse_exports/friend_jars.bzl
@@ -12,55 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-"""kt_friend_visitor"""
+"""kt_friend_jars_visitor"""
+# go/keep-sorted start
+load("//kotlin/common:is_eligible_friend.bzl", "is_eligible_friend")
load("//:visibility.bzl", "RULES_KOTLIN")
-
-def is_eligible_friend(target, friend):
- """
- Determines if `target` is allowed to use `internal` members of `friend`
-
- To be eligible, one of:
- 1. `target` and `friend` in same pkg
- 2. `target` in `testing/` subpkg of `friend` pkg
- 3. `target` in `javatests/` pkg, `friend` in parallel `java/` pkg
- 4. `target` in `test/java/` pkg, `friend` in parallel `main/java/` pkg
-
- Args:
- target: (Target) The current target
- friend: (Target) A potential friend of `target`
-
- Returns:
- True if `friend` is an eligible friend of `target`.
- """
-
- target_pkg = target.label.package + "/"
- friend_pkg = friend.label.package + "/"
-
- if target_pkg == friend_pkg:
- # Case 1
- return True
-
- if target_pkg.removesuffix("testing/") == friend_pkg:
- # Case 2
- return True
-
- if "javatests/" in target_pkg and "java/" in friend_pkg:
- # Case 3
- target_java_pkg = target_pkg.rsplit("javatests/", 1)[1]
- friend_java_pkg = friend_pkg.rsplit("java/", 1)[1]
- if target_java_pkg == friend_java_pkg:
- return True
-
- if ("test/java/" in target_pkg and "main/java/" in friend_pkg and
- True):
- # Case 4
- target_split = target_pkg.rsplit("test/java/", 1)
- friend_split = friend_pkg.rsplit("main/java/", 1)
- if target_split == friend_split:
- return True
-
- return False
+# go/keep-sorted end
def _get_output_jars(target, _ctx_rule):
# We can't simply use `JavaInfo.compile_jars` because we only want the JARs directly created by
@@ -74,14 +31,3 @@ kt_friend_jars_visitor = struct(
finish_expansion = None,
process_unvisited_target = None,
)
-
-def _get_output_labels(target, _):
- return [target.label]
-
-kt_friend_labels_visitor = struct(
- name = "friend_labels",
- visit_target = _get_output_labels,
- filter_edge = is_eligible_friend,
- finish_expansion = None,
- process_unvisited_target = None,
-)
diff --git a/kotlin/jvm/internal_do_not_use/traverse_exports/friend_labels.bzl b/kotlin/jvm/internal_do_not_use/traverse_exports/friend_labels.bzl
new file mode 100644
index 0000000..ef0aacd
--- /dev/null
+++ b/kotlin/jvm/internal_do_not_use/traverse_exports/friend_labels.bzl
@@ -0,0 +1,31 @@
+# Copyright 2022 Google LLC. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the License);
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""kt_friend_labels_visitor"""
+
+# go/keep-sorted start
+load("//kotlin/common:is_eligible_friend.bzl", "is_eligible_friend")
+load("//:visibility.bzl", "RULES_KOTLIN")
+# go/keep-sorted end
+
+def _get_output_labels(target, _):
+ return [target.label]
+
+kt_friend_labels_visitor = struct(
+ name = "friend_labels",
+ visit_target = _get_output_labels,
+ filter_edge = is_eligible_friend,
+ finish_expansion = None,
+ process_unvisited_target = None,
+)
diff --git a/kotlin/jvm/internal_do_not_use/traverse_exports/traverse_exports.bzl b/kotlin/jvm/internal_do_not_use/traverse_exports/traverse_exports.bzl
index f0f9e6a..edf2a10 100644
--- a/kotlin/jvm/internal_do_not_use/traverse_exports/traverse_exports.bzl
+++ b/kotlin/jvm/internal_do_not_use/traverse_exports/traverse_exports.bzl
@@ -14,12 +14,15 @@
"""Combined aspect for all rules_kotlin behaviours that need to traverse exports."""
+# go/keep-sorted start
+load("//:visibility.bzl", "RULES_KOTLIN")
load(":compiler_plugin.bzl", "kt_compiler_plugin_visitor")
load(":direct_jdeps.bzl", "kt_direct_jdeps_visitor")
load(":forbidden_deps.bzl", "kt_forbidden_deps_visitor")
-load(":friend_jars.bzl", "kt_friend_jars_visitor", "kt_friend_labels_visitor")
+load(":friend_jars.bzl", "kt_friend_jars_visitor")
+load(":friend_labels.bzl", "kt_friend_labels_visitor")
load(":java_plugin.bzl", "java_plugin_visitor")
-load("//:visibility.bzl", "RULES_KOTLIN")
+# go/keep-sorted end
# java_xxx_proto_library don't populate java_outputs but we can get them through
# required_aspect_providers from their proto_library deps.
diff --git a/kotlin/jvm/internal_do_not_use/util/BUILD b/kotlin/jvm/internal_do_not_use/util/BUILD
index bcfec8d..7e82771 100644
--- a/kotlin/jvm/internal_do_not_use/util/BUILD
+++ b/kotlin/jvm/internal_do_not_use/util/BUILD
@@ -14,7 +14,9 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
-package(default_visibility = ["//:internal"])
+package(
+ default_visibility = ["//:internal"],
+)
licenses(["notice"])
@@ -23,6 +25,7 @@ bzl_library(
srcs = glob(["*.bzl"]),
deps = [
"//:visibility_bzl",
+ "//toolchains/kotlin_jvm:toolchain_bzl",
"@bazel_tools//tools/jdk:jvmopts",
],
)
diff --git a/kotlin/jvm/internal_do_not_use/util/class_file_selectors.bzl b/kotlin/jvm/internal_do_not_use/util/class_file_selectors.bzl
index d5341c8..d3647d3 100644
--- a/kotlin/jvm/internal_do_not_use/util/class_file_selectors.bzl
+++ b/kotlin/jvm/internal_do_not_use/util/class_file_selectors.bzl
@@ -15,6 +15,7 @@
"""Selects bytecode class files with a matched source file in srcjars."""
load("//:visibility.bzl", "RULES_KOTLIN")
+load("//toolchains/kotlin_jvm:kt_jvm_toolchains.bzl", "kt_jvm_toolchains")
def gen_java_info_generated_class_jar(ctx, file_factory, kt_toolchain, input_jars, srcjars):
"""Generates a class jar with class file jar entries matching files in the give srcjars.
@@ -53,5 +54,6 @@ def gen_java_info_generated_class_jar(ctx, file_factory, kt_toolchain, input_jar
progress_message = "Generating JavaInfo.generated_class_jar into %{output}",
mnemonic = "ClassFileSelectorBySourceFile",
executable = jar_transformer,
+ toolchain = kt_jvm_toolchains.type,
)
return output_jar
diff --git a/kotlin/jvm_compile.bzl b/kotlin/jvm_compile.bzl
index 07d1400..ba3da82 100644
--- a/kotlin/jvm_compile.bzl
+++ b/kotlin/jvm_compile.bzl
@@ -151,7 +151,10 @@ def kt_jvm_compile(
coverage_srcs = coverage_srcs,
deps = r_java_infos + java_infos,
disable_lint_checks = disable_lint_checks,
- exported_plugins = [e[JavaPluginInfo] for e in exported_plugins if (JavaPluginInfo in e)],
+ exported_plugins = common.kt_plugins_map(
+ java_plugin_infos = common.collect_providers(JavaPluginInfo, exported_plugins),
+ android_lint_rulesets = common.collect_providers(lint_actions.AndroidLintRulesetInfo, exported_plugins),
+ ),
# Not all exported targets contain a JavaInfo (e.g. some only have CcInfo)
exports = r_java_infos + [e[JavaInfo] for e in exports if JavaInfo in e],
friend_jars = kt_traverse_exports.expand_friend_jars(deps, root = ctx),
@@ -167,29 +170,17 @@ def kt_jvm_compile(
output = output,
output_srcjar = output_srcjar,
plugins = common.kt_plugins_map(
- android_lint_singlejar_plugins = depset(
- transitive = [android_lint_rules_jars] + [
- p[lint_actions.AndroidLintRulesetInfo].singlejars
- for p in android_lint_plugins
- if (lint_actions.AndroidLintRulesetInfo in p)
- ],
- ),
- android_lint_libjar_plugin_infos = [
- p[JavaInfo]
- for p in android_lint_plugins
- if (JavaInfo in p)
+ android_lint_rulesets = (
+ common.collect_providers(lint_actions.AndroidLintRulesetInfo, android_lint_plugins) +
+ common.collect_providers(lint_actions.AndroidLintRulesetInfo, plugins)
+ ) + [
+ lint_actions.AndroidLintRulesetInfo(singlejars = android_lint_rules_jars),
],
- java_plugin_infos = [
- plugin[JavaPluginInfo]
- for plugin in plugins
- if JavaPluginInfo in plugin
- ],
- kt_compiler_plugin_infos =
- kt_traverse_exports.expand_compiler_plugins(deps).to_list() + [
- plugin[KtCompilerPluginInfo]
- for plugin in plugins
- if (KtCompilerPluginInfo in plugin)
- ],
+ java_plugin_infos = common.collect_providers(JavaPluginInfo, plugins),
+ kt_compiler_plugin_infos = (
+ kt_traverse_exports.expand_compiler_plugins(deps).to_list() +
+ common.collect_providers(KtCompilerPluginInfo, plugins)
+ ),
),
resource_files = resource_files,
runtime_deps = [d[JavaInfo] for d in runtime_deps if JavaInfo in d],
diff --git a/kotlin/jvm_import.bzl b/kotlin/jvm_import.bzl
index 5f7c6ed..72b5f6e 100644
--- a/kotlin/jvm_import.bzl
+++ b/kotlin/jvm_import.bzl
@@ -138,7 +138,7 @@ kt_jvm_import = rule(
fragments = ["java"],
provides = [JavaInfo],
implementation = _kt_jvm_import_impl,
- toolchains = [kt_jvm_toolchains.type],
+ toolchains = [kt_jvm_toolchains.type, "@bazel_tools//tools/jdk:toolchain_type"],
doc = """Allows the use of precompiled Kotlin `.jar` files as deps of `kt_*` targets.
Prefer this rule to `java_import` for Kotlin Jars. Most Java-like libraries
diff --git a/kotlin/jvm_library.internal.bzl b/kotlin/jvm_library.internal.bzl
index b7291d8..5625bdd 100644
--- a/kotlin/jvm_library.internal.bzl
+++ b/kotlin/jvm_library.internal.bzl
@@ -165,6 +165,7 @@ _KT_JVM_LIBRARY_ATTRS = dicts.add(
providers = [
[JavaPluginInfo],
[KtCompilerPluginInfo],
+ [lint_actions.AndroidLintRulesetInfo],
],
cfg = "exec",
doc = """JVM plugins to export to users.
@@ -199,6 +200,7 @@ _KT_JVM_LIBRARY_ATTRS = dicts.add(
providers = [
[JavaPluginInfo],
[KtCompilerPluginInfo],
+ [lint_actions.AndroidLintRulesetInfo],
],
cfg = "exec",
doc = """JVM plugins to run during compilation.
@@ -234,11 +236,9 @@ _KT_JVM_LIBRARY_ATTRS = dicts.add(
To support circular dependencies, this can include `.kt` and `.java` files.""",
),
_android_lint_plugins = attr.label_list(
- providers = [
- [JavaInfo],
- [lint_actions.AndroidLintRulesetInfo],
- ],
+ providers = [lint_actions.AndroidLintRulesetInfo],
cfg = "exec",
+ doc = """Additional Android Lint checks to run at compile-time.""",
),
)
@@ -251,7 +251,7 @@ kt_jvm_library_helper = rule(
),
provides = [JavaInfo],
implementation = _jvm_library_impl,
- toolchains = [kt_jvm_toolchains.type],
+ toolchains = [kt_jvm_toolchains.type, "@bazel_tools//tools/jdk:toolchain_type"],
doc = """This rule compiles Kotlin (and Java) sources into a Jar file. Most Java-like libraries
and binaries can depend on this rule, and this rule can in turn depend on Kotlin and
Java libraries. This rule supports a subset of attributes supported by `java_library`.
diff --git a/tests/analysis/jvm_compile_test.bzl b/tests/analysis/jvm_compile_test.bzl
index a8fd460..83e722c 100644
--- a/tests/analysis/jvm_compile_test.bzl
+++ b/tests/analysis/jvm_compile_test.bzl
@@ -86,7 +86,7 @@ _kt_jvm_compile = rule(
outputs = dict(
jar = "lib%{name}.jar",
),
- toolchains = [kt_jvm_toolchains.type],
+ toolchains = [kt_jvm_toolchains.type, "@bazel_tools//tools/jdk:toolchain_type"],
)
def _test_kt_jvm_compile_using_kt_jvm_compile_with_r_java():
diff --git a/tests/analysis/jvm_library/data/BUILD b/tests/analysis/jvm_library/data/BUILD
index 1809aa1..e92a2e8 100644
--- a/tests/analysis/jvm_library/data/BUILD
+++ b/tests/analysis/jvm_library/data/BUILD
@@ -15,19 +15,19 @@
load("//tests/analysis:for_test.bzl", "rules_for_test")
load("//tests/analysis:jvm_library_test.bzl", "jvm_library_test")
-package(default_testonly = True)
+package(
+ default_testonly = True,
+)
licenses(["notice"])
jvm_library_test(
name = "data_test",
- expected = dict(
- data = [
- "data.txt",
- # libX.jar is always in data_runfiles as well - just append it.
- "libdata.jar",
- ],
- ),
+ expected_runfile_names = [
+ "data.txt",
+ # libX.jar is always in data_runfiles as well - just append it.
+ "libdata.jar",
+ ],
target_under_test = rules_for_test.kt_jvm_library(
name = "data",
srcs = [
diff --git a/tests/analysis/jvm_library/deps/BUILD b/tests/analysis/jvm_library/deps/BUILD
index ccb03a0..6db53bd 100644
--- a/tests/analysis/jvm_library/deps/BUILD
+++ b/tests/analysis/jvm_library/deps/BUILD
@@ -15,7 +15,9 @@
load("//tests/analysis:for_test.bzl", "rules_for_test")
load("//tests/analysis:jvm_library_test.bzl", "jvm_library_test")
-package(default_testonly = True)
+package(
+ default_testonly = True,
+)
licenses(["notice"])
diff --git a/tests/analysis/jvm_library/no_java_srcs/BUILD b/tests/analysis/jvm_library/no_java_srcs/BUILD
index 116dcfd..f149c73 100644
--- a/tests/analysis/jvm_library/no_java_srcs/BUILD
+++ b/tests/analysis/jvm_library/no_java_srcs/BUILD
@@ -15,7 +15,9 @@
load("//tests/analysis:for_test.bzl", "rules_for_test")
load("//tests/analysis:jvm_library_test.bzl", "jvm_library_test")
-package(default_testonly = True)
+package(
+ default_testonly = True,
+)
licenses(["notice"])
diff --git a/tests/analysis/jvm_library/no_kt_srcs/BUILD b/tests/analysis/jvm_library/no_kt_srcs/BUILD
index a6e4f18..d5aafcd 100644
--- a/tests/analysis/jvm_library/no_kt_srcs/BUILD
+++ b/tests/analysis/jvm_library/no_kt_srcs/BUILD
@@ -15,7 +15,9 @@
load("//tests/analysis:for_test.bzl", "rules_for_test")
load("//tests/analysis:jvm_library_test.bzl", "jvm_library_test")
-package(default_testonly = True)
+package(
+ default_testonly = True,
+)
licenses(["notice"])
diff --git a/tests/analysis/jvm_library/nodeps/BUILD b/tests/analysis/jvm_library/nodeps/BUILD
index fc3e673..f2ae73b 100644
--- a/tests/analysis/jvm_library/nodeps/BUILD
+++ b/tests/analysis/jvm_library/nodeps/BUILD
@@ -15,7 +15,9 @@
load("//tests/analysis:for_test.bzl", "rules_for_test")
load("//tests/analysis:jvm_library_test.bzl", "jvm_library_test")
-package(default_testonly = True)
+package(
+ default_testonly = True,
+)
licenses(["notice"])
diff --git a/tests/analysis/jvm_library/only_common_srcs/BUILD b/tests/analysis/jvm_library/only_common_srcs/BUILD
index 49930f2..aae3068 100644
--- a/tests/analysis/jvm_library/only_common_srcs/BUILD
+++ b/tests/analysis/jvm_library/only_common_srcs/BUILD
@@ -15,7 +15,9 @@
load("//tests/analysis:for_test.bzl", "rules_for_test")
load("//tests/analysis:jvm_library_test.bzl", "jvm_library_test")
-package(default_testonly = True)
+package(
+ default_testonly = True,
+)
licenses(["notice"])
diff --git a/tests/analysis/jvm_library/runtime_deps/BUILD b/tests/analysis/jvm_library/runtime_deps/BUILD
index 17457ba..85f8b55 100644
--- a/tests/analysis/jvm_library/runtime_deps/BUILD
+++ b/tests/analysis/jvm_library/runtime_deps/BUILD
@@ -15,7 +15,9 @@
load("//tests/analysis:for_test.bzl", "rules_for_test")
load("//tests/analysis:jvm_library_test.bzl", "jvm_library_test")
-package(default_testonly = True)
+package(
+ default_testonly = True,
+)
licenses(["notice"])
diff --git a/tests/analysis/jvm_library/treeartifacts_srcs/BUILD b/tests/analysis/jvm_library/treeartifacts_srcs/BUILD
index 3d724c4..2ba8ecf 100644
--- a/tests/analysis/jvm_library/treeartifacts_srcs/BUILD
+++ b/tests/analysis/jvm_library/treeartifacts_srcs/BUILD
@@ -17,7 +17,9 @@ load("//tests/analysis:assert_failure_test.bzl", "assert_failure_test")
load("//tests/analysis:jvm_library_test.bzl", "jvm_library_test")
load("//tests/analysis:util.bzl", "create_dir")
-package(default_testonly = True)
+package(
+ default_testonly = True,
+)
licenses(["notice"])
diff --git a/tests/analysis/jvm_library_test.bzl b/tests/analysis/jvm_library_test.bzl
index d51e6e1..b43ee3e 100644
--- a/tests/analysis/jvm_library_test.bzl
+++ b/tests/analysis/jvm_library_test.bzl
@@ -27,7 +27,6 @@ def _test_impl(ctx):
env = analysistest.begin(ctx)
actions = analysistest.target_actions(env)
actual = ctx.attr.target_under_test
- expected = ctx.attr.expected
asserts.true(
env,
@@ -40,49 +39,46 @@ def _test_impl(ctx):
"Expected a ProguardSpecProvider provider.",
)
- if "data" in expected:
- expected_data = expected["data"]
- actual_data = _extract_data_runfiles(actual)
+ if ctx.attr.expected_al_ruleset_names != _DEFAULT_LIST:
+ al_action = get_action(actions, "KtAndroidLint")
+ asserts.set_equals(
+ env,
+ sets.make(ctx.attr.expected_al_ruleset_names),
+ sets.make([
+ a.rsplit("/", 1)[1]
+ for a in get_arg(al_action, "--lint_rules", style = "list")
+ ]),
+ )
- asserts.new_set_equals(
+ if ctx.attr.expected_runfile_names != _DEFAULT_LIST:
+ asserts.set_equals(
env,
- sets.make(expected_data),
- sets.make(actual_data),
- """
- FAIL: kt_jvm_library did not produce the expected data dependencies.
- EXPECTED: %s
- ACTUAL: %s
- """ % (expected_data, actual_data),
+ sets.make(ctx.attr.expected_runfile_names),
+ sets.make([
+ f.basename
+ for f in actual[DefaultInfo].data_runfiles.files.to_list()
+ ]),
)
- expected_exports = []
- for target in ctx.attr.expected_exports:
- asserts.equals(
+ if ctx.attr.expected_compile_jar_names != _DEFAULT_LIST:
+ asserts.set_equals(
env,
- 1,
- len(target[JavaInfo].full_compile_jars.to_list()),
- "Not a single compile-time Jar: %s" % target.label,
+ sets.make(ctx.attr.expected_compile_jar_names),
+ sets.make([f.basename for f in actual[JavaInfo].compile_jars.to_list()]),
+ "kt_jvm_library JavaInfo::compile_jars",
)
- expected_exports.extend(target[JavaInfo].full_compile_jars.to_list())
- actual_exports = actual[JavaInfo].full_compile_jars.to_list()
- # TODO: fail if there are *un*expected exports, maybe by making sure
- # that the actual exports are exactly the expected ones plus the Jar(s)
- # produced by this JavaInfo.
- for expected_export in expected_exports:
- asserts.true(
+ if ctx.attr.expected_exported_processor_jar_names != _DEFAULT_LIST:
+ asserts.set_equals(
env,
- expected_export in actual_exports,
- """
- kt_jvm_library did not export %s
- actual: %s
- """ % (expected_export, actual_exports),
+ sets.make(ctx.attr.expected_exported_processor_jar_names),
+ sets.make([f.basename for f in actual[JavaInfo].plugins.processor_jars.to_list()]),
)
- asserts.equals(
+ asserts.set_equals(
env,
- ctx.attr.expected_exported_processor_classes,
- actual[JavaInfo].plugins.processor_classes.to_list(),
+ sets.make(ctx.attr.expected_exported_processor_classes),
+ sets.make(actual[JavaInfo].plugins.processor_classes.to_list()),
)
kt_2_java_compile = get_action(actions, "Kt2JavaCompile")
@@ -111,8 +107,18 @@ def _test_impl(ctx):
_test = analysistest.make(
impl = _test_impl,
attrs = dict(
- expected = attr.string_list_dict(),
- expected_exports = attr.label_list(),
+ expected_al_ruleset_names = attr.string_list(
+ doc = "Android Lint rule JARs reported as run on the given target",
+ default = _DEFAULT_LIST,
+ ),
+ expected_compile_jar_names = attr.string_list(
+ doc = "Names of all JavaInfo::compile_jars for the given target",
+ default = _DEFAULT_LIST,
+ ),
+ expected_exported_processor_jar_names = attr.string_list(
+ doc = "Names of all JavaInfo.plugins JARs returned by the given target",
+ default = _DEFAULT_LIST,
+ ),
expected_exported_processor_classes = attr.string_list(
doc = "Annotation processors reported as to be run on depending targets",
),
@@ -123,6 +129,10 @@ _test = analysistest.make(
doc = "Names of all -Xfriend-paths= JARs",
default = _DEFAULT_LIST,
),
+ expected_runfile_names = attr.string_list(
+ doc = "Names of all runfiles",
+ default = _DEFAULT_LIST,
+ ),
expect_processor_classpath = attr.bool(),
expect_neverlink = attr.bool(),
),
@@ -154,9 +164,6 @@ _coverage_test = analysistest.make(
},
)
-def _extract_data_runfiles(target):
- return [f.basename for f in target[DefaultInfo].data_runfiles.files.to_list()]
-
def _test_kt_jvm_library_with_proguard_specs():
test_name = "kt_jvm_library_with_proguard_specs_test"
create_file(
@@ -438,9 +445,10 @@ fun greeting(): String = "Hello World!"
_test(
name = test_name,
target_under_test = test_name + "_tut",
- expected_exports = [
- ":%s_exp" % test_name,
- ":%s_javaexp" % test_name,
+ expected_compile_jar_names = [
+ "lib%s_tut-compile.jar" % test_name,
+ "lib%s_exp-compile.jar" % test_name,
+ "lib%s_javaexp-hjar.jar" % test_name,
],
)
return test_name
@@ -475,7 +483,10 @@ fun greeting(): String = "Hello World!"
_test(
name = test_name,
target_under_test = test_name + "_tut",
- expected_exports = [":%s_exports_plugin" % test_name],
+ expected_compile_jar_names = [
+ "lib%s_tut-compile.jar" % test_name,
+ "lib%s_exports_plugin-compile.jar" % test_name,
+ ],
expected_exported_processor_classes = [test_name],
)
return test_name
@@ -509,7 +520,10 @@ fun greeting(): String = "Hello World!"
_test(
name = test_name,
target_under_test = test_name + "_tut",
- expected_exports = [], # _exports_plugin has no compile/runtime Jars
+ expected_compile_jar_names = [
+ # _exports_plugin has no compile/runtime Jars
+ "lib%s_tut-compile.jar" % test_name,
+ ],
expected_exported_processor_classes = [test_name],
)
return test_name
diff --git a/tests/analysis/util.bzl b/tests/analysis/util.bzl
index 5e7e487..50bcc0e 100644
--- a/tests/analysis/util.bzl
+++ b/tests/analysis/util.bzl
@@ -87,12 +87,13 @@ def get_action(actions, mnemonic):
return menmonic_actions[0]
-def get_arg(action, arg_name):
+def get_arg(action, arg_name, style = "trim"):
"""Get a named arg from a specific action
Args:
action: [Optional[Action]]
arg_name: [string]
+ style: [Optional[string]] The style of commandline arg
Returns:
[Optional[string]] The arg value, or None if it couldn't be found
@@ -100,10 +101,22 @@ def get_arg(action, arg_name):
if not action:
return None
- arg_values = [a for a in action.argv if a.startswith(arg_name)]
- if len(arg_values) == 0:
+ args = action.argv
+ matches = [(i, a) for (i, a) in enumerate(args) if a.startswith(arg_name)]
+ if len(matches) == 0:
return None
- elif len(arg_values) > 1:
+ elif len(matches) > 1:
fail("Expected a single '%s' arg" % arg_name)
-
- return arg_values[0][len(arg_name):]
+ (index, arg) = matches[0]
+
+ if style == "trim":
+ return arg[len(arg_name):]
+ elif style == "list":
+ result = []
+ for i in range(index + 1, len(args)):
+ if args[i].startswith("--"):
+ break
+ result.append(args[i])
+ return result
+ else:
+ fail("Unrecognized arg style '%s" % style)
diff --git a/tests/jvm/java/functions/car/BUILD b/tests/jvm/java/functions/car/BUILD
index 5417fd4..6d0578c 100644
--- a/tests/jvm/java/functions/car/BUILD
+++ b/tests/jvm/java/functions/car/BUILD
@@ -14,7 +14,9 @@
load("//kotlin:rules.bzl", "kt_jvm_import", "kt_jvm_library")
-package(default_visibility = ["//tests/jvm/java/functions:__subpackages__"])
+package(
+ default_visibility = ["//tests/jvm/java/functions:__subpackages__"],
+)
licenses(["notice"])
diff --git a/tests/jvm/java/ijar/BUILD b/tests/jvm/java/ijar/BUILD
index d742e75..2f2721b 100644
--- a/tests/jvm/java/ijar/BUILD
+++ b/tests/jvm/java/ijar/BUILD
@@ -16,7 +16,9 @@ load("//kotlin:rules.bzl", "kt_jvm_library")
licenses(["notice"])
-package(default_testonly = 1)
+package(
+ default_testonly = 1,
+)
java_test(
name = "ijar",
diff --git a/tests/jvm/java/jni/BUILD b/tests/jvm/java/jni/BUILD
index 7225ef1..52619d4 100644
--- a/tests/jvm/java/jni/BUILD
+++ b/tests/jvm/java/jni/BUILD
@@ -12,13 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-load(
- "//kotlin:rules.bzl",
- "kt_jvm_library",
- "kt_jvm_test",
-)
+load("//kotlin:rules.bzl", "kt_jvm_library", "kt_jvm_test")
-package(default_testonly = 1)
+package(
+ default_testonly = 1,
+)
licenses(["notice"])
diff --git a/tests/jvm/java/junit/BUILD b/tests/jvm/java/junit/BUILD
index af26b52..0b256c1 100644
--- a/tests/jvm/java/junit/BUILD
+++ b/tests/jvm/java/junit/BUILD
@@ -14,7 +14,9 @@
load("//kotlin:rules.bzl", "kt_jvm_library", "kt_jvm_test")
-package(default_testonly = 1)
+package(
+ default_testonly = 1,
+)
licenses(["notice"])
diff --git a/tests/jvm/java/mockito/BUILD b/tests/jvm/java/mockito/BUILD
index ade78c9..4ee362e 100644
--- a/tests/jvm/java/mockito/BUILD
+++ b/tests/jvm/java/mockito/BUILD
@@ -14,7 +14,9 @@
load("//kotlin:rules.bzl", "kt_jvm_test")
-package(default_testonly = 1)
+package(
+ default_testonly = 1,
+)
licenses(["notice"])
diff --git a/tests/jvm/java/srcartifacts/BUILD b/tests/jvm/java/srcartifacts/BUILD
index 4236672..9d51c82 100644
--- a/tests/jvm/java/srcartifacts/BUILD
+++ b/tests/jvm/java/srcartifacts/BUILD
@@ -16,7 +16,9 @@ load("//kotlin:rules.bzl", "kt_jvm_library", "kt_jvm_test")
load("//tests/analysis:util.bzl", "create_dir", "create_file")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
-package(default_testonly = 1)
+package(
+ default_testonly = 1,
+)
licenses(["notice"])
diff --git a/toolchains/kotlin_jvm/BUILD b/toolchains/kotlin_jvm/BUILD
index 587d3a9..1f20159 100644
--- a/toolchains/kotlin_jvm/BUILD
+++ b/toolchains/kotlin_jvm/BUILD
@@ -16,35 +16,60 @@
load(":kt_jvm_toolchains.bzl", "kt_jvm_toolchains")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
+load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
licenses(["notice"])
-package(default_visibility = ["//:internal"])
+package(
+ default_visibility = ["//:internal"],
+)
toolchain_type(name = kt_jvm_toolchains.name)
-# Toolchain resolution must match :kt_jvm_toolchain_impl. Therefore, there's no
-# need for platform-specific toolchain declarations.
toolchain(
- name = "kt_jvm_toolchain",
- toolchain = ":kt_jvm_toolchain_impl",
+ name = "kt_jvm_toolchain_linux",
+ exec_compatible_with = [
+ "@platforms//os:linux",
+ ],
+ toolchain = ":kt_jvm_toolchain_linux_sts_jdk",
toolchain_type = kt_jvm_toolchains.type,
+ visibility = ["//visibility:public"],
)
+# TODO: Remove this once cl/520112558 has made it into an Android rules release
alias(
name = "kt_jvm_toolchain_impl",
- actual = select({
- "@bazel_platforms//os:macos": ":kt_jvm_toolchain_macos_impl",
- "//conditions:default": ":kt_jvm_toolchain_default_impl",
- }),
+ actual = ":kt_jvm_toolchain_linux_sts_jdk",
visibility = ["//visibility:public"],
)
kt_jvm_toolchains.declare(
- name = "kt_jvm_toolchain_macos_impl",
- enable_turbine_direct = False,
+ name = "kt_jvm_toolchain_linux_sts_jdk",
+ # TODO: Required due to magic attribute for DexArchiveAspect, remove once that
+ # attribute is removed.
+ visibility = ["//visibility:public"],
+)
+
+toolchain(
+ name = "kt_jvm_toolchain_macos",
+ exec_compatible_with = [
+ "@platforms//os:macos",
+ ],
+ toolchain = ":kt_jvm_toolchain_no_turbine_darwin_jdk",
+ toolchain_type = kt_jvm_toolchains.type,
+ visibility = ["//visibility:public"],
)
kt_jvm_toolchains.declare(
- name = "kt_jvm_toolchain_default_impl",
+ name = "kt_jvm_toolchain_no_turbine_darwin_jdk",
+ enable_turbine_direct = False,
+)
+
+# Turn on profiling of Kotlin/JVM actions
+#
+# Matches if the value is a substring of the target label. Empty string matches nothing.
+string_flag(
+ name = "profiling_filter",
+ build_setting_default = "",
+ visibility = ["//visibility:private"],
)
diff --git a/toolchains/kotlin_jvm/kt_jvm_toolchains.bzl b/toolchains/kotlin_jvm/kt_jvm_toolchains.bzl
index aaf1093..68bd2cd 100644
--- a/toolchains/kotlin_jvm/kt_jvm_toolchains.bzl
+++ b/toolchains/kotlin_jvm/kt_jvm_toolchains.bzl
@@ -16,13 +16,15 @@
load("//bazel:stubs.bzl", "select_java_language_level")
load("//:visibility.bzl", "RULES_DEFS_THAT_COMPILE_KOTLIN")
+load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
# Work around to toolchains in Google3.
+# buildifier: disable=provider-params
KtJvmToolchainInfo = provider()
-KT_VERSION = "v1_8_10"
+KT_VERSION = "v1_9_0"
-KT_LANG_VERSION = "1.8"
+KT_LANG_VERSION = "1.9"
# Kotlin JVM toolchain type label
_TYPE = Label("//toolchains/kotlin_jvm:kt_jvm_toolchain_type")
@@ -103,35 +105,40 @@ def _kotlinc_cli_flags(ctx):
"-nowarn",
])
+def _opt_for_test(val, getter):
+ return getter(val) if val else None
+
def _kt_jvm_toolchain_impl(ctx):
+ profiling_filter = ctx.attr.profiling_filter[BuildSettingInfo].value
+
kt_jvm_toolchain = dict(
+ # go/keep-sorted start
android_java8_apis_desugared = ctx.attr.android_java8_apis_desugared,
android_lint_config = ctx.file.android_lint_config,
android_lint_runner = ctx.attr.android_lint_runner[DefaultInfo].files_to_run,
build_marker = ctx.file.build_marker,
coverage_instrumenter = ctx.attr.coverage_instrumenter[DefaultInfo].files_to_run,
- # Don't require JavaInfo provider for integration test convenience.
- coverage_runtime = ctx.attr.coverage_runtime[JavaInfo] if JavaInfo in ctx.attr.coverage_runtime else None,
+ coverage_runtime = _opt_for_test(ctx.attr.coverage_runtime, lambda x: x[JavaInfo]),
genclass = ctx.file.genclass,
- header_gen_tool = ctx.attr.header_gen_tool[DefaultInfo].files_to_run if ctx.attr.header_gen_tool else None,
+ header_gen_tool = _opt_for_test(ctx.attr.header_gen_tool, lambda x: x[DefaultInfo].files_to_run),
+ is_profiling_enabled = lambda label: profiling_filter and (profiling_filter in str(label)),
java_language_version = ctx.attr.java_language_version,
java_runtime = ctx.attr.java_runtime,
jvm_abi_gen_plugin = ctx.file.jvm_abi_gen_plugin,
jvm_target = ctx.attr.jvm_target,
- kotlin_annotation_processing = ctx.file.kotlin_annotation_processing,
kotlin_compiler = ctx.attr.kotlin_compiler[DefaultInfo].files_to_run,
kotlin_language_version = ctx.attr.kotlin_language_version,
- kotlin_libs = [JavaInfo(compile_jar = jar, output_jar = jar) for jar in ctx.files.kotlin_libs],
- kt_codegen_java_runtime = ctx.attr.kt_codegen_java_runtime,
+ kotlin_libs = [x[JavaInfo] for x in ctx.attr.kotlin_libs],
kotlin_sdk_libraries = ctx.attr.kotlin_sdk_libraries,
kotlinc_cli_flags = _kotlinc_cli_flags(ctx),
kotlinc_ide_flags = _kotlinc_ide_flags(ctx),
+ kt_codegen_java_runtime = ctx.attr.kt_codegen_java_runtime,
proguard_whitelister = ctx.attr.proguard_whitelister[DefaultInfo].files_to_run,
source_jar_zipper = ctx.file.source_jar_zipper,
turbine = ctx.file.turbine,
- turbine_direct = ctx.file.turbine_direct if ctx.attr.enable_turbine_direct else None,
- turbine_jsa = ctx.file.turbine_jsa,
+ turbine_direct = _opt_for_test(ctx.attr.turbine_direct, lambda x: x[DefaultInfo].files_to_run),
turbine_java_runtime = ctx.attr.turbine_java_runtime,
+ # go/keep-sorted end
)
return [
platform_common.ToolchainInfo(**kt_jvm_toolchain),
@@ -197,11 +204,6 @@ kt_jvm_toolchain = rule(
jvm_target = attr.string(
doc = "The value to pass as -jvm-target, indicating the bytecode format to emit.",
),
- kotlin_annotation_processing = attr.label(
- default = "@kotlinc//:kotlin_annotation_processing",
- cfg = "exec",
- allow_single_file = True,
- ),
kotlin_compiler = attr.label(
default = "@kotlinc//:kotlin_compiler",
cfg = "exec",
@@ -216,7 +218,6 @@ kt_jvm_toolchain = rule(
"@kotlinc//:kotlin_stdlib",
"@kotlinc//:annotations",
],
- allow_files = [".jar"],
cfg = "target",
),
kotlin_sdk_libraries = attr.label_list(
@@ -228,6 +229,13 @@ kt_jvm_toolchain = rule(
],
cfg = "target",
),
+ kt_codegen_java_runtime = attr.label(
+ cfg = "exec",
+ ),
+ profiling_filter = attr.label(
+ default = "//toolchains/kotlin_jvm:profiling_filter",
+ providers = [BuildSettingInfo],
+ ),
proguard_whitelister = attr.label(
default = "@bazel_tools//tools/jdk:proguard_whitelister",
cfg = "exec",
@@ -258,16 +266,9 @@ kt_jvm_toolchain = rule(
cfg = "exec",
allow_single_file = True,
),
- turbine_jsa = attr.label(
- cfg = "exec",
- allow_single_file = True,
- ),
turbine_java_runtime = attr.label(
cfg = "exec",
),
- kt_codegen_java_runtime = attr.label(
- cfg = "exec",
- ),
),
provides = [platform_common.ToolchainInfo],
implementation = _kt_jvm_toolchain_impl,
@@ -288,7 +289,7 @@ _ATTRS = dict(
_toolchain = attr.label(
# TODO: Delete this attr when fixed.
doc = "Magic attribute name for DexArchiveAspect (b/78647825)",
- default = "//toolchains/kotlin_jvm:kt_jvm_toolchain_impl",
+ default = "//toolchains/kotlin_jvm:kt_jvm_toolchain_linux_sts_jdk",
),
)
diff --git a/tools/BUILD b/tools/BUILD
index 02f945c..812302f 100644
--- a/tools/BUILD
+++ b/tools/BUILD
@@ -17,7 +17,9 @@ load("//bazel:deploy_jar_freshness_golden_test.bzl", "deploy_jar_freshness_golde
licenses(["notice"])
-package(default_visibility = ["//:internal"])
+package(
+ default_visibility = ["//:internal"],
+)
# JAR that contains a marker entry, for identifying apps built by rules_kotlin.
genrule(
diff --git a/tools/bin/source_jar_zipper_deploy.jar b/tools/bin/source_jar_zipper_deploy.jar
index 8c6309e..b181e8a 100755
--- a/tools/bin/source_jar_zipper_deploy.jar
+++ b/tools/bin/source_jar_zipper_deploy.jar
Binary files differ
diff --git a/tools/java/com/google/devtools/kotlin/BUILD b/tools/java/com/google/devtools/kotlin/BUILD
index 544536b..0b7a223 100644
--- a/tools/java/com/google/devtools/kotlin/BUILD
+++ b/tools/java/com/google/devtools/kotlin/BUILD
@@ -16,7 +16,9 @@
load("//kotlin:rules.bzl", "kt_jvm_library")
-package(default_visibility = ["//:internal"])
+package(
+ default_visibility = ["//:internal"],
+)
licenses(["notice"])
diff --git a/tools/java/com/google/devtools/kotlin/SourceJarZipper.kt b/tools/java/com/google/devtools/kotlin/SourceJarZipper.kt
index c2d34d8..2ad7568 100644
--- a/tools/java/com/google/devtools/kotlin/SourceJarZipper.kt
+++ b/tools/java/com/google/devtools/kotlin/SourceJarZipper.kt
@@ -22,6 +22,7 @@ import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.StandardCopyOption
+import java.time.LocalDateTime
import java.util.zip.ZipEntry
import java.util.zip.ZipInputStream
import java.util.zip.ZipOutputStream
@@ -41,6 +42,7 @@ import picocli.CommandLine.Spec
)
class SourceJarZipper : Runnable {
@Spec private lateinit var spec: CommandSpec
+
override fun run() {
throw ParameterException(spec.commandLine(), "Specify a command: zip, zip_resources or unzip")
}
@@ -85,6 +87,9 @@ private fun clearSingletonEmptyPath(list: MutableList<Path>) {
}
}
+// Normalize timestamps
+val DEFAULT_TIMESTAMP = LocalDateTime.of(2010, 1, 1, 0, 0, 0)
+
fun MutableMap<Path, Path>.writeToStream(
zipper: ZipOutputStream,
prefix: String = "",
@@ -92,7 +97,7 @@ fun MutableMap<Path, Path>.writeToStream(
for ((zipPath, sourcePath) in this) {
BufferedInputStream(Files.newInputStream(sourcePath)).use { inputStream ->
val entry = ZipEntry(Paths.get(prefix).resolve(zipPath).toString())
- entry.time = 0
+ entry.timeLocal = DEFAULT_TIMESTAMP
zipper.putNextEntry(entry)
inputStream.copyTo(zipper, bufferSize = 1024)
}
@@ -125,9 +130,11 @@ class Zip : Runnable {
)
val commonSrcs = mutableListOf<Path>()
- companion object {
+ private companion object {
const val PACKAGE_SPACE = "package "
- val PACKAGE_NAME_REGEX = "[a-zA-Z][a-zA-Z0-9_]*(\\.[a-zA-Z0-9_]+)*".toRegex()
+ // can't start with digit and can't be all underscores
+ val IDENTIFIER_REGEX = Regex("(?:[a-zA-Z]|_+[a-zA-Z0-9])\\w*")
+ val PACKAGE_NAME_REGEX = Regex("$IDENTIFIER_REGEX(?:\\.$IDENTIFIER_REGEX)*")
}
override fun run() {
@@ -149,9 +156,14 @@ class Zip : Runnable {
// Kotlin allows usage of reserved words in package names framing them
// with backquote symbol "`"
val packageName =
- line.substring(PACKAGE_SPACE.length).trim().replace(";", "").replace("`", "")
+ line
+ .removePrefix(PACKAGE_SPACE)
+ .substringBefore("//")
+ .trim()
+ .removeSuffix(";")
+ .replace(Regex("\\B`(.+?)`\\B"), "$1")
if (!PACKAGE_NAME_REGEX.matches(packageName)) {
- errors.add("${this} contains an invalid package name")
+ errors.add("$this contains an invalid package name")
return this.fileName
}
return Paths.get(packageName.replace(".", "/")).resolve(this.fileName)