@@ -32,18 +32,19 @@ def _kotlin_compile_impl(ctx):
32
32
# preloader
33
33
inputs += ctx .files ._kotlin_home
34
34
35
+ args += ctx .attr .args
36
+
35
37
# Make classpath if needed. Include those from this and dependent rules.
36
- jars = []
38
+ jars = depset ()
37
39
38
- # Populate from (transitive) java dependencies
40
+ # Populate from (transitive) java dependencies.
39
41
for dep in ctx .attr .java_deps :
40
42
# Add-in all source and generated jar files
41
- for file in dep .files :
42
- jars .append (file )
43
- # Add-in transitive dependencies
44
- for file in dep .java .transitive_deps :
45
- jars .append (file )
46
-
43
+ if java_common .provider in dep :
44
+ info = dep [java_common .provider ]
45
+ # Don't use the ABI jars!
46
+ jars += info .full_compile_jars
47
+
47
48
# Populate from (transitive) kotlin dependencies
48
49
for dep in ctx .attr .deps :
49
50
jars += [file for file in dep .kt .transitive_jars ]
@@ -53,11 +54,9 @@ def _kotlin_compile_impl(ctx):
53
54
# The fileset object is either a ConfiguredTarget OR a depset.
54
55
files = getattr (fileset , 'files' , None )
55
56
if files :
56
- for file in files :
57
- jars += [file ]
57
+ jars = jars .union (files )
58
58
else :
59
- for file in fileset :
60
- jars += [file ]
59
+ jars = jars .union (fileset )
61
60
62
61
# Populate from android dependencies
63
62
for dep in ctx .attr .android_deps :
@@ -66,15 +65,21 @@ def _kotlin_compile_impl(ctx):
66
65
67
66
if jars :
68
67
# De-duplicate
69
- jarsetlist = depset (jars ).to_list ()
70
- args += ["-cp" , ":" .join ([file .path for file in jarsetlist ])]
71
- inputs += jarsetlist
72
-
68
+ jarlist = depset (jars ).to_list ()
69
+ args += ["-cp" , ":" .join ([f .path for f in jarlist ])]
70
+ inputs += jarlist
71
+ if ctx .attr .verbose :
72
+ print ("kotlin compile classpath: \n " + "\n " .join ([file .path for file in jarlist ]))
73
+
73
74
# Add in filepaths
74
75
for file in ctx .files .srcs :
75
76
inputs += [file ]
76
77
args += [file .path ]
77
78
79
+
80
+ if ctx .attr .verbose > 1 :
81
+ print ("kotlin compile arguments: \n %s" % "\n " .join (args ))
82
+
78
83
# Run the compiler
79
84
ctx .action (
80
85
mnemonic = "KotlinCompile" ,
@@ -92,7 +97,7 @@ def _kotlin_compile_impl(ctx):
92
97
kt = struct (
93
98
srcs = ctx .attr .srcs ,
94
99
jar = kt_jar ,
95
- transitive_jars = [kt_jar ] + jars ,
100
+ transitive_jars = [kt_jar ] + jars . to_list () ,
96
101
),
97
102
)
98
103
@@ -121,6 +126,11 @@ _kotlin_compile_attrs = {
121
126
providers = ["java" ],
122
127
),
123
128
129
+ # Add debugging info for the rule
130
+ "verbose" : attr .int (
131
+ default = 0 ,
132
+ ),
133
+
124
134
# Dependent android rules.
125
135
"android_deps" : attr .label_list (
126
136
providers = ["android" ],
@@ -140,6 +150,9 @@ _kotlin_compile_attrs = {
140
150
# Advanced options
141
151
"x_opts" : attr .string_list (),
142
152
153
+ # Other args
154
+ "args" : attr .string_list (),
155
+
143
156
# Plugin options
144
157
"plugin_opts" : attr .string_dict (),
145
158
@@ -281,6 +294,8 @@ def kotlin_binary(name,
281
294
x_opts = [],
282
295
plugin_opts = {},
283
296
java_deps = [],
297
+ compile_args = [],
298
+ verbose = None ,
284
299
visibility = None ,
285
300
** kwargs ):
286
301
@@ -291,16 +306,27 @@ def kotlin_binary(name,
291
306
srcs = srcs ,
292
307
deps = deps ,
293
308
x_opts = x_opts ,
309
+ args = compile_args ,
294
310
plugin_opts = plugin_opts ,
295
311
visibility = visibility ,
312
+ verbose = verbose ,
296
313
)
297
314
315
+ runtime_deps = [name + "_kt.jar" ] + java_deps + [
316
+ dep + "_kt"
317
+ for dep in deps
318
+ ] + ["@com_github_jetbrains_kotlin//:runtime" ]
319
+
320
+ if len (jars ):
321
+ native .java_import (
322
+ name = name + "_jars" ,
323
+ jars = jars ,
324
+ )
325
+ runtime_deps += [name + "_jars" ]
326
+
298
327
native .java_binary (
299
328
name = name ,
300
- runtime_deps = [name + "_kt.jar" ] + java_deps + [
301
- dep + "_kt"
302
- for dep in deps
303
- ] + ["@com_github_jetbrains_kotlin//:runtime" ],
329
+ runtime_deps = runtime_deps ,
304
330
visibility = visibility ,
305
331
** kwargs
306
332
)
0 commit comments