Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phase_merge_jars: refactor to separate function that merges jars to o… #1403

Merged
merged 1 commit into from
Dec 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions scala/private/phases/phase_merge_jars.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,38 @@
# DOCUMENT THIS
#

def phase_merge_jars(ctx, p):
def merge_jars_to_output(ctx, output, jars):
"""Calls Bazel's singlejar utility.
For a full list of available command line options see:
https://github.com/bazelbuild/bazel/blob/697d219526bffbecd29f29b402c9122ec5d9f2ee/src/java_tools/singlejar/java/com/google/devtools/build/singlejar/SingleJar.java#L337
Use --compression to reduce size of deploy jars.
"""
deploy_jar = ctx.outputs.deploy_jar
runtime_jars = p.compile.rjars
main_class = getattr(ctx.attr, "main_class", "")
progress_message = "Merging Scala jar: %s" % ctx.label
progress_message = "Merging Scala jar %s: %s" % (output, ctx.label)
args = ctx.actions.args()
args.add_all(["--compression", "--normalize", "--sources"])
args.add_all(runtime_jars, map_each = _fileToPath)
args.add_all(jars, map_each = _fileToPath)

if main_class:
args.add_all(["--main_class", main_class])
args.add_all(["--output", deploy_jar.path])
args.add_all(["--output", output.path])

args.set_param_file_format("multiline")
args.use_param_file("@%s")
ctx.actions.run(
inputs = runtime_jars,
outputs = [deploy_jar],
inputs = jars,
outputs = [output],
executable = ctx.executable._singlejar,
mnemonic = "ScalaDeployJar",
progress_message = progress_message,
arguments = [args],
)

def phase_merge_jars(ctx, p):
deploy_jar = ctx.outputs.deploy_jar
runtime_jars = p.compile.rjars
merge_jars_to_output(ctx, deploy_jar, runtime_jars)

def _fileToPath(file):
return file.path