Skip to content

Commit 663285b

Browse files
authored
Merge pull request #16 from pubref/sandbox
Include kotlin home libs in sandbox
2 parents 3e38721 + e0c5781 commit 663285b

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

kotlin/rules.bzl

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ def _kotlin_compile_impl(ctx):
1818
args += ["-P"]
1919
args += ["plugin:%s=\"%s\"" % (k, v)]
2020

21+
# Kotlin home - typically the dir 'external/com_github_jetbrains_kotlin'
22+
args += ["-kotlin-home", ctx.file._runtime.dirname + '/..']
23+
2124
# Make classpath if needed. Include those from this and dependent rules.
2225
jars = []
2326

@@ -51,25 +54,21 @@ def _kotlin_compile_impl(ctx):
5154
args += ["-cp", ":".join([file.path for file in jarsetlist])]
5255
inputs += jarsetlist
5356

54-
# Need to traverse back up to execroot, then down again
55-
kotlin_home = ctx.executable._kotlinc.dirname \
56-
+ "/../../../../../external/com_github_jetbrains_kotlin"
57-
5857
# Add in filepaths
5958
for file in ctx.files.srcs:
6059
inputs += [file]
6160
args += [file.path]
6261

62+
# Add all home libs to sandbox
63+
inputs += ctx.files._kotlin_home
64+
6365
# Run the compiler
6466
ctx.action(
6567
mnemonic = "KotlinCompile",
6668
inputs = inputs,
6769
outputs = [kt_jar],
6870
executable = ctx.executable._kotlinc,
6971
arguments = args,
70-
env = {
71-
"KOTLIN_HOME": kotlin_home,
72-
}
7372
)
7473

7574
return struct(
@@ -79,7 +78,6 @@ def _kotlin_compile_impl(ctx):
7978
srcs = ctx.attr.srcs,
8079
jar = kt_jar,
8180
transitive_jars = [kt_jar] + jars,
82-
home = kotlin_home,
8381
),
8482
)
8583

@@ -132,9 +130,15 @@ _kotlin_compile_attrs = {
132130
cfg = 'host',
133131
),
134132

133+
# kotlin home (for runtime libraries discovery)
134+
"_kotlin_home": attr.label(
135+
default=Label("@com_github_jetbrains_kotlin//:home"),
136+
),
137+
135138
# kotlin runtime
136139
"_runtime": attr.label(
137140
default=Label("@com_github_jetbrains_kotlin//:runtime"),
141+
single_file = True,
138142
),
139143

140144
}
@@ -207,6 +211,10 @@ def kotlin_binary(name,
207211

208212
KOTLIN_BUILD = """
209213
package(default_visibility = ["//visibility:public"])
214+
filegroup(
215+
name = "home",
216+
srcs = glob(["lib/*.jar"]),
217+
)
210218
java_import(
211219
name = "runtime",
212220
jars = ["lib/kotlin-runtime.jar"],

0 commit comments

Comments
 (0)