@@ -102,18 +102,20 @@ def _compiler_toolchains(ctx):
102
102
java_runtime = find_java_runtime_toolchain (ctx , ctx .attr ._host_javabase ),
103
103
)
104
104
105
- def _jvm_deps (ctx , toolchains , associated_targets , deps , runtime_deps = []):
105
+ def _jvm_deps (ctx , toolchains , associate_deps , deps , exports = [] , runtime_deps = []):
106
106
"""Encapsulates jvm dependency metadata."""
107
107
diff = _sets .intersection (
108
- _sets .copy_of ([x .label for x in associated_targets ]),
108
+ _sets .copy_of ([x .label for x in associate_deps ]),
109
109
_sets .copy_of ([x .label for x in deps ]),
110
110
)
111
111
if diff :
112
112
fail (
113
113
"\n ------\n Targets should only be put in associates= or deps=, not both:\n %s" %
114
114
",\n " .join ([" %s" % x for x in list (diff )]),
115
115
)
116
- dep_infos = [_java_info (d ) for d in associated_targets + deps ] + [toolchains .kt .jvm_stdlibs ]
116
+ dep_infos = [_java_info (d ) for d in associate_deps + deps ] + [toolchains .kt .jvm_stdlibs ]
117
+
118
+ associates = _associate_utils .get_associates (ctx , associates = associate_deps )
117
119
118
120
# Reduced classpath, exclude transitive deps from compilation
119
121
if (toolchains .kt .experimental_prune_transitive_deps and
@@ -132,10 +134,11 @@ def _jvm_deps(ctx, toolchains, associated_targets, deps, runtime_deps = []):
132
134
]
133
135
134
136
return struct (
137
+ module_name = associates .module_name ,
135
138
deps = dep_infos ,
136
- compile_jars = depset (
137
- transitive = transitive ,
138
- ),
139
+ exports = [ _java_info ( d ) for d in exports ],
140
+ associate_jars = associates . jars ,
141
+ compile_jars = depset ( transitive = transitive ),
139
142
runtime_deps = [_java_info (d ) for d in runtime_deps ],
140
143
)
141
144
@@ -378,7 +381,6 @@ def _run_kapt_builder_actions(
378
381
rule_kind ,
379
382
toolchains ,
380
383
srcs ,
381
- associates ,
382
384
compile_deps ,
383
385
deps_artifacts ,
384
386
annotation_processors ,
@@ -398,7 +400,6 @@ def _run_kapt_builder_actions(
398
400
toolchains = toolchains ,
399
401
srcs = srcs ,
400
402
generated_src_jars = [],
401
- associates = associates ,
402
403
compile_deps = compile_deps ,
403
404
deps_artifacts = deps_artifacts ,
404
405
annotation_processors = annotation_processors ,
@@ -424,7 +425,6 @@ def _run_ksp_builder_actions(
424
425
rule_kind ,
425
426
toolchains ,
426
427
srcs ,
427
- associates ,
428
428
compile_deps ,
429
429
deps_artifacts ,
430
430
annotation_processors ,
@@ -443,7 +443,6 @@ def _run_ksp_builder_actions(
443
443
toolchains = toolchains ,
444
444
srcs = srcs ,
445
445
generated_src_jars = [],
446
- associates = associates ,
447
446
compile_deps = compile_deps ,
448
447
deps_artifacts = deps_artifacts ,
449
448
annotation_processors = annotation_processors ,
@@ -464,7 +463,6 @@ def _run_kt_builder_action(
464
463
toolchains ,
465
464
srcs ,
466
465
generated_src_jars ,
467
- associates ,
468
466
compile_deps ,
469
467
deps_artifacts ,
470
468
annotation_processors ,
@@ -477,7 +475,7 @@ def _run_kt_builder_action(
477
475
kotlinc_options = ctx .attr .kotlinc_opts [KotlincOptions ] if ctx .attr .kotlinc_opts else toolchains .kt .kotlinc_options
478
476
javac_options = ctx .attr .javac_opts [JavacOptions ] if ctx .attr .javac_opts else toolchains .kt .javac_options
479
477
480
- args = _utils .init_args (ctx , rule_kind , associates .module_name , kotlinc_options )
478
+ args = _utils .init_args (ctx , rule_kind , compile_deps .module_name , kotlinc_options )
481
479
482
480
for f , path in outputs .items ():
483
481
args .add ("--" + f , path )
@@ -492,7 +490,7 @@ def _run_kt_builder_action(
492
490
args .add_all ("--sources" , srcs .all_srcs , omit_if_empty = True )
493
491
args .add_all ("--source_jars" , srcs .src_jars + generated_src_jars , omit_if_empty = True )
494
492
args .add_all ("--deps_artifacts" , deps_artifacts , omit_if_empty = True )
495
- args .add_all ("--kotlin_friend_paths" , associates . jars , map_each = _associate_utils . flatten_jars )
493
+ args .add_all ("--kotlin_friend_paths" , compile_deps . associate_jars , omit_if_empty = True )
496
494
args .add ("--instrument_coverage" , ctx .coverage_instrumented ())
497
495
498
496
# Collect and prepare plugin descriptor for the worker.
@@ -593,21 +591,21 @@ def kt_jvm_produce_jar_actions(ctx, rule_kind):
593
591
"""
594
592
toolchains = _compiler_toolchains (ctx )
595
593
srcs = _partitioned_srcs (ctx .files .srcs )
596
- associates = _associate_utils .get_associates (ctx )
597
594
compile_deps = _jvm_deps (
598
595
ctx ,
599
- toolchains ,
600
- associates . targets ,
596
+ toolchains = toolchains ,
597
+ associate_deps = ctx . attr . associates ,
601
598
deps = ctx .attr .deps ,
602
- runtime_deps = ctx .attr .runtime_deps ,
599
+ exports = getattr (ctx .attr , "exports" , []),
600
+ runtime_deps = getattr (ctx .attr , "runtime_deps" , []),
603
601
)
604
602
605
603
annotation_processors = _plugin_mappers .targets_to_annotation_processors (ctx .attr .plugins + ctx .attr .deps )
606
604
ksp_annotation_processors = _plugin_mappers .targets_to_ksp_annotation_processors (ctx .attr .plugins + ctx .attr .deps )
607
605
transitive_runtime_jars = _plugin_mappers .targets_to_transitive_runtime_jars (ctx .attr .plugins + ctx .attr .deps )
608
606
plugins = _new_plugins_from (ctx .attr .plugins + _exported_plugins (deps = ctx .attr .deps ))
609
607
610
- deps_artifacts = _deps_artifacts (toolchains , ctx .attr .deps + associates . targets )
608
+ deps_artifacts = _deps_artifacts (toolchains , ctx .attr .deps + ctx . attr . associates )
611
609
612
610
generated_src_jars = []
613
611
annotation_processing = None
@@ -623,7 +621,6 @@ def kt_jvm_produce_jar_actions(ctx, rule_kind):
623
621
srcs = srcs ,
624
622
generated_kapt_src_jars = [],
625
623
generated_ksp_src_jars = [],
626
- associates = associates ,
627
624
compile_deps = compile_deps ,
628
625
deps_artifacts = deps_artifacts ,
629
626
annotation_processors = annotation_processors ,
@@ -674,8 +671,8 @@ def kt_jvm_produce_jar_actions(ctx, rule_kind):
674
671
source_jar = source_jar ,
675
672
jdeps = output_jdeps ,
676
673
deps = compile_deps .deps ,
677
- runtime_deps = [ _java_info ( d ) for d in ctx . attr . runtime_deps ] ,
678
- exports = [ _java_info ( d ) for d in getattr ( ctx . attr , " exports" , [])] ,
674
+ runtime_deps = compile_deps . runtime_deps ,
675
+ exports = compile_deps . exports ,
679
676
neverlink = getattr (ctx .attr , "neverlink" , False ),
680
677
generated_source_jar = generated_source_jar ,
681
678
)
@@ -692,8 +689,8 @@ def kt_jvm_produce_jar_actions(ctx, rule_kind):
692
689
instrumented_files = instrumented_files ,
693
690
kt = _KtJvmInfo (
694
691
srcs = ctx .files .srcs ,
695
- module_name = associates .module_name ,
696
- module_jars = associates . jars ,
692
+ module_name = compile_deps .module_name ,
693
+ module_jars = compile_deps . associate_jars ,
697
694
language_version = toolchains .kt .api_version ,
698
695
exported_compiler_plugins = _collect_plugins_for_export (
699
696
getattr (ctx .attr , "exported_compiler_plugins" , []),
@@ -723,7 +720,6 @@ def _run_kt_java_builder_actions(
723
720
srcs ,
724
721
generated_kapt_src_jars ,
725
722
generated_ksp_src_jars ,
726
- associates ,
727
723
compile_deps ,
728
724
deps_artifacts ,
729
725
annotation_processors ,
@@ -749,7 +745,6 @@ def _run_kt_java_builder_actions(
749
745
rule_kind = rule_kind ,
750
746
toolchains = toolchains ,
751
747
srcs = srcs ,
752
- associates = associates ,
753
748
compile_deps = compile_deps ,
754
749
deps_artifacts = deps_artifacts ,
755
750
annotation_processors = annotation_processors ,
@@ -773,7 +768,6 @@ def _run_kt_java_builder_actions(
773
768
rule_kind = rule_kind ,
774
769
toolchains = toolchains ,
775
770
srcs = srcs ,
776
- associates = associates ,
777
771
compile_deps = compile_deps ,
778
772
deps_artifacts = deps_artifacts ,
779
773
annotation_processors = ksp_annotation_processors ,
@@ -810,7 +804,6 @@ def _run_kt_java_builder_actions(
810
804
toolchains = toolchains ,
811
805
srcs = srcs ,
812
806
generated_src_jars = generated_kapt_src_jars + generated_ksp_src_jars ,
813
- associates = associates ,
814
807
compile_deps = compile_deps ,
815
808
deps_artifacts = deps_artifacts ,
816
809
annotation_processors = [],
@@ -831,8 +824,8 @@ def _run_kt_java_builder_actions(
831
824
compile_jar = kt_compile_jar ,
832
825
jdeps = kt_jdeps ,
833
826
deps = compile_deps .deps ,
834
- runtime_deps = [ d [ JavaInfo ] for d in ctx . attr . runtime_deps ] ,
835
- exports = [ d [ JavaInfo ] for d in getattr ( ctx . attr , " exports" , [])] ,
827
+ runtime_deps = compile_deps . runtime_deps ,
828
+ exports = compile_deps . exports ,
836
829
neverlink = getattr (ctx .attr , "neverlink" , False ),
837
830
)
838
831
java_infos .append (kt_java_info )
0 commit comments