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

deploy_jar creation uses args file to support long classpaths #942

Merged
merged 3 commits into from
Jan 19, 2020
Merged
Show file tree
Hide file tree
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
22 changes: 15 additions & 7 deletions scala/private/phases/phase_merge_jars.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,27 @@ def phase_merge_jars(ctx, p):
Use --compression to reduce size of deploy jars.
"""
deploy_jar = ctx.outputs.deploy_jar
jars_list = p.compile.rjars.to_list()
runtime_jars = p.compile.rjars
main_class = getattr(ctx.attr, "main_class", "")
progress_message = "Merging Scala jar: %s" % ctx.label
args = ["--compression", "--normalize", "--sources"]
args.extend([j.path for j in jars_list])
args = ctx.actions.args()
args.add_all(["--compression", "--normalize", "--sources"])
args.add_all(runtime_jars, map_each = _fileToPath)

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

args.set_param_file_format("multiline")
args.use_param_file("@%s")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is that trick?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed :) I think it's not really clear why we need this param though so I opened this bazel issue bazelbuild/bazel#10616

ctx.actions.run(
inputs = jars_list,
inputs = runtime_jars,
outputs = [deploy_jar],
executable = ctx.executable._singlejar,
mnemonic = "ScalaDeployJar",
progress_message = progress_message,
arguments = args,
arguments = [args],
)

def _fileToPath(file):
return file.path
11 changes: 8 additions & 3 deletions test/src/main/scala/scalarules/test/large_classpath/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//scala:scala.bzl", "scala_binary")
load("//scala:scala.bzl", "scala_binary", "scala_library")
load(":helper.bzl", "create_dependencies", "get_dependency_labels")

scala_binary(
Expand All @@ -8,12 +8,17 @@ scala_binary(
unused_dependency_checker_mode = "off",
visibility = ["//visibility:public"],
deps = get_dependency_labels(
amount = 250,
amount = 1000,
length = 20,
),
)

scala_library(
name = "triggerDeployJarCreation",
data = [":largeClasspath_deploy.jar"],
)

create_dependencies(
amount = 250,
amount = 1000,
length = 20,
)