From aa190050e043b9514f868df4c2b655594ea0922e Mon Sep 17 00:00:00 2001 From: Ittai Zeidman Date: Sun, 19 Jan 2020 11:42:07 +0200 Subject: [PATCH 1/3] deploy_jar creation uses args file to support long classpaths --- scala/private/phases/phase_merge_jars.bzl | 22 +++++++++++++------ .../scalarules/test/large_classpath/BUILD | 11 +++++++--- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/scala/private/phases/phase_merge_jars.bzl b/scala/private/phases/phase_merge_jars.bzl index 880c5bd4e..d45f49bb4 100644 --- a/scala/private/phases/phase_merge_jars.bzl +++ b/scala/private/phases/phase_merge_jars.bzl @@ -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", use_always = True) 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 \ No newline at end of file diff --git a/test/src/main/scala/scalarules/test/large_classpath/BUILD b/test/src/main/scala/scalarules/test/large_classpath/BUILD index e9f1415a5..c8cffe27a 100644 --- a/test/src/main/scala/scalarules/test/large_classpath/BUILD +++ b/test/src/main/scala/scalarules/test/large_classpath/BUILD @@ -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( @@ -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, ) From 7453d7cb30af618be7e322a206ffeca83cd94632 Mon Sep 17 00:00:00 2001 From: Ittai Zeidman Date: Sun, 19 Jan 2020 11:43:19 +0200 Subject: [PATCH 2/3] allow bazel to not always use param file --- scala/private/phases/phase_merge_jars.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scala/private/phases/phase_merge_jars.bzl b/scala/private/phases/phase_merge_jars.bzl index d45f49bb4..7df964757 100644 --- a/scala/private/phases/phase_merge_jars.bzl +++ b/scala/private/phases/phase_merge_jars.bzl @@ -24,7 +24,7 @@ def phase_merge_jars(ctx, p): args.add_all(["--output", deploy_jar.path]) args.set_param_file_format("multiline") - args.use_param_file("@%s", use_always = True) + args.use_param_file("@%s") ctx.actions.run( inputs = runtime_jars, outputs = [deploy_jar], From 0f05da238281c52f22aaf7183fae7c5d4d9a006c Mon Sep 17 00:00:00 2001 From: Ittai Zeidman Date: Sun, 19 Jan 2020 11:57:48 +0200 Subject: [PATCH 3/3] linting --- scala/private/phases/phase_merge_jars.bzl | 2 +- test/src/main/scala/scalarules/test/large_classpath/BUILD | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scala/private/phases/phase_merge_jars.bzl b/scala/private/phases/phase_merge_jars.bzl index 7df964757..a8507a5f1 100644 --- a/scala/private/phases/phase_merge_jars.bzl +++ b/scala/private/phases/phase_merge_jars.bzl @@ -35,4 +35,4 @@ def phase_merge_jars(ctx, p): ) def _fileToPath(file): - return file.path \ No newline at end of file + return file.path diff --git a/test/src/main/scala/scalarules/test/large_classpath/BUILD b/test/src/main/scala/scalarules/test/large_classpath/BUILD index c8cffe27a..4d8783082 100644 --- a/test/src/main/scala/scalarules/test/large_classpath/BUILD +++ b/test/src/main/scala/scalarules/test/large_classpath/BUILD @@ -14,8 +14,8 @@ scala_binary( ) scala_library( - name="triggerDeployJarCreation", - data = [":largeClasspath_deploy.jar"] + name = "triggerDeployJarCreation", + data = [":largeClasspath_deploy.jar"], ) create_dependencies(