@@ -11,44 +11,15 @@ def write_manifest_file(actions, output_file, main_class):
11
11
12
12
def collect_jars (
13
13
dep_targets ,
14
- dependency_analyzer_is_off = True ,
15
- unused_dependency_checker_is_off = True ,
16
- plus_one_deps_is_off = True ):
14
+ dependency_mode ,
15
+ need_direct_info ,
16
+ need_indirect_info ):
17
17
"""Compute the runtime and compile-time dependencies from the given targets""" # noqa
18
18
19
- if dependency_analyzer_is_off :
20
- return _collect_jars_when_dependency_analyzer_is_off (
21
- dep_targets ,
22
- unused_dependency_checker_is_off ,
23
- plus_one_deps_is_off ,
24
- )
25
- else :
26
- return _collect_jars_when_dependency_analyzer_is_on (dep_targets )
27
-
28
- def collect_plugin_paths (plugins ):
29
- """Get the actual jar paths of plugins as a depset."""
30
- paths = []
31
- for p in plugins :
32
- if hasattr (p , "path" ):
33
- paths .append (p )
34
- elif JavaInfo in p :
35
- paths .extend ([j .class_jar for j in p [JavaInfo ].outputs .jars ])
36
- # support http_file pointed at a jar. http_jar uses ijar,
37
- # which breaks scala macros
38
-
39
- elif hasattr (p , "files" ):
40
- paths .extend ([f for f in p .files .to_list () if not_sources_jar (f .basename )])
41
- return depset (paths )
42
-
43
- def _collect_jars_when_dependency_analyzer_is_off (
44
- dep_targets ,
45
- unused_dependency_checker_is_off ,
46
- plus_one_deps_is_off ):
19
+ transitive_compile_jars = []
20
+ jars2labels = {}
47
21
compile_jars = []
48
- plus_one_deps_compile_jars = []
49
22
runtime_jars = []
50
- jars2labels = {}
51
-
52
23
deps_providers = []
53
24
54
25
for dep_target in dep_targets :
@@ -59,60 +30,67 @@ def _collect_jars_when_dependency_analyzer_is_off(
59
30
compile_jars .append (java_provider .compile_jars )
60
31
runtime_jars .append (java_provider .transitive_runtime_jars )
61
32
62
- if not unused_dependency_checker_is_off :
33
+ additional_transitive_compile_jars = _additional_transitive_compile_jars (
34
+ java_provider = java_provider ,
35
+ dep_target = dep_target ,
36
+ dependency_mode = dependency_mode ,
37
+ )
38
+ transitive_compile_jars .append (additional_transitive_compile_jars )
39
+
40
+ if need_direct_info or need_indirect_info :
41
+ if need_indirect_info :
42
+ all_jars = additional_transitive_compile_jars .to_list ()
43
+ else :
44
+ all_jars = []
63
45
add_labels_of_jars_to (
64
46
jars2labels ,
65
47
dep_target ,
66
- [] ,
48
+ all_jars ,
67
49
java_provider .compile_jars .to_list (),
68
50
)
69
51
70
- if (not plus_one_deps_is_off ) and (PlusOneDeps in dep_target ):
71
- plus_one_deps_compile_jars .append (
72
- depset (transitive = [dep [JavaInfo ].compile_jars for dep in dep_target [PlusOneDeps ].direct_deps if JavaInfo in dep ]),
73
- )
74
-
75
52
return struct (
76
53
compile_jars = depset (transitive = compile_jars ),
77
54
transitive_runtime_jars = depset (transitive = runtime_jars ),
78
55
jars2labels = JarsToLabelsInfo (jars_to_labels = jars2labels ),
79
- transitive_compile_jars = depset (transitive = compile_jars + plus_one_deps_compile_jars ),
56
+ transitive_compile_jars = depset (transitive = transitive_compile_jars ),
80
57
deps_providers = deps_providers ,
81
58
)
82
59
83
- def _collect_jars_when_dependency_analyzer_is_on (dep_targets ):
84
- transitive_compile_jars = []
85
- jars2labels = {}
86
- compile_jars = []
87
- runtime_jars = []
88
- deps_providers = []
89
-
90
- for dep_target in dep_targets :
91
- # we require a JavaInfo for dependencies
92
- # must use java_import or scala_import if you have raw files
93
- java_provider = dep_target [JavaInfo ]
94
- deps_providers .append (java_provider )
95
- current_dep_compile_jars = java_provider .compile_jars
96
- current_dep_transitive_compile_jars = java_provider .transitive_compile_time_jars
97
- runtime_jars .append (java_provider .transitive_runtime_jars )
98
-
99
- compile_jars .append (current_dep_compile_jars )
100
- transitive_compile_jars .append (current_dep_transitive_compile_jars )
60
+ def collect_plugin_paths (plugins ):
61
+ """Get the actual jar paths of plugins as a depset."""
62
+ paths = []
63
+ for p in plugins :
64
+ if hasattr (p , "path" ):
65
+ paths .append (p )
66
+ elif JavaInfo in p :
67
+ paths .extend ([j .class_jar for j in p [JavaInfo ].outputs .jars ])
68
+ # support http_file pointed at a jar. http_jar uses ijar,
69
+ # which breaks scala macros
101
70
102
- add_labels_of_jars_to (
103
- jars2labels ,
104
- dep_target ,
105
- current_dep_transitive_compile_jars .to_list (),
106
- current_dep_compile_jars .to_list (),
107
- )
71
+ elif hasattr (p , "files" ):
72
+ paths .extend ([f for f in p .files .to_list () if not_sources_jar (f .basename )])
73
+ return depset (paths )
108
74
109
- return struct (
110
- compile_jars = depset (transitive = compile_jars ),
111
- transitive_runtime_jars = depset (transitive = runtime_jars ),
112
- jars2labels = JarsToLabelsInfo (jars_to_labels = jars2labels ),
113
- transitive_compile_jars = depset (transitive = transitive_compile_jars ),
114
- deps_providers = deps_providers ,
115
- )
75
+ def _additional_transitive_compile_jars (
76
+ java_provider ,
77
+ dep_target ,
78
+ dependency_mode ):
79
+ if dependency_mode == "transitive" :
80
+ return java_provider .transitive_compile_time_jars
81
+ elif dependency_mode == "plus-one" :
82
+ # dep_target will not always have a PlusOneDeps provider, such as
83
+ # with scala_maven_import_external, hence the need for the fallback.
84
+ if PlusOneDeps in dep_target :
85
+ plus_one_jars = [dep [JavaInfo ].compile_jars for dep in dep_target [PlusOneDeps ].direct_deps if JavaInfo in dep ]
86
+
87
+ # plus_one_jars only contains the deps of deps, not the deps themselves.
88
+ # Hence the need to include the dep's compile jars anyways
89
+ return depset (transitive = plus_one_jars + [java_provider .compile_jars ])
90
+ else :
91
+ return java_provider .compile_jars
92
+ else : # direct
93
+ return java_provider .compile_jars
116
94
117
95
# When import mavan_jar's for scala macros we have to use the jar:file requirement
118
96
# since bazel 0.6.0 this brings in the source jar too
0 commit comments