@@ -548,22 +548,32 @@ def _create_scala_compilation_provider(ctx, ijar, source_jar, deps_providers):
548
548
runtime_deps = runtime_deps ,
549
549
)
550
550
551
- def build_deployable (ctx , jars_list ):
552
- # This calls bazels singlejar utility.
553
- # For a full list of available command line options see:
554
- # https://github.com/bazelbuild/bazel/blob/master/src/java_tools/singlejar/java/com/google/devtools/build/singlejar/SingleJar.java#L311
555
- # Use --compression to reduce size of deploy jars.
551
+ def merge_jars (actions , deploy_jar , singlejar_executable , jars_list , main_class = "" , progress_message = "" ):
552
+ """Calls Bazel's singlejar utility.
553
+
554
+ For a full list of available command line options see:
555
+ https://github.com/bazelbuild/bazel/blob/697d219526bffbecd29f29b402c9122ec5d9f2ee/src/java_tools/singlejar/java/com/google/devtools/build/singlejar/SingleJar.java#L337
556
+ Use --compression to reduce size of deploy jars.
557
+
558
+ Args:
559
+ actions: The actions module from ctx: https://docs.bazel.build/versions/master/skylark/lib/actions.html
560
+ deploy_jar: The deploy jar, usually defined in ctx.outputs.
561
+ singlejar_executable: The singlejar executable file.
562
+ jars_list: The jars to pass to singlejar.
563
+ main_class: The main class to run, if any. Defaults to an empty string.
564
+ progress_message: A progress message to display when Bazel executes this action. Defaults to an empty string.
565
+ """
556
566
args = ["--compression" , "--normalize" , "--sources" ]
557
567
args .extend ([j .path for j in jars_list ])
558
- if getattr ( ctx . attr , " main_class" , "" ) :
559
- args .extend (["--main_class" , ctx . attr . main_class ])
560
- args .extend (["--output" , ctx . outputs . deploy_jar .path ])
561
- ctx . actions .run (
568
+ if main_class :
569
+ args .extend (["--main_class" , main_class ])
570
+ args .extend (["--output" , deploy_jar .path ])
571
+ actions .run (
562
572
inputs = jars_list ,
563
- outputs = [ctx . outputs . deploy_jar ],
564
- executable = ctx . executable . _singlejar ,
573
+ outputs = [deploy_jar ],
574
+ executable = singlejar_executable ,
565
575
mnemonic = "ScalaDeployJar" ,
566
- progress_message = "scala deployable %s" % ctx . label ,
576
+ progress_message = progress_message ,
567
577
arguments = args ,
568
578
)
569
579
@@ -832,7 +842,14 @@ def scala_binary_common(
832
842
) # no need to build an ijar for an executable
833
843
rjars = depset (outputs .full_jars , transitive = [rjars ])
834
844
835
- build_deployable (ctx , rjars .to_list ())
845
+ merge_jars (
846
+ actions = ctx .actions ,
847
+ deploy_jar = ctx .outputs .deploy_jar ,
848
+ singlejar_executable = ctx .executable ._singlejar ,
849
+ jars_list = rjars .to_list (),
850
+ main_class = getattr (ctx .attr , "main_class" , "" ),
851
+ progress_message = "Merging Scala binary jar: %s" % ctx .label ,
852
+ )
836
853
837
854
runfiles = ctx .runfiles (
838
855
transitive_files = depset (
0 commit comments