kt_toolchain_ide_info rule generating ide toolchain json file and restructure skylark a bit
diff --git a/Makefile b/Makefile
index 2ea059b..1d86e39 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@
reformat:
buildifier -mode=fix -v kotlin/*.bzl
- buildifier -mode=fix -v kotlin/rules/*.bzl
+ buildifier -mode=fix -v kotlin/internal/*.bzl
docs.regen:
bazel build //docs
diff --git a/docs/index.html b/docs/index.html
index 60c7bc9..6bf282a 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -59,12 +59,11 @@
</ul>
</li>
<li>
- <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html">Kotlin Toolchains</a>
+ <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html">toolchains Rules</a>
<ul>
- <li><a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html#overview">Overview</a></li>
<li>
- <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html#kt_jvm_toolchain">
- kt_jvm_toolchain
+ <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html#kt_toolchain">
+ kt_toolchain
</a>
</li>
</ul>
@@ -83,7 +82,7 @@
<h2>Rule sets</h2>
<ul>
<li><a href="#kotlin">Kotlin Rules</a></li>
- <li><a href="#toolchains">Kotlin Toolchains</a></li>
+ <li><a href="#toolchains">toolchains Rules</a></li>
</ul>
</nav>
@@ -174,7 +173,7 @@
</tr>
</tbody>
</table>
-<h2><a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html">Kotlin Toolchains</a></h2>
+<h2><a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html">toolchains Rules</a></h2>
<h3>Rules</h3>
<table class="overview-table">
@@ -185,8 +184,8 @@
<tbody>
<tr>
<td>
- <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html#kt_jvm_toolchain">
- <code>kt_jvm_toolchain</code>
+ <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html#kt_toolchain">
+ <code>kt_toolchain</code>
</a>
</td>
<td>
@@ -205,8 +204,8 @@
<tbody>
<tr>
<td>
- <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html#define_kt_jvm_toolchain">
- <code>define_kt_jvm_toolchain</code>
+ <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html#define_kt_toolchain">
+ <code>define_kt_toolchain</code>
</a>
</td>
<td>
@@ -214,17 +213,6 @@
</td>
</tr>
- <tr>
- <td>
- <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html#kt_register_jvm_toolchain">
- <code>kt_register_jvm_toolchain</code>
- </a>
- </td>
- <td>
- <p>Register the default JVM toolchain.</p>
-
- </td>
- </tr>
</tbody>
</table>
diff --git a/docs/kotlin/kotlin.html b/docs/kotlin/kotlin.html
index 9569070..640b263 100644
--- a/docs/kotlin/kotlin.html
+++ b/docs/kotlin/kotlin.html
@@ -59,12 +59,11 @@
</ul>
</li>
<li>
- <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html">Kotlin Toolchains</a>
+ <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html">toolchains Rules</a>
<ul>
- <li><a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html#overview">Overview</a></li>
<li>
- <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html#kt_jvm_toolchain">
- kt_jvm_toolchain
+ <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html#kt_toolchain">
+ kt_toolchain
</a>
</li>
</ul>
diff --git a/docs/kotlin/toolchains.html b/docs/kotlin/toolchains.html
index 8b7764f..8617634 100644
--- a/docs/kotlin/toolchains.html
+++ b/docs/kotlin/toolchains.html
@@ -10,7 +10,7 @@
<meta name="viewport" content="width=device-width initial-scale=1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
- <title>Kotlin Toolchains</title>
+ <title>toolchains Rules</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,600,700" type="text/css">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
@@ -23,7 +23,7 @@
mdl-layout--fixed-header">
<header class="mdl-layout__header">
<div class="mdl-layout__header-row">
- <span class="mdl-layout-title">Kotlin Toolchains</span>
+ <span class="mdl-layout-title">toolchains Rules</span>
</div>
</header>
<div class="mdl-layout__drawer">
@@ -59,12 +59,11 @@
</ul>
</li>
<li>
- <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html">Kotlin Toolchains</a>
+ <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html">toolchains Rules</a>
<ul>
- <li><a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html#overview">Overview</a></li>
<li>
- <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html#kt_jvm_toolchain">
- kt_jvm_toolchain
+ <a href="https://bazelbuild.github.io/rules_kotlin/kotlin/toolchains.html#kt_toolchain">
+ kt_toolchain
</a>
</li>
</ul>
@@ -76,47 +75,28 @@
<main class="mdl-layout__content">
<div class="page-content">
- <h1>Kotlin Toolchains</h1>
+ <h1>toolchains Rules</h1>
<nav class="toc">
- <h2><a href="#overview">Overview</a></h2>
<h2>Rules</h2>
<ul>
- <li><a href="#kt_jvm_toolchain">kt_jvm_toolchain</a></li>
+ <li><a href="#kt_toolchain">kt_toolchain</a></li>
</ul>
<h2>Macros</h2>
<ul>
- <li><a href="#define_kt_jvm_toolchain">define_kt_jvm_toolchain</a></li>
- <li><a href="#kt_register_jvm_toolchain">kt_register_jvm_toolchain</a></li>
+ <li><a href="#define_kt_toolchain">define_kt_toolchain</a></li>
</ul>
</nav>
<hr>
- <h2 id="overview">Overview</h2>
- <p>This file contains macros for defining and registering specific toolchains.</p>
-<h3>Examples</h3>
-<p>To override a tool chain use the appropriate macro in a <code>BUILD</code> file to declare the toolchain:</p>
-<pre><code class="lang-bzl">load("@io_bazel_rules_kotlin//kotlin:toolchains.bzl", "define_kt_jvm_toolchain")
-define_kt_jvm_toolchain(
- name= "custom_toolchain",
- api_version = "1.1",
- language_version = "1.1",
-)
-</code></pre>
-<p>and then register it in the <code>WORKSPACE</code>:</p>
-<pre><code class="lang-bzl">register_toolchains("//:custom_toolchain")
-</code></pre>
+ <h2 id="define_kt_toolchain">define_kt_toolchain</h2>
- <hr>
-
- <h2 id="define_kt_jvm_toolchain">define_kt_jvm_toolchain</h2>
-
- <pre>define_kt_jvm_toolchain(<a href="#define_kt_jvm_toolchain.name">name</a>, <a href="#define_kt_jvm_toolchain.language_version">language_version</a>, <a href="#define_kt_jvm_toolchain.api_version">api_version</a>, <a href="#define_kt_jvm_toolchain.jvm_target">jvm_target</a>, <a href="#define_kt_jvm_toolchain.coroutines">coroutines</a>)</pre>
+ <pre>define_kt_toolchain(<a href="#define_kt_toolchain.name">name</a>, <a href="#define_kt_toolchain.language_version">language_version</a>, <a href="#define_kt_toolchain.api_version">api_version</a>, <a href="#define_kt_toolchain.jvm_target">jvm_target</a>, <a href="#define_kt_toolchain.coroutines">coroutines</a>)</pre>
<p>Define a Kotlin JVM Toolchain, the name is used in the <code>toolchain</code> rule so can be used to register the toolchain in the WORKSPACE file.</p>
- <h3 id="define_kt_jvm_toolchain_args">Attributes</h3>
+ <h3 id="define_kt_toolchain_args">Attributes</h3>
<table class="params-table">
<colgroup>
@@ -124,35 +104,35 @@
<col class="col-description" />
</colgroup>
<tbody>
- <tr id="define_kt_jvm_toolchain.name">
+ <tr id="define_kt_toolchain.name">
<td><code>name</code></td>
<td>
<p><code><a href="https://bazel.build/docs/build-ref.html#name">Name</a>; Required</code></p>
<p>A unique name for this rule.</p>
</td>
</tr>
- <tr id="define_kt_jvm_toolchain.language_version">
+ <tr id="define_kt_toolchain.language_version">
<td><code>language_version</code></td>
<td>
<p><code>Unknown; Optional</code></p>
</td>
</tr>
- <tr id="define_kt_jvm_toolchain.api_version">
+ <tr id="define_kt_toolchain.api_version">
<td><code>api_version</code></td>
<td>
<p><code>Unknown; Optional</code></p>
</td>
</tr>
- <tr id="define_kt_jvm_toolchain.jvm_target">
+ <tr id="define_kt_toolchain.jvm_target">
<td><code>jvm_target</code></td>
<td>
<p><code>Unknown; Optional</code></p>
</td>
</tr>
- <tr id="define_kt_jvm_toolchain.coroutines">
+ <tr id="define_kt_toolchain.coroutines">
<td><code>coroutines</code></td>
<td>
<p><code>Unknown; Optional</code></p>
@@ -163,23 +143,14 @@
</table>
<hr>
- <h2 id="kt_register_jvm_toolchain">kt_register_jvm_toolchain</h2>
+ <h2 id="kt_toolchain">kt_toolchain</h2>
- <pre>kt_register_jvm_toolchain()</pre>
-
- <p>Register the default JVM toolchain.</p>
-
-
- <hr>
-
- <h2 id="kt_jvm_toolchain">kt_jvm_toolchain</h2>
-
- <pre>kt_jvm_toolchain(<a href="#kt_jvm_toolchain.name">name</a>, <a href="#kt_jvm_toolchain.api_version">api_version</a>, <a href="#kt_jvm_toolchain.coroutines">coroutines</a>, <a href="#kt_jvm_toolchain.jvm_target">jvm_target</a>, <a href="#kt_jvm_toolchain.language_version">language_version</a>)</pre>
+ <pre>kt_toolchain(<a href="#kt_toolchain.name">name</a>, <a href="#kt_toolchain.api_version">api_version</a>, <a href="#kt_toolchain.coroutines">coroutines</a>, <a href="#kt_toolchain.jvm_target">jvm_target</a>, <a href="#kt_toolchain.language_version">language_version</a>)</pre>
<p>The kotlin jvm toolchain</p>
- <h3 id="kt_jvm_toolchain_args">Attributes</h3>
+ <h3 id="kt_toolchain_args">Attributes</h3>
<table class="params-table">
<colgroup>
@@ -187,35 +158,35 @@
<col class="col-description" />
</colgroup>
<tbody>
- <tr id="kt_jvm_toolchain.name">
+ <tr id="kt_toolchain.name">
<td><code>name</code></td>
<td>
<p><code><a href="https://bazel.build/docs/build-ref.html#name">Name</a>; Required</code></p>
<p>A unique name for this rule.</p>
</td>
</tr>
- <tr id="kt_jvm_toolchain.api_version">
+ <tr id="kt_toolchain.api_version">
<td><code>api_version</code></td>
<td>
<p><code>String; Optional; Default is '1.2'</code></p>
<p>the -api_version flag <a href="https://kotlinlang.org/docs/reference/compatibility.html">see</a>.</p>
</td>
</tr>
- <tr id="kt_jvm_toolchain.coroutines">
+ <tr id="kt_toolchain.coroutines">
<td><code>coroutines</code></td>
<td>
<p><code>String; Optional; Default is 'enable'</code></p>
<p>the -Xcoroutines flag, enabled by default as it's considered production ready 1.2.0 onward.</p>
</td>
</tr>
- <tr id="kt_jvm_toolchain.jvm_target">
+ <tr id="kt_toolchain.jvm_target">
<td><code>jvm_target</code></td>
<td>
<p><code>String; Optional; Default is '1.8'</code></p>
<p>the -jvm_target flag.</p>
</td>
</tr>
- <tr id="kt_jvm_toolchain.language_version">
+ <tr id="kt_toolchain.language_version">
<td><code>language_version</code></td>
<td>
<p><code>String; Optional; Default is '1.2'</code></p>
diff --git a/kotlin/BUILD b/kotlin/BUILD
index 7411d64..d20fe7f 100644
--- a/kotlin/BUILD
+++ b/kotlin/BUILD
@@ -13,13 +13,16 @@
# limitations under the License.
package(default_visibility = ["//visibility:public"])
-load("//kotlin:toolchains.bzl", "define_kt_jvm_toolchain")
+load("//kotlin:toolchains.bzl", "define_kt_toolchain")
+load("//kotlin/internal:bootstrap.bzl", "kt_toolchain_ide_info")
toolchain_type(
- name = "kt_jvm_toolchain_type",
+ name = "kt_toolchain_type",
visibility = ["//visibility:public"]
)
-define_kt_jvm_toolchain(name = "default_jvm_toolchain")
+define_kt_toolchain(name = "default_toolchain")
+
+kt_toolchain_ide_info(name="kt_toolchain_ide_info")
exports_files(["toolchains.bzl", "kotlin.bzl"], visibility=["//docs:__subpackages__"])
\ No newline at end of file
diff --git a/kotlin/rules/BUILD b/kotlin/internal/BUILD
similarity index 100%
rename from kotlin/rules/BUILD
rename to kotlin/internal/BUILD
diff --git a/kotlin/internal/bootstrap.bzl b/kotlin/internal/bootstrap.bzl
new file mode 100644
index 0000000..2513c40
--- /dev/null
+++ b/kotlin/internal/bootstrap.bzl
@@ -0,0 +1,56 @@
+# Copyright 2018 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""This file contains rules used to bootstrap the compiler repository."""
+
+load("//kotlin/internal:kt.bzl", "kt")
+load("//kotlin/internal:rules.bzl", _kt_jvm_import_impl="kt_jvm_import_impl")
+
+kotlin_stdlib = rule(
+ attrs = {
+ "jars": attr.label_list(
+ allow_files = True,
+ mandatory = True,
+ cfg = "host",
+ ),
+ "srcjar": attr.label(
+ allow_single_file = True,
+ cfg = "host",
+ ),
+ },
+ implementation = _kt_jvm_import_impl,
+)
+
+"""Import Kotlin libraries that are part of the compiler release."""
+
+def _kt_toolchain_ide_info_impl(ctx):
+ tc=ctx.toolchains[kt.defs.TOOLCHAIN_TYPE]
+ info = struct(
+ label = tc.label,
+ common = struct(
+ language_version = tc.language_version,
+ api_version = tc.api_version,
+ coroutines = tc.coroutines
+ ),
+ jvm = struct(
+ jvm_target = tc.jvm_target,
+ )
+ )
+ ctx.actions.write(ctx.outputs.ide_info, info.to_json())
+ return [DefaultInfo(files=depset([ctx.outputs.ide_info]))]
+
+kt_toolchain_ide_info = rule(
+ outputs = {"ide_info": "kt_toolchain_ide_info.json"},
+ toolchains = [kt.defs.TOOLCHAIN_TYPE],
+ implementation = _kt_toolchain_ide_info_impl,
+)
diff --git a/kotlin/rules/compile.bzl b/kotlin/internal/compile.bzl
similarity index 86%
rename from kotlin/rules/compile.bzl
rename to kotlin/internal/compile.bzl
index 5000d20..b2b6e91 100644
--- a/kotlin/rules/compile.bzl
+++ b/kotlin/internal/compile.bzl
@@ -11,22 +11,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-load(
- "//kotlin/rules:defs.bzl",
- _KotlinInfo = "KotlinInfo",
-)
-load(
- "//kotlin/rules:plugins.bzl",
- _merge_plugin_infos = "merge_plugin_infos",
-)
-load(
- "//kotlin/rules:util.bzl",
- _collect_all_jars = "collect_all_jars",
- _collect_jars_for_compile = "collect_jars_for_compile",
- _kotlin_build_resourcejar_action = "kotlin_build_resourcejar_action",
- _kotlin_fold_jars_action = "kotlin_fold_jars_action",
- _kotlin_maybe_make_srcs_action = "kotlin_maybe_make_srcs_action",
-)
+load("//kotlin/internal:kt.bzl", "kt")
+load("//kotlin/internal:plugins.bzl", "plugins")
+load("//kotlin/internal:utils.bzl", "utils")
def _kotlin_do_compile_action(ctx, output_jar, compile_jars, opts):
"""Internal macro that sets up a Kotlin compile action.
@@ -45,7 +32,7 @@
opts: struct containing Kotlin compilation options.
"""
compiler_output_base=ctx.actions.declare_directory(ctx.label.name + "." + "kotlinc")
- tc=ctx.toolchains["@io_bazel_rules_kotlin//kotlin:kt_jvm_toolchain_type"]
+ tc=ctx.toolchains[kt.defs.TOOLCHAIN_TYPE]
args = [
"--target_label", ctx.label,
"--compiler_output_base", compiler_output_base.path,
@@ -60,7 +47,7 @@
"--kotlin_passthrough_flags", "-Xcoroutines=%s" % tc.coroutines
]
# Collect and prepare plugin descriptor for the worker.
- plugin_info=_merge_plugin_infos(ctx.attr.plugins + ctx.attr.deps)
+ plugin_info=plugins.merge_plugin_infos(ctx.attr.plugins + ctx.attr.deps)
if len(plugin_info.processors) > 0:
args += [ "--kt-plugins", plugin_info.to_json() ]
@@ -118,8 +105,8 @@
Returns:
A JavaInfo provider.
"""
- deps=_collect_all_jars(ctx.attr.deps)
- exported_deps=_collect_all_jars(getattr(ctx.attr, "exports", []))
+ deps=utils.collect_all_jars(ctx.attr.deps)
+ exported_deps=utils.collect_all_jars(getattr(ctx.attr, "exports", []))
my_compile_jars = exported_deps.compile_jars + [ctx.outputs.jar]
my_runtime_jars = exported_deps.runtime_jars + [ctx.outputs.jar]
@@ -135,7 +122,7 @@
use_ijar = False,
# A list or set of output source jars that contain the uncompiled source files including the source files
# generated by annotation processors if the case.
- source_jars=_kotlin_maybe_make_srcs_action(ctx),
+ source_jars=utils.actions.maybe_make_srcsjar(ctx),
# A list or a set of jars that should be used at compilation for a given target.
compile_time_jars = my_compile_jars,
# A list or a set of jars that should be used at runtime for a given target.
@@ -144,8 +131,8 @@
transitive_runtime_jars=my_transitive_runtime_jars
)
-def kotlin_make_providers(ctx, java_info, transitive_files=depset(order="default")):
- kotlin_info=_KotlinInfo(
+def _make_providers(ctx, java_info, transitive_files=depset(order="default")):
+ kotlin_info=kt.info.KtInfo(
src=ctx.attr.srcs,
outputs = struct(
jdeps = ctx.outputs.jdeps,
@@ -169,7 +156,7 @@
providers=[java_info,default_info,kotlin_info],
)
-def kotlin_compile_action(ctx):
+def _compile_action (ctx):
"""Setup a kotlin compile action.
Args:
@@ -187,7 +174,7 @@
# If this rule has any resources declared setup a zipper action to turn them into a jar and then add the declared zipper output to the merge list.
if len(ctx.files.resources) > 0:
- output_merge_list = output_merge_list + [_kotlin_build_resourcejar_action(ctx)]
+ output_merge_list = output_merge_list + [utils.actions.build_resourcejar(ctx)]
# If this compile operation requires merging other jars setup the compile operation to go to a intermediate file and add that file to the merge list.
if len(output_merge_list) > 0:
@@ -202,12 +189,17 @@
_kotlin_do_compile_action(
ctx,
kt_compile_output_jar,
- _collect_jars_for_compile(ctx.attr.deps) + kotlin_auto_deps,
+ utils.collect_jars_for_compile(ctx.attr.deps) + kotlin_auto_deps,
_select_compilation_options(ctx)
)
# setup the merge action if needed.
if len(output_merge_list) > 0:
- _kotlin_fold_jars_action(ctx, output_jar, output_merge_list)
+ utils.actions.fold_jars(ctx, output_jar, output_merge_list)
# create the java provider but the kotlin and default provider cannot be created here.
- return _make_java_provider(ctx, kotlin_auto_deps)
\ No newline at end of file
+ return _make_java_provider(ctx, kotlin_auto_deps)
+
+compile = struct(
+ compile_action = _compile_action,
+ make_providers = _make_providers,
+)
diff --git a/kotlin/rules/defs.bzl b/kotlin/internal/kt.bzl
similarity index 67%
rename from kotlin/rules/defs.bzl
rename to kotlin/internal/kt.bzl
index f7564db..cd8d1e7 100644
--- a/kotlin/rules/defs.bzl
+++ b/kotlin/internal/kt.bzl
@@ -11,27 +11,35 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-
-# The name of the rules repo. Centralised so it's easy to change.
-REPO_ROOT = "io_bazel_rules_kotlin"
-
-# The name of the Kotlin compiler workspace.
-KOTLIN_REPO_ROOT = "com_github_jetbrains_kotlin"
-
########################################################################################################################
# Providers
########################################################################################################################
-KotlinInfo = provider(
+_defs = struct(
+ DEFAULT_TOOLCHAIN = "@io_bazel_rules_kotlin//kotlin:default_toolchain",
+ # The name of the Kotlin compiler workspace.
+ KT_COMPILER_REPO = "com_github_jetbrains_kotlin",
+ # The name of the rules repo. Centralised so it's easy to change.
+ REPO_ROOT = "io_bazel_rules_kotlin",
+ TOOLCHAIN_TYPE = "@io_bazel_rules_kotlin//kotlin:kt_toolchain_type",
+)
+
+_KtInfo = provider(
fields = {
"src": "the source files. [intelij-aspect]",
"outputs": "output jars produced by this rule. [intelij-aspect]",
},
)
-KotlinPluginInfo = provider(
+_KtPluginInfo = provider(
fields = {
"processors": "a serializeable list of structs containing an annotation processor definitions",
},
)
-"""a serializable provider containing plugin descriptors that can be processed by the worker"""
+kt = struct(
+ defs = _defs,
+ info = struct(
+ KtInfo = _KtInfo,
+ KtPluginInfo = _KtPluginInfo,
+ ),
+)
diff --git a/kotlin/internal/plugins.bzl b/kotlin/internal/plugins.bzl
new file mode 100644
index 0000000..85ed686
--- /dev/null
+++ b/kotlin/internal/plugins.bzl
@@ -0,0 +1,66 @@
+# Copyright 2018 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+load("//kotlin/internal:kt.bzl", "kt")
+
+def _mk_processor_entry(l,p):
+ return struct(
+ label=l,
+ processor_class=p.processor_class,
+ classpath=[cp.path for cp in java_common.merge([j[JavaInfo] for j in p.deps]).full_compile_jars],
+ generates_api=p.generates_api,
+ )
+
+def _merge_plugin_infos(attrs):
+ tally={}
+ processors=[]
+ for info in [a[kt.info.KtPluginInfo] for a in attrs]:
+ for p in info.processors:
+ if p.label not in tally:
+ tally[p.label] = True
+ processors.append(p)
+ return kt.info.KtPluginInfo(processors=processors)
+
+def _restore_label(l):
+ lbl = l.workspace_root
+ if lbl.startswith("external/"):
+ lbl = lbl.replace("external/", "@")
+ return lbl + "//" + l.package + ":" + l.name
+
+_EMPTY_PLUGIN_INFO = [kt.info.KtPluginInfo(processors = [])]
+
+def _kt_jvm_plugin_aspect_impl(target, ctx):
+ if ctx.rule.kind == "java_plugin":
+ return [kt.info.KtPluginInfo(
+ processors = [_mk_processor_entry(_restore_label(ctx.label),ctx.rule.attr)]
+ )]
+ else:
+ if ctx.rule.kind == "java_library":
+ return [_merge_plugin_infos(ctx.rule.attr.exported_plugins)]
+ else:
+ return _EMPTY_PLUGIN_INFO
+
+kt_jvm_plugin_aspect = aspect(
+ attr_aspects = [
+ "plugins",
+ "exported_plugins",
+ ],
+ implementation = _kt_jvm_plugin_aspect_impl,
+)
+
+"""renders a java info into a kt.info.KtPluginInfo."""
+
+plugins = struct(
+ kt_jvm_plugin_aspect = kt_jvm_plugin_aspect,
+ merge_plugin_infos = _merge_plugin_infos,
+)
diff --git a/kotlin/rules/rules.bzl b/kotlin/internal/rules.bzl
similarity index 78%
rename from kotlin/rules/rules.bzl
rename to kotlin/internal/rules.bzl
index b2c5595..93047ab 100644
--- a/kotlin/rules/rules.bzl
+++ b/kotlin/internal/rules.bzl
@@ -12,19 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-load(
- "//kotlin/rules:compile.bzl",
- _kotlin_compile_action = "kotlin_compile_action",
- _kotlin_make_providers = "kotlin_make_providers",
-)
-load(
- "//kotlin/rules:util.bzl",
- _kotlin_write_launcher_action = "kotlin_write_launcher_action",
-)
-load(
- "//kotlin/rules:defs.bzl",
- _KotlinInfo = "KotlinInfo",
-)
+load("//kotlin/internal:compile.bzl", "compile")
+load("//kotlin/internal:kt.bzl", "kt")
+load("//kotlin/internal:utils.bzl", "utils")
def _extract_kotlin_artifact(files):
jars = [j for j in files if j.basename.endswith(".jar") and not j.basename.endswith("-sources.jar")]
@@ -48,7 +38,7 @@
fail("the srcjar attribute should not be set when importing multiple class jars")
return artifacts
-def kotlin_import_impl(ctx):
+def kt_jvm_import_impl(ctx):
artifacts=_collect_import_artifacts(ctx)
jars = [a.class_jar for a in artifacts]
@@ -61,22 +51,22 @@
transitive_compile_time_jars=jars,
transitive_runtime_jars=jars
)
- kotlin_info=_KotlinInfo(outputs = struct(jars = artifacts))
+ kotlin_info=kt.info.KtInfo(outputs = struct(jars = artifacts))
default_info = DefaultInfo(files=depset(jars))
return struct(kt = kotlin_info, providers= [default_info, java_info, kotlin_info])
-def kotlin_library_impl(ctx):
- return _kotlin_make_providers(ctx, _kotlin_compile_action(ctx))
+def kt_jvm_library_impl(ctx):
+ return compile.make_providers(ctx, compile.compile_action(ctx))
-def kotlin_binary_impl(ctx):
- java_info = _kotlin_compile_action(ctx)
- _kotlin_write_launcher_action(
+def kt_jvm_binary_impl(ctx):
+ java_info = compile.compile_action(ctx)
+ utils.actions.write_launcher(
ctx,
java_info.transitive_runtime_jars,
ctx.attr.main_class,
ctx.attr.jvm_flags
)
- return _kotlin_make_providers(
+ return compile.make_providers(
ctx,
java_info,
depset(
@@ -86,19 +76,19 @@
)
)
-def kotlin_junit_test_impl(ctx):
- java_info = _kotlin_compile_action(ctx)
+def kt_jvm_junit_test_impl(ctx):
+ java_info = compile.compile_action(ctx)
transitive_runtime_jars = java_info.transitive_runtime_jars + ctx.files._bazel_test_runner
launcherJvmFlags = ["-ea", "-Dbazel.test_suite=%s"% ctx.attr.test_class]
- _kotlin_write_launcher_action(
+ utils.actions.write_launcher(
ctx,
transitive_runtime_jars,
main_class = "com.google.testing.junit.runner.BazelTestRunner",
jvm_flags = launcherJvmFlags + ctx.attr.jvm_flags,
)
- return _kotlin_make_providers(
+ return compile.make_providers(
ctx,
java_info,
depset(
diff --git a/kotlin/rules/util.bzl b/kotlin/internal/utils.bzl
similarity index 78%
rename from kotlin/rules/util.bzl
rename to kotlin/internal/utils.bzl
index 2338a04..7b6ce28 100644
--- a/kotlin/rules/util.bzl
+++ b/kotlin/internal/utils.bzl
@@ -12,14 +12,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-load("//kotlin/rules:defs.bzl", "KotlinInfo")
+load(
+ "//kotlin/internal:kt.bzl",
+ kt = "kt",
+)
-# DEPSET UTILS #########################################################################################################
+# MISC UTILS ###################################################################################################################################################
+def _restore_label(l):
+ lbl = l.workspace_root
+ if lbl.startswith("external/"):
+ lbl = lbl.replace("external/", "@")
+ return lbl + "//" + l.package + ":" + l.name
+
+# DEPSET UTILS #################################################################################################################################################
def _select_compile_jars(dep):
"""selects the correct compile time jar from a java provider"""
if not JavaInfo in dep:
return []
- is_kotlin_provider = KotlinInfo in dep
+ is_kotlin_provider = kt.info.KtInfo in dep
java_provider = dep[JavaInfo]
if is_kotlin_provider:
return java_provider.full_compile_jars
@@ -28,7 +38,7 @@
else:
return java_provider.compile_jars
-def collect_jars_for_compile(deps):
+def _collect_jars_for_compile(deps):
"""creates the compile jar depset, this should be strict including only the output jars of the listed dependencies.
"""
compile_jars = depset()
@@ -36,7 +46,7 @@
compile_jars += _select_compile_jars(d)
return compile_jars
-def collect_all_jars(deps):
+def _collect_all_jars(deps):
"""
Merges a list of java providers into a struct of depsets.
"""
@@ -61,7 +71,7 @@
transitive_compile_time_jars = transitive_compile_time_jars
)
-# RESOURCE JARS ########################################################################################################
+# RESOURCE JARS ################################################################################################################################################
_CONVENTIONAL_RESOURCE_PATHS = [
"src/main/resources",
"src/test/resources",
@@ -101,7 +111,7 @@
res_cmd.extend([line])
return "".join(res_cmd)
-def kotlin_build_resourcejar_action(ctx):
+def _build_resourcejar_action(ctx):
resources = _add_resources_cmd(ctx)
resources_jar_output = ctx.actions.declare_file(ctx.label.name + "-resources.jar")
zipper_arg_path = ctx.actions.declare_file("%s_resources_zipper_args" % ctx.label.name)
@@ -124,8 +134,8 @@
)
return resources_jar_output
-# SRC JARS #############################################################################################################
-def kotlin_maybe_make_srcs_action(ctx):
+# SRC JARS #####################################################################################################################################################
+def _maybe_make_srcsjar_action(ctx):
if len(ctx.files.srcs) > 0:
output_srcjar = ctx.actions.declare_file(ctx.label.name + "-sources.jar")
args = ["--output", output_srcjar.path]
@@ -144,8 +154,8 @@
else:
return []
-# PACKAGE JARS #########################################################################################################
-def kotlin_fold_jars_action(ctx, output_jar, input_jars):
+# PACKAGE JARS #################################################################################################################################################
+def _fold_jars_action(ctx, output_jar, input_jars):
args=["--output", output_jar.path]
for i in input_jars:
args += ["--sources", i.path]
@@ -159,8 +169,8 @@
progress_message="Merging Kotlin output jar " + output_jar.short_path
)
-# JVM LAUNCH SCRIPTS ###################################################################################################
-def kotlin_write_launcher_action(ctx, rjars, main_class, jvm_flags, args="", wrapper_preamble=""):
+# JVM LAUNCH SCRIPTS ###########################################################################################################################################
+def _write_launcher_action(ctx, rjars, main_class, jvm_flags, args="", wrapper_preamble=""):
"""Macro that writes out a launcher script shell script.
Args:
rjars: All of the runtime jars required to launch this java target.
@@ -184,4 +194,17 @@
"%workspace_prefix%": ctx.workspace_name + "/",
},
is_executable = True,
- )
\ No newline at end of file
+ )
+
+# EXPORT #######################################################################################################################################################
+utils = struct(
+ actions = struct(
+ build_resourcejar = _build_resourcejar_action,
+ fold_jars = _fold_jars_action,
+ maybe_make_srcsjar = _maybe_make_srcsjar_action,
+ write_launcher = _write_launcher_action,
+ ),
+ collect_all_jars = _collect_all_jars,
+ collect_jars_for_compile = _collect_jars_for_compile,
+ restore_label = _restore_label,
+)
diff --git a/kotlin/kotlin.bzl b/kotlin/kotlin.bzl
index 0d2b5b0..d624907 100644
--- a/kotlin/kotlin.bzl
+++ b/kotlin/kotlin.bzl
@@ -96,12 +96,26 @@
########################################################################################################################
load(
- "//kotlin/rules:defs.bzl",
- "KOTLIN_REPO_ROOT",
+ "//kotlin/internal:kt.bzl",
+ _kt = "kt",
+)
+# struct can't be used till skydoc is removed
+load(
+ "//kotlin/internal:plugins.bzl",
+ _kt_jvm_plugin_aspect="kt_jvm_plugin_aspect",
+)
+# struct can't be used till skydoc is removed
+load(
+ "//kotlin/internal:rules.bzl",
+ _kt_jvm_binary_impl = "kt_jvm_binary_impl",
+ _kt_jvm_import_impl = "kt_jvm_import_impl",
+ _kt_jvm_junit_test_impl = "kt_jvm_junit_test_impl",
+ _kt_jvm_library_impl = "kt_jvm_library_impl",
)
load(
- "//kotlin/rules:plugins.bzl",
- _kt_jvm_plugin_aspect = "kt_jvm_plugin_aspect",
+ "//kotlin:kotlin_compiler_repositories.bzl",
+ "KOTLIN_CURRENT_RELEASE",
+ _kotlin_compiler_repository = "kotlin_compiler_repository",
)
# The files types that may be passed to the core Kotlin compile rule.
@@ -116,6 +130,9 @@
".jar",
"-sources.jar",
])
+# _kt.defs.KT_COMPILER_REPO can't be used till skydoc is removed
+KT_COMPILER_REPO="com_github_jetbrains_kotlin"
+
########################################################################################################################
# Rule Attributes
@@ -124,13 +141,13 @@
"_kotlin_compiler_classpath": attr.label_list(
allow_files = True,
default = [
- Label("@" + KOTLIN_REPO_ROOT + "//:compiler"),
- Label("@" + KOTLIN_REPO_ROOT + "//:reflect"),
- Label("@" + KOTLIN_REPO_ROOT + "//:script-runtime"),
+ Label("@" + KT_COMPILER_REPO + "//:compiler"),
+ Label("@" + KT_COMPILER_REPO + "//:reflect"),
+ Label("@" + KT_COMPILER_REPO + "//:script-runtime"),
],
),
"_kotlin_home": attr.label(
- default = Label("@" + KOTLIN_REPO_ROOT + "//:home"),
+ default = Label("@" + KT_COMPILER_REPO + "//:home"),
allow_files = True,
cfg = "host",
),
@@ -141,17 +158,23 @@
),
"_kotlin_runtime": attr.label(
single_file = True,
- default = Label("@" + KOTLIN_REPO_ROOT + "//:runtime"),
+ default = Label("@" + KT_COMPILER_REPO + "//:runtime"),
),
"_kotlin_std": attr.label_list(default = [
- Label("@" + KOTLIN_REPO_ROOT + "//:stdlib"),
- Label("@" + KOTLIN_REPO_ROOT + "//:stdlib-jdk7"),
- Label("@" + KOTLIN_REPO_ROOT + "//:stdlib-jdk8"),
+ Label("@" + KT_COMPILER_REPO + "//:stdlib"),
+ Label("@" + KT_COMPILER_REPO + "//:stdlib-jdk7"),
+ Label("@" + KT_COMPILER_REPO + "//:stdlib-jdk8"),
]),
+ "_kotlin_toolchain": attr.label_list(
+ default = [
+ Label("@io_bazel_rules_kotlin//kotlin:kt_toolchain_ide_info"),
+ ],
+ allow_files = False,
+ ),
"_kotlin_reflect": attr.label(
single_file = True,
default =
- Label("@" + KOTLIN_REPO_ROOT + "//:reflect"),
+ Label("@" + KT_COMPILER_REPO + "//:reflect"),
),
"_singlejar": attr.label(
executable = True,
@@ -200,7 +223,7 @@
default = [],
aspects = [_kt_jvm_plugin_aspect],
),
- "module_name": attr.string()
+ "module_name": attr.string(),
}.items())
_runnable_common_attr = dict(_common_attr.items() + {
@@ -224,12 +247,6 @@
########################################################################################################################
# Repositories and Toolchains
########################################################################################################################
-load(
- "//kotlin:kotlin_compiler_repositories.bzl",
- "KOTLIN_CURRENT_RELEASE",
- _kotlin_compiler_repository = "kotlin_compiler_repository",
-)
-
def kotlin_repositories(
kotlin_release_version=KOTLIN_CURRENT_RELEASE
):
@@ -241,30 +258,20 @@
"""
_kotlin_compiler_repository(kotlin_release_version)
-load("//kotlin:toolchains.bzl", _kt_register_jvm_toolchain="kt_register_jvm_toolchain")
-
def kt_register_toolchains():
"""register all default toolchains"""
- _kt_register_jvm_toolchain()
+ native.register_toolchains(_kt.defs.DEFAULT_TOOLCHAIN)
########################################################################################################################
# Simple Rules:
########################################################################################################################
-load(
- "//kotlin/rules:rules.bzl",
- _kotlin_binary_impl = "kotlin_binary_impl",
- _kotlin_import_impl = "kotlin_import_impl",
- _kotlin_junit_test_impl = "kotlin_junit_test_impl",
- _kotlin_library_impl = "kotlin_library_impl",
-)
-
kt_jvm_library = rule(
attrs = dict(_common_attr.items() + {
- "exports": attr.label_list(default = [])
+ "exports": attr.label_list(default = []),
}.items()),
outputs = _common_outputs,
- implementation = _kotlin_library_impl,
- toolchains = ["@io_bazel_rules_kotlin//kotlin:kt_jvm_toolchain_type"]
+ toolchains = [_kt.defs.TOOLCHAIN_TYPE],
+ implementation = _kt_jvm_library_impl,
)
"""This rule compiles and links Kotlin and Java sources into a .jar file.
@@ -291,8 +298,8 @@
attrs = dict(_runnable_common_attr.items() + {"main_class": attr.string(mandatory = True)}.items()),
executable = True,
outputs = _binary_outputs,
- implementation = _kotlin_binary_impl,
- toolchains = ["@io_bazel_rules_kotlin//kotlin:kt_jvm_toolchain_type"]
+ toolchains = [_kt.defs.TOOLCHAIN_TYPE],
+ implementation = _kt_jvm_binary_impl,
)
"""Builds a Java archive ("jar file"), plus a wrapper shell script with the same name as the rule. The wrapper shell script uses a classpath that includes,
@@ -318,8 +325,8 @@
executable = True,
outputs = _binary_outputs,
test = True,
- implementation = _kotlin_junit_test_impl,
- toolchains = ["@io_bazel_rules_kotlin//kotlin:kt_jvm_toolchain_type"]
+ toolchains = [_kt.defs.TOOLCHAIN_TYPE],
+ implementation = _kt_jvm_junit_test_impl,
)
"""Setup a simple kotlin_test.
@@ -341,7 +348,7 @@
allow_single_file = True,
),
},
- implementation = _kotlin_import_impl,
+ implementation = _kt_jvm_import_impl,
)
# The pairing of src and class is used by intellij to attatch sources, this is picked up via the kt provider attribute.
diff --git a/kotlin/kotlin_compiler_repositories.bzl b/kotlin/kotlin_compiler_repositories.bzl
index 4d72046..2531073 100644
--- a/kotlin/kotlin_compiler_repositories.bzl
+++ b/kotlin/kotlin_compiler_repositories.bzl
@@ -14,7 +14,10 @@
"""This file contains the Kotlin compiler repository definitions.
"""
-load("//kotlin/rules:defs.bzl", "KOTLIN_REPO_ROOT")
+load(
+ "//kotlin/internal:kt.bzl",
+ _kt = "kt",
+)
KOTLIN_RELEASES = {
"1.2.21": {
@@ -40,7 +43,7 @@
}
KOTLIN_COMPILER_REPO_BUILD_FILE = """
-load("@io_bazel_rules_kotlin//kotlin/rules:bootstrap.bzl", kotlin_stdlib="kotlin_stdlib")
+load("@io_bazel_rules_kotlin//kotlin/internal:bootstrap.bzl", kotlin_stdlib="kotlin_stdlib")
package(default_visibility = ["//visibility:public"])
filegroup(
@@ -151,7 +154,7 @@
fail('"%s" not a valid kotlin release, current release is "%s"' % (kotlin_release_version, KOTLIN_CURRENT_RELEASE))
native.new_http_archive(
- name = KOTLIN_REPO_ROOT,
+ name = _kt.defs.KT_COMPILER_REPO,
url = release["url"],
sha256 = release["sha256"],
build_file_content= KOTLIN_COMPILER_REPO_BUILD_FILE,
diff --git a/kotlin/rules/bootstrap.bzl b/kotlin/rules/bootstrap.bzl
deleted file mode 100644
index c8daebc..0000000
--- a/kotlin/rules/bootstrap.bzl
+++ /dev/null
@@ -1,40 +0,0 @@
-# Copyright 2018 The Bazel Authors. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-"""This file contains rules used to bootstrap the compiler repository."""
-
-load(
- "//kotlin/rules:defs.bzl",
- _KotlinInfo = "KotlinInfo",
-)
-load(
- "//kotlin/rules:rules.bzl",
- _kotlin_import_impl = "kotlin_import_impl",
-)
-
-kotlin_stdlib = rule(
- attrs = {
- "jars": attr.label_list(
- allow_files = True,
- mandatory = True,
- cfg = "host",
- ),
- "srcjar": attr.label(
- allow_single_file = True,
- cfg = "host",
- ),
- },
- implementation = _kotlin_import_impl,
-)
-
-"""Import Kotlin libraries that are part of the compiler release."""
diff --git a/kotlin/rules/plugins.bzl b/kotlin/rules/plugins.bzl
deleted file mode 100644
index 54a3f74..0000000
--- a/kotlin/rules/plugins.bzl
+++ /dev/null
@@ -1,51 +0,0 @@
-load(
- "//kotlin/rules:defs.bzl",
- _KotlinPluginInfo = "KotlinPluginInfo",
-)
-
-def _mk_processor_entry(l,p):
- return struct(
- label=l,
- processor_class=p.processor_class,
- classpath=[cp.path for cp in java_common.merge([j[JavaInfo] for j in p.deps]).full_compile_jars],
- generates_api=p.generates_api,
- )
-
-def merge_plugin_infos(attrs):
- tally={}
- processors=[]
- for info in [a[_KotlinPluginInfo] for a in attrs]:
- for p in info.processors:
- if p.label not in tally:
- tally[p.label] = True
- processors.append(p)
- return _KotlinPluginInfo(processors=processors)
-
-def _restore_label(l):
- lbl = l.workspace_root
- if lbl.startswith("external/"):
- lbl = lbl.replace("external/", "@")
- return lbl + "//" + l.package + ":" + l.name
-
-_EMPTY_PLUGIN_INFO = [_KotlinPluginInfo(processors = [])]
-
-def _kt_jvm_plugin_aspect_impl(target, ctx):
- if ctx.rule.kind == "java_plugin":
- return [_KotlinPluginInfo(
- processors = [_mk_processor_entry(_restore_label(ctx.label),ctx.rule.attr)]
- )]
- else:
- if ctx.rule.kind == "java_library":
- return [merge_plugin_infos(ctx.rule.attr.exported_plugins)]
- else:
- return _EMPTY_PLUGIN_INFO
-
-kt_jvm_plugin_aspect = aspect(
- attr_aspects = [
- "plugins",
- "exported_plugins",
- ],
- implementation = _kt_jvm_plugin_aspect_impl,
-)
-
-"""renders a java info into a KotlinPluginInfo."""
diff --git a/kotlin/toolchains.bzl b/kotlin/toolchains.bzl
index e7ce1fb..9666b88 100644
--- a/kotlin/toolchains.bzl
+++ b/kotlin/toolchains.bzl
@@ -11,6 +11,15 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+load(
+ "//kotlin/internal:utils.bzl",
+ _utils = "utils",
+)
+load(
+ "//kotlin/internal:kt.bzl",
+ _kt = "kt",
+)
+
"""Kotlin Toolchains
This file contains macros for defining and registering specific toolchains.
@@ -20,9 +29,9 @@
To override a tool chain use the appropriate macro in a `BUILD` file to declare the toolchain:
```bzl
-load("@io_bazel_rules_kotlin//kotlin:toolchains.bzl", "define_kt_jvm_toolchain")
+load("@io_bazel_rules_kotlin//kotlin:toolchains.bzl", "define_kt_toolchain")
-define_kt_jvm_toolchain(
+define_kt_toolchain(
name= "custom_toolchain",
api_version = "1.1",
language_version = "1.1",
@@ -33,30 +42,58 @@
register_toolchains("//:custom_toolchain")
```
"""
+
# The toolchain rules are not made private, at least the jvm ones so that they may be introspected in Intelij.
_common_attrs = {
- 'language_version': attr.string(default="1.2", values=["1.1", "1.2"]),
- 'api_version': attr.string(default="1.2", values=["1.1", "1.2"]),
- "coroutines": attr.string(default="enable", values=["enable", "warn", "error"]),
+ "language_version": attr.string(
+ default = "1.2",
+ values = [
+ "1.1",
+ "1.2",
+ ],
+ ),
+ "api_version": attr.string(
+ default = "1.2",
+ values = [
+ "1.1",
+ "1.2",
+ ],
+ ),
+ "coroutines": attr.string(
+ default = "enable",
+ values = [
+ "enable",
+ "warn",
+ "error",
+ ],
+ ),
}
_kt_jvm_attrs = dict(_common_attrs.items() + {
- 'jvm_target': attr.string(default="1.8", values=["1.6", "1.8"]),
+ "jvm_target": attr.string(
+ default = "1.8",
+ values = [
+ "1.6",
+ "1.8",
+ ],
+ ),
}.items())
-def _kotlin_jvm_toolchain_impl(ctx):
+def _kotlin_toolchain_impl(ctx):
toolchain = platform_common.ToolchainInfo(
+ label = _utils.restore_label(ctx.label),
language_version = ctx.attr.language_version,
api_version = ctx.attr.api_version,
jvm_target = ctx.attr.jvm_target,
coroutines = ctx.attr.coroutines
)
- return [toolchain]
+ return struct(providers=[toolchain])
-kt_jvm_toolchain = rule(
- implementation = _kotlin_jvm_toolchain_impl,
- attrs = _kt_jvm_attrs
+kt_toolchain = rule(
+ attrs = _kt_jvm_attrs,
+ implementation = _kotlin_toolchain_impl,
)
+
"""The kotlin jvm toolchain
Args:
language_version: the -languag_version flag [see](https://kotlinlang.org/docs/reference/compatibility.html).
@@ -65,10 +102,10 @@
coroutines: the -Xcoroutines flag, enabled by default as it's considered production ready 1.2.0 onward.
"""
-def define_kt_jvm_toolchain(name, language_version=None, api_version=None, jvm_target=None, coroutines=None):
+def define_kt_toolchain(name, language_version=None, api_version=None, jvm_target=None, coroutines=None):
"""Define a Kotlin JVM Toolchain, the name is used in the `toolchain` rule so can be used to register the toolchain in the WORKSPACE file."""
impl_name = name + "_impl"
- kt_jvm_toolchain(
+ kt_toolchain(
name = impl_name,
language_version = language_version,
api_version = api_version,
@@ -78,11 +115,7 @@
)
native.toolchain(
name = name,
- toolchain_type = "@io_bazel_rules_kotlin//kotlin:kt_jvm_toolchain_type",
+ toolchain_type = _kt.defs.TOOLCHAIN_TYPE,
toolchain = impl_name,
visibility = ["//visibility:public"]
)
-
-def kt_register_jvm_toolchain():
- """Register the default JVM toolchain."""
- native.register_toolchains("@io_bazel_rules_kotlin//kotlin:default_jvm_toolchain")
diff --git a/kotlin/workers/BUILD b/kotlin/workers/BUILD
index 010e07a..6cfd49f 100644
--- a/kotlin/workers/BUILD
+++ b/kotlin/workers/BUILD
@@ -25,7 +25,7 @@
"//third_party:moshi-kotlin"
],
exports = [
- "//kotlin/workers/proto"
+ "//kotlin/workers/proto",
],
runtime_deps = [
"@com_github_jetbrains_kotlin//:kotlin-stdlib",