Skip to content

Commit cb950f5

Browse files
authored
Replace zipper with singlejar (#1463)
* Replace zipper with singlejar Remove zipper from common attributes singlejar is already there and can generate jars with resources Looking at bazel source code `singlejar` utility is used for: * [pack_sources](https://github.com/bazelbuild/bazel/blob/455454a56e961affb041a1d4a9214f7f313a05aa/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfoBuildHelper.java#L198) * [resources_jar](https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/rules/java/ResourceJarActionBuilder.java#L123) Motivation: * use precompiled binaries ie singlejar comes precompiled via remote_java_tools while zipper is built from sources (at least in remote execution) * use single tool to accomplish same goal * Fix //test/jmh:Run__test_jmh_test_jmh_jdk11 by specifying correct jdk version instead of system default
1 parent a0235fd commit cb950f5

File tree

3 files changed

+21
-47
lines changed

3 files changed

+21
-47
lines changed

scala/private/common_attributes.bzl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,6 @@ implicit_deps = {
8787
default = Label("@bazel_tools//tools/jdk:singlejar"),
8888
allow_files = True,
8989
),
90-
"_zipper": attr.label(
91-
executable = True,
92-
cfg = "exec",
93-
default = Label("@bazel_tools//tools/zip:zipper"),
94-
allow_files = True,
95-
),
9690
"_java_runtime": attr.label(
9791
default = Label("@bazel_tools//tools/jdk:current_java_runtime"),
9892
),

scala/private/phases/phase_compile.bzl

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -254,44 +254,28 @@ def _compile_or_empty(
254254
)
255255

256256
def _build_nosrc_jar(ctx):
257-
resources = _add_resources_cmd(ctx)
258-
ijar_cmd = ""
259-
260-
# this ensures the file is not empty
261-
resources += "META-INF/MANIFEST.MF=%s\n" % ctx.outputs.manifest.path
262-
263-
zipper_arg_path = ctx.actions.declare_file("%s_zipper_args" % ctx.label.name)
264-
ctx.actions.write(zipper_arg_path, resources)
265-
cmd = """
266-
set -o errexit
267-
set -o nounset
268-
set -o pipefail
269-
rm -f {jar_output}
270-
{zipper} c {jar_output} @{path}
271-
# ensures that empty src targets still emit a statsfile and a diagnosticsfile
272-
touch {statsfile}
273-
touch {diagnosticsfile}
274-
""" + ijar_cmd
275-
276-
cmd = cmd.format(
277-
path = zipper_arg_path.path,
278-
jar_output = ctx.outputs.jar.path,
279-
zipper = ctx.executable._zipper.path,
280-
statsfile = ctx.outputs.statsfile.path,
281-
diagnosticsfile = ctx.outputs.diagnosticsfile.path,
257+
resources = [s + ":" + t for t, s in _resource_paths(ctx.files.resources, ctx.attr.resource_strip_prefix)]
258+
259+
args = ctx.actions.args()
260+
args.set_param_file_format("multiline")
261+
args.use_param_file("@%s")
262+
args.add("--compression")
263+
args.add("--normalize")
264+
args.add("--exclude_build_data")
265+
args.add("--warn_duplicate_resources")
266+
args.add("--output", ctx.outputs.jar)
267+
args.add_all("--resources", resources)
268+
269+
ctx.actions.run(
270+
inputs = ctx.files.resources,
271+
outputs = [ctx.outputs.jar],
272+
executable = ctx.executable._singlejar,
273+
progress_message = "scalac %s" % ctx.label,
274+
arguments = [args],
282275
)
283276

284-
outs = [ctx.outputs.jar, ctx.outputs.statsfile, ctx.outputs.diagnosticsfile]
285-
inputs = ctx.files.resources + [ctx.outputs.manifest]
286-
287-
ctx.actions.run_shell(
288-
inputs = inputs,
289-
tools = [ctx.executable._zipper, zipper_arg_path],
290-
outputs = outs,
291-
command = cmd,
292-
progress_message = "scala %s" % ctx.label,
293-
arguments = [],
294-
)
277+
ctx.actions.write(ctx.outputs.statsfile, "")
278+
ctx.actions.write(ctx.outputs.diagnosticsfile, "")
295279

296280
def _create_scala_compilation_provider(ctx, ijar, source_jar, deps_providers):
297281
exports = []
@@ -378,11 +362,6 @@ def _try_to_compile_java_jar(
378362
java_compilation_provider = provider,
379363
)
380364

381-
def _add_resources_cmd(ctx):
382-
paths = _resource_paths(ctx.files.resources, ctx.attr.resource_strip_prefix)
383-
lines = ["{target}={source}\n".format(target = p[0], source = p[1]) for p in paths]
384-
return "".join(lines)
385-
386365
def _collect_java_providers_of(deps):
387366
providers = []
388367
for dep in deps:

test/jmh/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ scala_benchmark_jmh(
6363
scala_benchmark_jmh(
6464
name = "test_jmh_jdk11",
6565
srcs = ["TestJmhRuntimeJdk11.scala"],
66+
runtime_jdk = "@bazel_tools//tools/jdk:remote_jdk11",
6667
)
6768

6869
[sh_test(

0 commit comments

Comments
 (0)