15
15
"""Rules for supporting the Scala language."""
16
16
17
17
load ("//specs2:specs2_junit.bzl" , "specs2_junit_dependencies" )
18
+ load (":scala_cross_version.bzl" , "scala_version" , "scala_mvn_artifact" )
18
19
_jar_filetype = FileType ([".jar" ])
19
20
_java_filetype = FileType ([".java" ])
20
21
_scala_filetype = FileType ([".scala" ])
@@ -66,7 +67,7 @@ def _adjust_resources_path(path, resource_strip_prefix):
66
67
def _add_resources_cmd (ctx ):
67
68
res_cmd = []
68
69
for f in ctx .files .resources :
69
- c_dir , res_path = _adjust_resources_path (f .path , ctx .attr .resource_strip_prefix )
70
+ c_dir , res_path = _adjust_resources_path (f .short_path , ctx .attr .resource_strip_prefix )
70
71
target_path = res_path
71
72
if target_path [0 ] == "/" :
72
73
target_path = target_path [1 :]
@@ -197,6 +198,7 @@ PrintCompileTime: {print_compile_time}
197
198
ResourceDests: {resource_dest}
198
199
ResourceJars: {resource_jars}
199
200
ResourceSrcs: {resource_src}
201
+ ResourceShortPaths: {resource_short_paths}
200
202
ResourceStripPrefix: {resource_strip_prefix}
201
203
ScalacOpts: {scala_opts}
202
204
SourceJars: {srcjars}
@@ -218,8 +220,9 @@ DependencyAnalyzerMode: {dependency_analyzer_mode}
218
220
srcjars = "," .join ([f .path for f in all_srcjars ]),
219
221
java_files = "," .join ([f .path for f in java_srcs ]),
220
222
resource_src = "," .join ([f .path for f in ctx .files .resources ]),
223
+ resource_short_paths = "," .join ([f .short_path for f in ctx .files .resources ]),
221
224
resource_dest = "," .join (
222
- [_adjust_resources_path_by_default_prefixes (f .path )[1 ] for f in ctx .files .resources ]
225
+ [_adjust_resources_path_by_default_prefixes (f .short_path )[1 ] for f in ctx .files .resources ]
223
226
),
224
227
resource_strip_prefix = ctx .attr .resource_strip_prefix ,
225
228
resource_jars = "," .join ([f .path for f in ctx .files .resource_jars ]),
@@ -390,15 +393,20 @@ def _write_launcher(ctx, rjars, main_class, jvm_flags, args="", wrapper_preamble
390
393
javabin = "%s/%s" % (runfiles_root , ctx .executable ._java .short_path )
391
394
template = ctx .attr ._java_stub_template .files .to_list ()[0 ]
392
395
396
+ exec_str = ""
397
+ if wrapper_preamble == "" :
398
+ exec_str = "exec "
399
+
393
400
wrapper = ctx .new_file (ctx .label .name + "_wrapper.sh" )
394
401
ctx .file_action (
395
402
output = wrapper ,
396
403
content = """#!/bin/bash
397
404
{preamble}
398
405
399
- {javabin} "$@" {args}
406
+ {exec_str}{ javabin} "$@" {args}
400
407
""" .format (
401
408
preamble = wrapper_preamble ,
409
+ exec_str = exec_str ,
402
410
javabin = javabin ,
403
411
args = args ,
404
412
),
@@ -514,7 +522,7 @@ def _collect_jars_when_dependency_analyzer_is_on(dep_targets):
514
522
jars2labels = jars2labels ,
515
523
transitive_compile_jars = transitive_compile_jars )
516
524
517
- def _collect_jars (dep_targets , dependency_analyzer_is_off = True ):
525
+ def collect_jars (dep_targets , dependency_analyzer_is_off = True ):
518
526
"""Compute the runtime and compile-time dependencies from the given targets""" # noqa
519
527
520
528
if dependency_analyzer_is_off :
@@ -542,10 +550,10 @@ def _collect_jars_from_common_ctx(ctx, extra_deps = [], extra_runtime_deps = [])
542
550
543
551
# Get jars from deps
544
552
auto_deps = [ctx .attr ._scalalib , ctx .attr ._scalareflect ]
545
- deps_jars = _collect_jars (ctx .attr .deps + auto_deps + extra_deps , dependency_analyzer_is_off )
553
+ deps_jars = collect_jars (ctx .attr .deps + auto_deps + extra_deps , dependency_analyzer_is_off )
546
554
(cjars , transitive_rjars , jars2labels , transitive_compile_jars ) = (deps_jars .compile_jars , deps_jars .transitive_runtime_jars , deps_jars .jars2labels , deps_jars .transitive_compile_jars )
547
555
548
- runtime_dep_jars = _collect_jars (ctx .attr .runtime_deps + extra_runtime_deps , dependency_analyzer_is_off )
556
+ runtime_dep_jars = collect_jars (ctx .attr .runtime_deps + extra_runtime_deps , dependency_analyzer_is_off )
549
557
transitive_rjars += runtime_dep_jars .transitive_runtime_jars
550
558
551
559
if not dependency_analyzer_is_off :
@@ -556,7 +564,7 @@ def _collect_jars_from_common_ctx(ctx, extra_deps = [], extra_runtime_deps = [])
556
564
def _format_full_jars_for_intellij_plugin (full_jars ):
557
565
return [struct (class_jar = jar , ijar = None ) for jar in full_jars ]
558
566
559
- def _create_java_provider (ctx , scalaattr , transitive_compile_time_jars ):
567
+ def create_java_provider (ctx , scalaattr , transitive_compile_time_jars ):
560
568
# This is needed because Bazel >=0.6.0 requires ctx.actions and a Java
561
569
# toolchain. Fortunately, the same change that added this requirement also
562
570
# added this field to the Java provider so we can use it to test which
@@ -610,7 +618,7 @@ def _lib(ctx, non_macro_lib):
610
618
# Add information from exports (is key that AFTER all build actions/runfiles analysis)
611
619
# Since after, will not show up in deploy_jar or old jars runfiles
612
620
# Notice that compile_jars is intentionally transitive for exports
613
- exports_jars = _collect_jars (ctx .attr .exports )
621
+ exports_jars = collect_jars (ctx .attr .exports )
614
622
next_cjars += exports_jars .compile_jars
615
623
transitive_rjars += exports_jars .transitive_runtime_jars
616
624
@@ -631,7 +639,7 @@ def _lib(ctx, non_macro_lib):
631
639
transitive_exports = [] #needed by intellij plugin
632
640
)
633
641
634
- java_provider = _create_java_provider (ctx , scalaattr , jars .transitive_compile_jars )
642
+ java_provider = create_java_provider (ctx , scalaattr , jars .transitive_compile_jars )
635
643
636
644
return struct (
637
645
files = depset ([ctx .outputs .jar ]), # Here is the default output
@@ -695,7 +703,7 @@ def _scala_binary_common(ctx, cjars, rjars, transitive_compile_time_jars, jars2l
695
703
transitive_exports = [] #needed by intellij plugin
696
704
)
697
705
698
- java_provider = _create_java_provider (ctx , scalaattr , transitive_compile_time_jars )
706
+ java_provider = create_java_provider (ctx , scalaattr , transitive_compile_time_jars )
699
707
700
708
return struct (
701
709
files = depset ([ctx .outputs .executable ]),
@@ -772,7 +780,7 @@ def _scala_test_impl(ctx):
772
780
jars .transitive_compile_jars , jars .jars2labels )
773
781
# _scalatest is an http_jar, so its compile jar is run through ijar
774
782
# however, contains macros, so need to handle separately
775
- scalatest_jars = _collect_jars ([ctx .attr ._scalatest ]).transitive_runtime_jars
783
+ scalatest_jars = collect_jars ([ctx .attr ._scalatest ]).transitive_runtime_jars
776
784
cjars += scalatest_jars
777
785
transitive_rjars += scalatest_jars
778
786
@@ -973,17 +981,6 @@ scala_repl = rule(
973
981
fragments = ["java" ]
974
982
)
975
983
976
- def scala_version ():
977
- """return the scala version for use in maven coordinates"""
978
- return "2.12"
979
-
980
- def scala_mvn_artifact (artifact ):
981
- gav = artifact .split (":" )
982
- groupid = gav [0 ]
983
- artifactid = gav [1 ]
984
- version = gav [2 ]
985
- return "%s:%s_%s:%s" % (groupid , artifactid , scala_version (), version )
986
-
987
984
SCALA_BUILD_FILE = """
988
985
# scala.BUILD
989
986
java_import(
0 commit comments