Skip to content

Commit

Permalink
Merge pull request #16 from pubref/sandbox
Browse files Browse the repository at this point in the history
Include kotlin home libs in sandbox
  • Loading branch information
pcj authored May 25, 2017
2 parents 3e38721 + e0c5781 commit 663285b
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions kotlin/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def _kotlin_compile_impl(ctx):
args += ["-P"]
args += ["plugin:%s=\"%s\"" % (k, v)]

# Kotlin home - typically the dir 'external/com_github_jetbrains_kotlin'
args += ["-kotlin-home", ctx.file._runtime.dirname + '/..']

# Make classpath if needed. Include those from this and dependent rules.
jars = []

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

# Need to traverse back up to execroot, then down again
kotlin_home = ctx.executable._kotlinc.dirname \
+ "/../../../../../external/com_github_jetbrains_kotlin"

# Add in filepaths
for file in ctx.files.srcs:
inputs += [file]
args += [file.path]

# Add all home libs to sandbox
inputs += ctx.files._kotlin_home

# Run the compiler
ctx.action(
mnemonic = "KotlinCompile",
inputs = inputs,
outputs = [kt_jar],
executable = ctx.executable._kotlinc,
arguments = args,
env = {
"KOTLIN_HOME": kotlin_home,
}
)

return struct(
Expand All @@ -79,7 +78,6 @@ def _kotlin_compile_impl(ctx):
srcs = ctx.attr.srcs,
jar = kt_jar,
transitive_jars = [kt_jar] + jars,
home = kotlin_home,
),
)

Expand Down Expand Up @@ -132,9 +130,15 @@ _kotlin_compile_attrs = {
cfg = 'host',
),

# kotlin home (for runtime libraries discovery)
"_kotlin_home": attr.label(
default=Label("@com_github_jetbrains_kotlin//:home"),
),

# kotlin runtime
"_runtime": attr.label(
default=Label("@com_github_jetbrains_kotlin//:runtime"),
single_file = True,
),

}
Expand Down Expand Up @@ -207,6 +211,10 @@ def kotlin_binary(name,

KOTLIN_BUILD = """
package(default_visibility = ["//visibility:public"])
filegroup(
name = "home",
srcs = glob(["lib/*.jar"]),
)
java_import(
name = "runtime",
jars = ["lib/kotlin-runtime.jar"],
Expand Down

0 comments on commit 663285b

Please sign in to comment.