From fb056bccd02762978c59f9b2c70a669901893229 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 14 Feb 2023 09:13:55 -0800 Subject: [PATCH] Add a `build_target` parameter to deploy jar creation and use the actual `java_binary` target label as it's value This removes dependence on the internal suffix which will differ for `java_test` deploy jars PiperOrigin-RevId: 509548615 Change-Id: I5ed9ad293e83f92cb436a1e63d8b2e36d578a108 --- .../bazel/java/bazel_java_binary_deploy_jar.bzl | 1 + .../builtins_bzl/common/java/java_binary_deploy_jar.bzl | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/starlark/builtins_bzl/bazel/java/bazel_java_binary_deploy_jar.bzl b/src/main/starlark/builtins_bzl/bazel/java/bazel_java_binary_deploy_jar.bzl index 94f01fb589edfa..1bc772a3768709 100644 --- a/src/main/starlark/builtins_bzl/bazel/java/bazel_java_binary_deploy_jar.bzl +++ b/src/main/starlark/builtins_bzl/bazel/java/bazel_java_binary_deploy_jar.bzl @@ -41,6 +41,7 @@ def _bazel_deploy_jars_impl(ctx): info.main_class, info.coverage_main_class, info.strip_as_default, + ctx.attr.binary.label.name, ) return [] diff --git a/src/main/starlark/builtins_bzl/common/java/java_binary_deploy_jar.bzl b/src/main/starlark/builtins_bzl/common/java/java_binary_deploy_jar.bzl index 3eee1943a5f379..67f0432c02edaf 100644 --- a/src/main/starlark/builtins_bzl/common/java/java_binary_deploy_jar.bzl +++ b/src/main/starlark/builtins_bzl/common/java/java_binary_deploy_jar.bzl @@ -34,6 +34,7 @@ def create_deploy_archives( main_class, coverage_main_class, strip_as_default, + build_target, hermetic = False, add_exports = depset(), add_opens = depset(), @@ -51,6 +52,7 @@ def create_deploy_archives( runfiles: (Depset) the runfiles for the deploy jar main_class: (String) FQN of the entry point for execution coverage_main_class: (String) FQN of the entry point for coverage collection + build_target: (String) Name of the build target for stamping strip_as_default: (bool) Whether to create unstripped deploy jar hermetic: (bool) add_exports: (depset) @@ -85,6 +87,7 @@ def create_deploy_archives( runtime_classpath, manifest_lines, build_info_files, + build_target, output = ctx.outputs.deployjar, shared_archive = shared_archive, one_version_level = one_version_level, @@ -108,6 +111,7 @@ def create_deploy_archives( runtime_classpath, manifest_lines, build_info_files, + build_target, output = ctx.outputs.unstrippeddeployjar, multi_release = multi_release, hermetic = hermetic, @@ -127,6 +131,7 @@ def _create_deploy_archive( runtime_classpath, manifest_lines, build_info_files, + build_target, output, shared_archive = None, one_version_level = "OFF", @@ -152,7 +157,7 @@ def _create_deploy_archive( args.set_param_file_format("shell").use_param_file("@%s", use_always = True) args.add("--output", output) - args.add("--build_target", str(ctx.label)[:-len(DEPLOY_JAR_RULE_NAME_SUFFIX)]) + args.add("--build_target", build_target) args.add("--normalize") args.add("--compression") if main_class: