1
- load ("//java/private:common.bzl" , "MAVEN_PREFIX " , "MavenInfo " , "explode_coordinates " , "has_maven_deps " )
2
- # load("//java/private:module.bzl", "GatheredJavaModuleInfo", "has_java_module_deps ")
1
+ load ("//java/private:common.bzl" , "MavenInfo " , "has_maven_deps " , "read_coordinates " , "explode_coordinates " )
2
+ load ("//java/private:module.bzl" , "JavaModuleInfo " )
3
3
4
4
DistZipInfo = provider (
5
5
fields = {
6
6
"dist_infos" : "Transitive collection of structs containing base_name, binary_jar, and source_jar" ,
7
7
},
8
8
)
9
9
10
+ _ATTR_ASPECTS = [
11
+ "deps" ,
12
+ "exports" ,
13
+ "runtime_deps" ,
14
+ ]
15
+
16
+ def _name (coordinates , default ):
17
+ if not coordinates :
18
+ return default
19
+ exploded = explode_coordinates (coordinates )
20
+ return exploded [1 ] + "-" + exploded [2 ]
21
+
10
22
def _dist_aspect_impl (target , ctx ):
11
23
deps = getattr (ctx .rule .attr , "deps" , [])
12
24
exports = getattr (ctx .rule .attr , "exports" , [])
13
25
rt_deps = getattr (ctx .rule .attr , "runtime_deps" , [])
14
- tgt = getattr (ctx .rule .attr , "target" , None )
15
26
16
27
all_deps = deps + exports + rt_deps
17
- if tgt :
18
- all_deps .append (tgt )
28
+ transitive_infos = [d [DistZipInfo ].dist_infos for d in all_deps ]
19
29
20
30
name = None
21
- tags = getattr (ctx .rule .attr , "tags" , [])
22
- for tag in tags :
23
- if tag .startswith (MAVEN_PREFIX ):
24
- raw = tag [len (MAVEN_PREFIX ):]
25
- coords = explode_coordinates (raw )
26
- if "jar" == coords [3 ]:
27
- name = "%s-%s" % (coords [1 ], coords [2 ])
28
-
29
- transitive_infos = [d [DistZipInfo ].dist_infos for d in all_deps if DistZipInfo in d ]
30
-
31
- if not name :
32
- # Return accumulated dist infos
33
- return [
34
- DistZipInfo (
35
- dist_infos = depset ([], transitive = transitive_infos ),
36
- ),
37
- ]
38
-
39
- source_jars = depset ()
40
- binary_jars = depset ()
41
-
42
- if "maven_artifacts" == ctx .rule .kind :
43
- binary_jars = target [OutputGroupInfo ].binjar
44
- source_jars = target [OutputGroupInfo ].srcjar
31
+ binary_jars = []
32
+ source_jars = []
33
+
34
+ if MavenInfo in target and target [MavenInfo ].coordinates :
35
+ name = _name (target [MavenInfo ].coordinates , None )
36
+ binary_jars = target [MavenInfo ].artifact_jars
37
+ source_jars = target [MavenInfo ].source_jars
38
+ elif JavaModuleInfo in target and target [JavaModuleInfo ].name :
39
+ coordinates = read_coordinates (ctx .rule .attr .tags )
40
+ name = _name (coordinates , target [JavaModuleInfo ].name )
41
+ binary_jars = target [JavaInfo ].runtime_output_jars
42
+ source_jars = target [JavaInfo ].source_jars
45
43
elif JavaInfo in target :
46
- binary_jars = depset (target [JavaInfo ].runtime_output_jars )
47
- # elif GatheredJavaModuleInfo in target:
48
- # binary_jars = depset(target[GatheredJavaModuleInfo].binary_jars)
49
- # source_jars = depset(target[GatheredJavaModuleInfo].source_jars)
50
-
51
- binary_jar = None
52
- if len (binary_jars .to_list ()) > 1 :
53
- fail ("Unable to process more than one binary jar" )
54
- elif len (binary_jars .to_list ()) == 1 :
55
- binary_jar = binary_jars .to_list ()[0 ]
56
- source_jar = None
57
- if len (source_jars .to_list ()) > 1 :
58
- fail ("Unable to process more than one source jar" )
59
- elif len (source_jars .to_list ()) == 1 :
60
- source_jar = source_jars .to_list ()[0 ]
44
+ coordinates = read_coordinates (ctx .rule .attr .tags )
45
+ if coordinates :
46
+ name = _name (coordinates , None )
47
+ binary_jars = target [JavaInfo ].runtime_output_jars
48
+ source_jars = target [JavaInfo ].source_jars
49
+
50
+ if len (binary_jars ) > 1 :
51
+ fail ("Unsure how to handle expanding binary jars for " + target )
52
+ if len (source_jars ) > 1 :
53
+ fail ("Unsure how to handle expanding source jars for " + target )
61
54
62
55
current = struct (
63
56
target = str (target .label ),
64
- base_name = name ,
65
- binary_jar = binary_jar ,
66
- source_jar = source_jar ,
57
+ name = name ,
58
+ binary_jar = binary_jars [ 0 ] if len ( binary_jars ) else None ,
59
+ source_jar = source_jars [ 0 ] if len ( source_jars ) else None ,
67
60
)
68
61
69
62
return [
@@ -74,19 +67,13 @@ def _dist_aspect_impl(target, ctx):
74
67
75
68
_dist_aspect = aspect (
76
69
_dist_aspect_impl ,
77
- attr_aspects = [
78
- "deps" ,
79
- "exports" ,
80
- "runtime_deps" ,
81
- "target" ,
82
- ],
70
+ attr_aspects = _ATTR_ASPECTS ,
83
71
provides = [
84
72
DistZipInfo ,
85
73
],
86
74
required_aspect_providers = [
87
- [DistZipInfo ],
88
- # [GatheredJavaModuleInfo],
89
75
[JavaInfo ],
76
+ [JavaInfo , JavaModuleInfo ],
90
77
[MavenInfo ],
91
78
],
92
79
)
@@ -98,10 +85,10 @@ def is_third_party(prefixes, target):
98
85
return False
99
86
100
87
def _java_dist_zip_impl (ctx ):
101
- out = ctx .actions .declare_file ("%s-dist.zip" % ctx .attr .name )
88
+ # out = ctx.actions.declare_file("%s-dist.zip" % ctx.attr.name)
102
89
103
- args = ctx .actions .args ()
104
- args .add_all (["c" , out .path ])
90
+ # args = ctx.actions.args()
91
+ # args.add_all(["c", out.path])
105
92
106
93
inputs = []
107
94
files = []
@@ -116,22 +103,22 @@ def _java_dist_zip_impl(ctx):
116
103
117
104
for info in infos :
118
105
for dist_info in info .dist_infos .to_list ():
119
- if not dist_info .binary_jar :
106
+ if not dist_info .name :
120
107
continue
121
108
122
109
inputs .append (dist_info .binary_jar )
123
110
if is_third_party (ctx .attr .third_party_prefixes , dist_info .target ):
124
- third_party .append ("lib/%s.jar=%s" % (dist_info .base_name , dist_info .binary_jar .path ))
111
+ third_party .append ("lib/%s.jar=%s" % (dist_info .name , dist_info .binary_jar .path ))
125
112
else :
126
- first_party .append ("%s.jar=%s" % (dist_info .base_name , dist_info .binary_jar .path ))
113
+ first_party .append ("%s.jar=%s" % (dist_info .name , dist_info .binary_jar .path ))
127
114
128
- if dist_info .source_jar :
115
+ if dist_info .source_jar and not is_third_party ( ctx . attr . third_party_prefixes , dist_info . target ) :
129
116
inputs .append (dist_info .source_jar )
130
- if is_third_party (ctx .attr .third_party_prefixes , dist_info .target ):
131
- third_party .append ("lib/%s-sources.jar=%s" % (dist_info .base_name , dist_info .source_jar .path ))
132
- else :
133
- first_party .append ("%s-sources.jar=%s" % (dist_info .base_name , dist_info .source_jar .path ))
117
+ first_party .append ("%s-sources.jar=%s" % (dist_info .name , dist_info .source_jar .path ))
134
118
119
+ out = ctx .actions .declare_file ("%s.zip" % ctx .attr .name )
120
+ args = ctx .actions .args ()
121
+ args .add_all (["c" , out ])
135
122
args .add_all (sorted (files ))
136
123
args .add_all (sorted (first_party ))
137
124
args .add_all (sorted (third_party ))
@@ -155,12 +142,11 @@ java_dist_zip = rule(
155
142
allow_files = True ,
156
143
),
157
144
"deps" : attr .label_list (
158
- allow_empty = False ,
159
145
providers = [
160
146
[DistZipInfo ],
161
147
],
162
148
aspects = [
163
- _dist_aspect ,
149
+ _dist_aspect , has_maven_deps ,
164
150
],
165
151
),
166
152
"third_party_prefixes" : attr .string_list (
0 commit comments