@@ -113,24 +113,27 @@ touch {statsfile}
113
113
114
114
115
115
def _collect_plugin_paths (plugins ):
116
- paths = depset ()
116
+ paths = []
117
117
for p in plugins :
118
118
if hasattr (p , "path" ):
119
- paths += [ p . path ]
119
+ paths . append ( p )
120
120
elif hasattr (p , "scala" ):
121
- paths += [ p .scala .outputs .jar . path ]
121
+ paths . append ( p .scala .outputs .jar )
122
122
elif hasattr (p , "java" ):
123
- paths += [j .class_jar . path for j in p .java .outputs .jars ]
123
+ paths . extend ( [j .class_jar for j in p .java .outputs .jars ])
124
124
# support http_file pointed at a jar. http_jar uses ijar,
125
125
# which breaks scala macros
126
126
elif hasattr (p , "files" ):
127
- paths += [ f . path for f in p .files if not_sources_jar (f .basename ) ]
128
- return paths
127
+ paths . extend ([ f for f in p .files if not_sources_jar (f .basename )])
128
+ return depset ( paths )
129
129
130
130
131
131
def _expand_location (ctx , flags ):
132
132
return [ctx .expand_location (f , ctx .attr .data ) for f in flags ]
133
133
134
+ def _join_path (args , sep = "," ):
135
+ return sep .join ([f .path for f in args ])
136
+
134
137
def _compile (ctx , cjars , dep_srcjars , buildijar , transitive_compile_jars , labels , implicit_junit_deps_needed_for_java_compilation ):
135
138
ijar_output_path = ""
136
139
ijar_cmd_path = ""
@@ -141,7 +144,7 @@ def _compile(ctx, cjars, dep_srcjars, buildijar, transitive_compile_jars, labels
141
144
java_srcs = _java_filetype .filter (ctx .files .srcs )
142
145
sources = _scala_filetype .filter (ctx .files .srcs ) + java_srcs
143
146
srcjars = _srcjar_filetype .filter (ctx .files .srcs )
144
- all_srcjars = depset (srcjars + list ( dep_srcjars ) )
147
+ all_srcjars = depset (srcjars , transitive = [ dep_srcjars ] )
145
148
# look for any plugins:
146
149
plugins = _collect_plugin_paths (ctx .attr .plugins )
147
150
dependency_analyzer_plugin_jars = []
@@ -156,13 +159,14 @@ def _compile(ctx, cjars, dep_srcjars, buildijar, transitive_compile_jars, labels
156
159
# "off" mode is used as a feature toggle, that preserves original behaviour
157
160
dependency_analyzer_mode = ctx .fragments .java .strict_java_deps
158
161
dep_plugin = ctx .attr ._dependency_analyzer_plugin
159
- plugins += [ f . path for f in dep_plugin .files ]
162
+ plugins = depset ( transitive = [ plugins , dep_plugin .files ])
160
163
dependency_analyzer_plugin_jars = ctx .files ._dependency_analyzer_plugin
161
164
compiler_classpath_jars = transitive_compile_jars
162
165
163
- direct_jars = "," .join ([j .path for j in cjars ])
164
- indirect_jars = "," .join ([j .path for j in transitive_compile_jars ])
165
- indirect_targets = "," .join ([labels [j .path ] for j in transitive_compile_jars ])
166
+ direct_jars = _join_path (cjars .to_list ())
167
+ transitive_cjars_list = transitive_compile_jars .to_list ()
168
+ indirect_jars = _join_path (transitive_cjars_list )
169
+ indirect_targets = "," .join ([labels [j .path ] for j in transitive_cjars_list ])
166
170
current_target = str (ctx .label )
167
171
168
172
optional_scalac_args = """
@@ -177,10 +181,10 @@ CurrentTarget: {current_target}
177
181
current_target = current_target
178
182
)
179
183
180
- plugin_arg = "," . join ( list ( plugins ))
184
+ plugin_arg = _join_path ( plugins . to_list ( ))
181
185
182
186
separator = ctx .configuration .host_path_separator
183
- compiler_classpath = separator . join ([ j . path for j in compiler_classpath_jars ] )
187
+ compiler_classpath = _join_path ( compiler_classpath_jars . to_list (), separator )
184
188
185
189
toolchain = ctx .toolchains ['@io_bazel_rules_scala//scala:toolchain_type' ]
186
190
scalacopts = toolchain .scalacopts + ctx .attr .scalacopts
@@ -213,20 +217,21 @@ StatsfileOutput: {statsfile_output}
213
217
print_compile_time = ctx .attr .print_compile_time ,
214
218
plugin_arg = plugin_arg ,
215
219
cp = compiler_classpath ,
216
- classpath_resource_src = "," . join ([ f . path for f in classpath_resources ] ),
217
- files = "," . join ([ f . path for f in sources ] ),
220
+ classpath_resource_src = _join_path ( classpath_resources ),
221
+ files = _join_path ( sources ),
218
222
enableijar = buildijar ,
219
223
ijar_out = ijar_output_path ,
220
224
ijar_cmd_path = ijar_cmd_path ,
221
- srcjars = "," .join ([f .path for f in all_srcjars ]),
222
- java_files = "," .join ([f .path for f in java_srcs ]),
225
+ srcjars = _join_path (all_srcjars .to_list ()),
226
+ java_files = _join_path (java_srcs ),
227
+ # the resource paths need to be aligned in order
223
228
resource_src = "," .join ([f .path for f in ctx .files .resources ]),
224
229
resource_short_paths = "," .join ([f .short_path for f in ctx .files .resources ]),
225
230
resource_dest = "," .join (
226
231
[_adjust_resources_path_by_default_prefixes (f .short_path )[1 ] for f in ctx .files .resources ]
227
232
),
228
233
resource_strip_prefix = ctx .attr .resource_strip_prefix ,
229
- resource_jars = "," . join ([ f . path for f in ctx .files .resource_jars ] ),
234
+ resource_jars = _join_path ( ctx .files .resource_jars ),
230
235
dependency_analyzer_mode = dependency_analyzer_mode ,
231
236
statsfile_output = ctx .outputs .statsfile .path
232
237
)
@@ -240,8 +245,8 @@ StatsfileOutput: {statsfile_output}
240
245
outs = [ctx .outputs .jar , ctx .outputs .statsfile ]
241
246
if buildijar :
242
247
outs .extend ([ctx .outputs .ijar ])
243
- ins = (list ( compiler_classpath_jars ) +
244
- list ( dep_srcjars ) +
248
+ ins = (compiler_classpath_jars . to_list ( ) +
249
+ dep_srcjars . to_list ( ) +
245
250
list (srcjars ) +
246
251
list (sources ) +
247
252
ctx .files .srcs +
@@ -344,7 +349,7 @@ def collect_java_providers_of(deps):
344
349
345
350
def _compile_or_empty (ctx , jars , srcjars , buildijar , transitive_compile_jars , jars2labels , implicit_junit_deps_needed_for_java_compilation ):
346
351
# We assume that if a srcjar is present, it is not empty
347
- if len (ctx .files .srcs ) + len (srcjars ) == 0 :
352
+ if len (ctx .files .srcs ) + len (srcjars . to_list () ) == 0 :
348
353
_build_nosrc_jar (ctx , buildijar )
349
354
# no need to build ijar when empty
350
355
return struct (ijar = ctx .outputs .jar ,
@@ -372,17 +377,17 @@ def _compile_or_empty(ctx, jars, srcjars, buildijar, transitive_compile_jars, ja
372
377
full_jars = full_jars ,
373
378
ijars = ijars )
374
379
375
- def _build_deployable (ctx , jars ):
380
+ def _build_deployable (ctx , jars_list ):
376
381
# This calls bazels singlejar utility.
377
382
# For a full list of available command line options see:
378
383
# https://github.com/bazelbuild/bazel/blob/master/src/java_tools/singlejar/java/com/google/devtools/build/singlejar/SingleJar.java#L311
379
384
args = ["--normalize" , "--sources" ]
380
- args .extend ([j .path for j in jars ])
385
+ args .extend ([j .path for j in jars_list ])
381
386
if getattr (ctx .attr , "main_class" , "" ):
382
387
args .extend (["--main_class" , ctx .attr .main_class ])
383
388
args .extend (["--output" , ctx .outputs .deploy_jar .path ])
384
389
ctx .actions .run (
385
- inputs = list ( jars ) ,
390
+ inputs = jars_list ,
386
391
outputs = [ctx .outputs .deploy_jar ],
387
392
executable = ctx .executable ._singlejar ,
388
393
mnemonic = "ScalaDeployJar" ,
@@ -452,7 +457,7 @@ def _write_executable(ctx, rjars, main_class, jvm_flags, wrapper):
452
457
template = ctx .attr ._java_stub_template .files .to_list ()[0 ]
453
458
# RUNPATH is defined here:
454
459
# https://github.com/bazelbuild/bazel/blob/0.4.5/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt#L227
455
- classpath = ":" .join (["${RUNPATH}%s" % (j .short_path ) for j in rjars ])
460
+ classpath = ":" .join (["${RUNPATH}%s" % (j .short_path ) for j in rjars . to_list () ])
456
461
jvm_flags = " " .join ([ctx .expand_location (f , ctx .attr .data ) for f in jvm_flags ])
457
462
ctx .actions .expand_template (
458
463
template = template ,
@@ -471,11 +476,11 @@ def _write_executable(ctx, rjars, main_class, jvm_flags, wrapper):
471
476
)
472
477
473
478
def collect_srcjars (targets ):
474
- srcjars = depset ()
479
+ srcjars = []
475
480
for target in targets :
476
481
if hasattr (target , "srcjars" ):
477
- srcjars += [ target .srcjars .srcjar ]
478
- return srcjars
482
+ srcjars . append ( target .srcjars .srcjar )
483
+ return depset ( srcjars )
479
484
480
485
def add_labels_of_jars_to (jars2labels , dependency , all_jars , direct_jars ):
481
486
for jar in direct_jars :
@@ -526,68 +531,68 @@ def filter_not_sources(deps):
526
531
return depset ([dep for dep in deps .to_list () if not_sources_jar (dep .basename ) ])
527
532
528
533
def _collect_runtime_jars (dep_targets ):
529
- runtime_jars = depset ()
534
+ runtime_jars = []
530
535
531
536
for dep_target in dep_targets :
532
537
if java_common .provider in dep_target :
533
- runtime_jars += dep_target [java_common .provider ].transitive_runtime_jars
538
+ runtime_jars . append ( dep_target [java_common .provider ].transitive_runtime_jars )
534
539
else :
535
540
# support http_file pointed at a jar. http_jar uses ijar,
536
541
# which breaks scala macros
537
- runtime_jars += filter_not_sources (dep_target .files )
542
+ runtime_jars . append ( filter_not_sources (dep_target .files ) )
538
543
539
544
return runtime_jars
540
545
541
546
def _collect_jars_when_dependency_analyzer_is_off (dep_targets ):
542
- compile_jars = depset ()
543
- runtime_jars = depset ()
547
+ compile_jars = []
548
+ runtime_jars = []
544
549
545
550
for dep_target in dep_targets :
546
551
if java_common .provider in dep_target :
547
552
java_provider = dep_target [java_common .provider ]
548
- compile_jars += java_provider .compile_jars
549
- runtime_jars += java_provider .transitive_runtime_jars
553
+ compile_jars . append ( java_provider .compile_jars )
554
+ runtime_jars . append ( java_provider .transitive_runtime_jars )
550
555
else :
551
556
# support http_file pointed at a jar. http_jar uses ijar,
552
557
# which breaks scala macros
553
- compile_jars += filter_not_sources (dep_target .files )
554
- runtime_jars += filter_not_sources (dep_target .files )
558
+ compile_jars . append ( filter_not_sources (dep_target .files ) )
559
+ runtime_jars . append ( filter_not_sources (dep_target .files ) )
555
560
556
- return struct (compile_jars = compile_jars ,
557
- transitive_runtime_jars = runtime_jars ,
561
+ return struct (compile_jars = depset ( transitive = compile_jars ) ,
562
+ transitive_runtime_jars = depset ( transitive = runtime_jars ) ,
558
563
jars2labels = {},
559
564
transitive_compile_jars = depset ())
560
565
561
566
def _collect_jars_when_dependency_analyzer_is_on (dep_targets ):
562
- transitive_compile_jars = depset ()
567
+ transitive_compile_jars = []
563
568
jars2labels = {}
564
- compile_jars = depset ()
565
- runtime_jars = depset ()
569
+ compile_jars = []
570
+ runtime_jars = []
566
571
567
572
for dep_target in dep_targets :
568
- current_dep_compile_jars = depset ()
569
- current_dep_transitive_compile_jars = depset ()
573
+ current_dep_compile_jars = None
574
+ current_dep_transitive_compile_jars = None
570
575
571
576
if java_common .provider in dep_target :
572
577
java_provider = dep_target [java_common .provider ]
573
578
current_dep_compile_jars = java_provider .compile_jars
574
579
current_dep_transitive_compile_jars = java_provider .transitive_compile_time_jars
575
- runtime_jars += java_provider .transitive_runtime_jars
580
+ runtime_jars . append ( java_provider .transitive_runtime_jars )
576
581
else :
577
582
# support http_file pointed at a jar. http_jar uses ijar,
578
583
# which breaks scala macros
579
584
current_dep_compile_jars = filter_not_sources (dep_target .files )
580
- runtime_jars += filter_not_sources (dep_target .files )
581
585
current_dep_transitive_compile_jars = filter_not_sources (dep_target .files )
586
+ runtime_jars .append (filter_not_sources (dep_target .files ))
582
587
583
- compile_jars += current_dep_compile_jars
584
- transitive_compile_jars += current_dep_transitive_compile_jars
585
- add_labels_of_jars_to (jars2labels , dep_target , current_dep_transitive_compile_jars , current_dep_compile_jars )
588
+ compile_jars . append ( current_dep_compile_jars )
589
+ transitive_compile_jars . append ( current_dep_transitive_compile_jars )
590
+ add_labels_of_jars_to (jars2labels , dep_target , current_dep_transitive_compile_jars . to_list () , current_dep_compile_jars . to_list () )
586
591
587
- return struct (compile_jars = compile_jars ,
588
- transitive_runtime_jars = runtime_jars ,
592
+ return struct (compile_jars = depset ( transitive = compile_jars ) ,
593
+ transitive_runtime_jars = depset ( transitive = runtime_jars ) ,
589
594
jars2labels = jars2labels ,
590
- transitive_compile_jars = transitive_compile_jars )
595
+ transitive_compile_jars = depset ( transitive = transitive_compile_jars ) )
591
596
592
597
def collect_jars (dep_targets , dependency_analyzer_is_off = True ):
593
598
"""Compute the runtime and compile-time dependencies from the given targets""" # noqa
@@ -620,7 +625,7 @@ def _collect_jars_from_common_ctx(ctx, extra_deps = [], extra_runtime_deps = [])
620
625
deps_jars = collect_jars (ctx .attr .deps + auto_deps + extra_deps , dependency_analyzer_is_off )
621
626
(cjars , transitive_rjars , jars2labels , transitive_compile_jars ) = (deps_jars .compile_jars , deps_jars .transitive_runtime_jars , deps_jars .jars2labels , deps_jars .transitive_compile_jars )
622
627
623
- transitive_rjars += _collect_runtime_jars (ctx .attr .runtime_deps + extra_runtime_deps )
628
+ transitive_rjars = depset ( transitive = [ transitive_rjars ] + _collect_runtime_jars (ctx .attr .runtime_deps + extra_runtime_deps ) )
624
629
625
630
return struct (compile_jars = cjars , transitive_runtime_jars = transitive_rjars , jars2labels = jars2labels , transitive_compile_jars = transitive_compile_jars )
626
631
@@ -636,7 +641,7 @@ def create_java_provider(scalaattr, transitive_compile_time_jars):
636
641
use_ijar = False ,
637
642
compile_time_jars = scalaattr .compile_jars ,
638
643
runtime_jars = scalaattr .transitive_runtime_jars ,
639
- transitive_compile_time_jars = transitive_compile_time_jars + scalaattr .compile_jars ,
644
+ transitive_compile_time_jars = depset ( transitive = [ transitive_compile_time_jars , scalaattr .compile_jars ]) ,
640
645
transitive_runtime_jars = scalaattr .transitive_runtime_jars ,
641
646
)
642
647
else :
@@ -692,14 +697,9 @@ def _lib(ctx, non_macro_lib):
692
697
write_manifest (ctx )
693
698
outputs = _compile_or_empty (ctx , cjars , srcjars , non_macro_lib , jars .transitive_compile_jars , jars .jars2labels , [])
694
699
695
- transitive_rjars += outputs .full_jars
696
-
697
- _build_deployable (ctx , transitive_rjars )
700
+ transitive_rjars = depset (outputs .full_jars , transitive = [transitive_rjars ])
698
701
699
- # Now, need to setup providers for dependents
700
- # Notice that transitive_rjars just carries over from dependency analysis
701
- # but cjars 'resets' between cjars and next_cjars
702
- next_cjars = depset (outputs .ijars ) # use ijar, if available, for future compiles
702
+ _build_deployable (ctx , transitive_rjars .to_list ())
703
703
704
704
# Using transitive_files since transitive_rjars a depset and avoiding linearization
705
705
runfiles = ctx .runfiles (
@@ -711,13 +711,12 @@ def _lib(ctx, non_macro_lib):
711
711
# Since after, will not show up in deploy_jar or old jars runfiles
712
712
# Notice that compile_jars is intentionally transitive for exports
713
713
exports_jars = collect_jars (ctx .attr .exports )
714
- next_cjars += exports_jars .compile_jars
715
- transitive_rjars += exports_jars .transitive_runtime_jars
714
+ transitive_rjars = depset (transitive = [transitive_rjars , exports_jars .transitive_runtime_jars ])
716
715
717
716
scalaattr = create_scala_provider (
718
717
ijar = outputs .ijar ,
719
718
class_jar = outputs .class_jar ,
720
- compile_jars = next_cjars ,
719
+ compile_jars = depset ( outputs . ijars , transitive = [ exports_jars . compile_jars ]) ,
721
720
transitive_runtime_jars = transitive_rjars ,
722
721
deploy_jar = ctx .outputs .deploy_jar ,
723
722
full_jars = outputs .full_jars ,
@@ -760,14 +759,13 @@ def _scala_macro_library_impl(ctx):
760
759
# Common code shared by all scala binary implementations.
761
760
def _scala_binary_common (ctx , cjars , rjars , transitive_compile_time_jars , jars2labels , java_wrapper , implicit_junit_deps_needed_for_java_compilation = []):
762
761
write_manifest (ctx )
763
- outputs = _compile_or_empty (ctx , cjars , [] , False , transitive_compile_time_jars , jars2labels , implicit_junit_deps_needed_for_java_compilation ) # no need to build an ijar for an executable
764
- rjars += outputs .full_jars
762
+ outputs = _compile_or_empty (ctx , cjars , depset () , False , transitive_compile_time_jars , jars2labels , implicit_junit_deps_needed_for_java_compilation ) # no need to build an ijar for an executable
763
+ rjars = depset ( outputs .full_jars , transitive = [ rjars ])
765
764
766
- rjars_list = list (rjars )
767
- _build_deployable (ctx , rjars_list )
765
+ _build_deployable (ctx , rjars .to_list ())
768
766
769
767
runfiles = ctx .runfiles (
770
- files = rjars_list + [ctx .outputs .executable , java_wrapper ] + ctx .files ._java_runtime ,
768
+ transitive_files = depset ( [ctx .outputs .executable , java_wrapper ] + ctx .files ._java_runtime , transitive = [ rjars ]) ,
771
769
collect_data = True )
772
770
773
771
scalaattr = create_scala_provider (
@@ -860,12 +858,13 @@ def _scala_test_impl(ctx):
860
858
# _scalatest is an http_jar, so its compile jar is run through ijar
861
859
# however, contains macros, so need to handle separately
862
860
scalatest_jars = collect_jars ([ctx .attr ._scalatest ]).transitive_runtime_jars
863
- cjars += scalatest_jars
864
- transitive_rjars += scalatest_jars
861
+ cjars = depset ( transitive = [ cjars , scalatest_jars ])
862
+ transitive_rjars = depset ( transitive = [ transitive_rjars , scalatest_jars ])
865
863
866
864
if is_dependency_analyzer_on (ctx ):
867
- transitive_compile_jars += scalatest_jars
868
- add_labels_of_jars_to (jars_to_labels , ctx .attr ._scalatest , scalatest_jars , scalatest_jars )
865
+ transitive_compile_jars = depset (transitive = [scalatest_jars , transitive_compile_jars ])
866
+ scalatest_jars_list = scalatest_jars .to_list ()
867
+ add_labels_of_jars_to (jars_to_labels , ctx .attr ._scalatest , scalatest_jars_list , scalatest_jars_list )
869
868
870
869
args = " " .join ([
871
870
"-R \" {path}\" " .format (path = ctx .outputs .jar .short_path ),
@@ -1206,7 +1205,8 @@ def scala_repositories():
1206
1205
1207
1206
def _sanitize_string_for_usage (s ):
1208
1207
res_array = []
1209
- for c in s :
1208
+ for idx in range (len (s )):
1209
+ c = s [idx ]
1210
1210
if c .isalnum () or c == "." :
1211
1211
res_array .append (c )
1212
1212
else :
0 commit comments