Skip to content

Commit

Permalink
deploy_jar creation uses args file to support long classpaths (#942)
Browse files Browse the repository at this point in the history
* deploy_jar creation uses args file to support long classpaths

* allow bazel to not always use param file

* linting
  • Loading branch information
ittaiz authored Jan 19, 2020
1 parent 4833542 commit 4a95548
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
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")
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,
)

0 comments on commit 4a95548

Please sign in to comment.