Skip to content

Commit 37b099c

Browse files
cushonrules_java Copybara
authored andcommitted
Refactor java_single_jar to allow custom output names.
PiperOrigin-RevId: 834288538 Change-Id: I18bd305a6870e74db4136f3dc78ffebefaaf91cd
1 parent 1993657 commit 37b099c

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

java/java_single_jar.bzl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def _java_single_jar(ctx):
4040
args.use_param_file("@%s")
4141
args.set_param_file_format("multiline")
4242
args.add_all("--deploy_manifest_lines", ctx.attr.deploy_manifest_lines)
43-
args.add("--output", ctx.outputs.jar)
43+
args.add("--output", ctx.outputs.output)
4444
args.add("--normalize")
4545

4646
# Deal with limitation of singlejar flags: tool's default behavior is
@@ -64,15 +64,15 @@ def _java_single_jar(ctx):
6464

6565
ctx.actions.run(
6666
inputs = inputs,
67-
outputs = [ctx.outputs.jar],
67+
outputs = [ctx.outputs.output],
6868
arguments = [args],
69-
progress_message = "Merging into %s" % ctx.outputs.jar.short_path,
69+
progress_message = "Merging into %s" % ctx.outputs.output.short_path,
7070
mnemonic = "JavaSingleJar",
7171
executable = ctx.executable._singlejar,
7272
use_default_shell_env = True,
7373
)
7474

75-
files = depset([ctx.outputs.jar])
75+
files = depset([ctx.outputs.output])
7676
providers = [DefaultInfo(
7777
files = files,
7878
runfiles = ctx.runfiles(transitive_files = files),
@@ -81,6 +81,11 @@ def _java_single_jar(ctx):
8181
providers.append(java_common.JavaRuntimeClasspathInfo(runtime_classpath = inputs))
8282
return providers
8383

84+
def _init(name, **kwargs):
85+
if "output" not in kwargs:
86+
kwargs["output"] = name + ".jar"
87+
return kwargs
88+
8489
java_single_jar = rule(
8590
attrs = {
8691
"deps": attr.label_list(
@@ -122,10 +127,9 @@ java_single_jar = rule(
122127
allow_single_file = True,
123128
executable = True,
124129
),
130+
"output": attr.output(),
125131
},
126-
outputs = {
127-
"jar": "%{name}.jar",
128-
},
132+
initializer = _init,
129133
implementation = _java_single_jar,
130134
doc = """
131135
Collects Java dependencies and jar files into a single jar

0 commit comments

Comments
 (0)