Skip to content

Commit

Permalink
Remove unused Java runtime dependency of Bazel deploy jar rule
Browse files Browse the repository at this point in the history
Bazel's deploy jar rule never uses the hermetic runtime feature and thus
doesn't need a Java runtime dependency.
  • Loading branch information
fmeum committed Aug 1, 2023
1 parent 404eb64 commit 09ca59f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ def _bazel_deploy_jars_impl(ctx):
build_info_files,
str(ctx.attr.binary.label),
manifest_lines = info.manifest_lines,
hermetic_runtime_support = False,
)

return []

deploy_jars = make_deploy_jars_rule(implementation = _bazel_deploy_jars_impl)
deploy_jars = make_deploy_jars_rule(
implementation = _bazel_deploy_jars_impl,
hermetic_runtime_support = False,
)
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def create_deploy_archives(
build_info_files,
build_target,
hermetic = False,
hermetic_runtime_support = True,
add_exports = depset(),
add_opens = depset(),
shared_archive = None,
Expand All @@ -57,6 +58,7 @@ def create_deploy_archives(
strip_as_default: (bool) Whether to create unstripped deploy jar
build_info_files: ([File]) the artifacts containing workspace status for the current build
hermetic: (bool)
hermetic_runtime_support: (bool)
add_exports: (depset)
add_opens: (depset)
shared_archive: (File) Optional .jsa artifact
Expand Down Expand Up @@ -95,6 +97,7 @@ def create_deploy_archives(
one_version_allowlist = one_version_allowlist,
multi_release = multi_release,
hermetic = hermetic,
hermetic_runtime_support = hermetic_runtime_support,
add_exports = add_exports,
add_opens = add_opens,
extra_args = extra_args,
Expand All @@ -116,6 +119,7 @@ def create_deploy_archives(
output = ctx.outputs.unstrippeddeployjar,
multi_release = multi_release,
hermetic = hermetic,
hermetic_runtime_support = hermetic_runtime_support,
extra_args = extra_args,
)
else:
Expand All @@ -139,6 +143,7 @@ def create_deploy_archive(
one_version_allowlist = None,
multi_release = False,
hermetic = False,
hermetic_runtime_support = True,
add_exports = [],
add_opens = [],
extra_args = []):
Expand Down Expand Up @@ -167,8 +172,6 @@ def create_deploy_archive(
add_opens: (depset)
extra_args: (list[Args]) Optional arguments for the deploy jar action
"""
runtime = semantics.find_java_runtime_toolchain(ctx)

input_files = []
input_files.extend(build_info_files)

Expand Down Expand Up @@ -209,17 +212,21 @@ def create_deploy_archive(
if multi_release:
args.add("--multi_release")

hermetic_files = runtime.hermetic_files
if hermetic and runtime.lib_modules != None and hermetic_files != None:
java_home = runtime.java_home
lib_modules = runtime.lib_modules
args.add("--hermetic_java_home", java_home)
args.add("--jdk_lib_modules", lib_modules)
args.add_all("--resources", hermetic_files)
input_files.append(lib_modules)
if hermetic_runtime_support:
runtime = semantics.find_java_runtime_toolchain(ctx)
hermetic_files = runtime.hermetic_files
if hermetic and runtime.lib_modules != None and hermetic_files != None:
java_home = runtime.java_home
lib_modules = runtime.lib_modules
args.add("--hermetic_java_home", java_home)
args.add("--jdk_lib_modules", lib_modules)
args.add_all("--resources", hermetic_files)
input_files.append(lib_modules)

if shared_archive == None:
shared_archive = runtime.default_cds
if shared_archive == None:
shared_archive = runtime.default_cds
else:
hermetic_files = None

if shared_archive:
input_files.append(shared_archive)
Expand All @@ -233,8 +240,7 @@ def create_deploy_archive(
classpath_resources,
runtime_classpath,
runfiles,
hermetic_files,
])
] + ([hermetic_files] if hermetic_files else []))

ctx.actions.run(
mnemonic = "JavaDeployJar",
Expand All @@ -254,7 +260,7 @@ def _implicit_outputs(binary):
"unstrippeddeployjar": "%s_deploy.jar.unstripped" % binary_name,
}

def make_deploy_jars_rule(implementation):
def make_deploy_jars_rule(implementation, hermetic_runtime_support = True):
"""Creates the deploy jar auxiliary rule for java_binary
Args:
Expand All @@ -274,12 +280,19 @@ def make_deploy_jars_rule(implementation):
),
"_cc_toolchain": attr.label(default = "@" + cc_semantics.get_repo() + "//tools/cpp:current_cc_toolchain"),
"_java_toolchain_type": attr.label(default = semantics.JAVA_TOOLCHAIN_TYPE),
"_java_runtime_toolchain_type": attr.label(default = semantics.JAVA_RUNTIME_TOOLCHAIN_TYPE),
"_build_info_translator": attr.label(
default = semantics.BUILD_INFO_TRANSLATOR_LABEL,
),
},
} | (
{
"_java_runtime_toolchain_type": attr.label(
default = semantics.JAVA_RUNTIME_TOOLCHAIN_TYPE,
),
} if hermetic_runtime_support else {}
),
outputs = _implicit_outputs,
fragments = ["java"],
toolchains = [semantics.JAVA_TOOLCHAIN, semantics.JAVA_RUNTIME_TOOLCHAIN] + cc_helper.use_cpp_toolchain(),
toolchains = [semantics.JAVA_TOOLCHAIN] + cc_helper.use_cpp_toolchain() + (
[semantics.JAVA_RUNTIME_TOOLCHAIN] if hermetic_runtime_support else []
),
)

0 comments on commit 09ca59f

Please sign in to comment.