Skip to content

Commit 404d3b3

Browse files
authored
Remove hard coding "io_bazel_rules_kotlin" to allow alternative names. (#433)
* Remove hard coding `io_bazel_rules_kotlin`, to allow repositories with alternative names. Use deploy jar for jarjar to make sure runtime deps are present. Rename development workspace to `dev_io_bazel_rules_kotlin` to dissuade hard coding the release repository name * Remove unused bzl from the migration to maven repositories. * Fix hard coded run file paths in the builder by propagating the workspace_name to the builder. (non-ideal, it'll do until the files are passed in as args) Add the (mostly undocumented) testing.TestEnvironment provider to the unit tests -- this adds the same env variables as seen in java_test. * Tweak release script to avoid sending a "" target when build args are skipped. Starlark formatting. Add repository name to the under-privileged js rules. * Standardize on using Label in defaults.
1 parent 73695e3 commit 404d3b3

File tree

25 files changed

+189
-138
lines changed

25 files changed

+189
-138
lines changed

WORKSPACE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
workspace(name = "io_bazel_rules_kotlin")
14+
workspace(name = "dev_io_bazel_rules_kotlin")
1515

1616
load("//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies")
1717

@@ -21,7 +21,7 @@ load("//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")
2121

2222
kotlin_repositories()
2323

24-
kt_register_toolchains()
24+
register_toolchains("@dev_io_bazel_rules_kotlin//kotlin/internal:default_toolchain")
2525

2626
# Creates toolchain configuration for remote execution with BuildKite CI
2727
# for rbe_ubuntu1604

docs/kotlin.md

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,25 @@ kt_compiler_plugin(<a href="#kt_compiler_plugin-name">name</a>, <a href="#kt_com
4949
|
5050
<a id="kt_compiler_plugin-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
5151
|
52-
<a id="kt_compiler_plugin-compile_phase"></a>compile_phase | Runs the compiler plugin during kotlin compilation. Known examples: allopen, sam_with_reciever | Boolean | optional | False |
52+
<a id="kt_compiler_plugin-compile_phase"></a>compile_phase | Runs the compiler plugin during kotlin compilation. Known examples: allopen, sam_with_reciever | Boolean | optional | True |
5353
|
5454
<a id="kt_compiler_plugin-deps"></a>deps | The list of libraries to be added to the compiler's plugin classpath | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
5555
|
5656
<a id="kt_compiler_plugin-id"></a>id | The ID of the plugin | String | required | |
5757
|
5858
<a id="kt_compiler_plugin-options"></a>options | Dictionary of options to be passed to the plugin. Supports the following template values: <code>{generatedClasses}</code>: directory for generated class output <code>{temp}</code>: temporary directory, discarded between invocations <code>{generatedSources}</code>: directory for generated source output | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
5959
|
60-
<a id="kt_compiler_plugin-stubs_phase"></a>stubs_phase | Runs the compiler plugin before compile. | Boolean | optional | False |
60+
<a id="kt_compiler_plugin-stubs_phase"></a>stubs_phase | Runs the compiler plugin in kapt stub generation. | Boolean | optional | True |
6161
|
62-
<a id="kt_compiler_plugin-target_embedded_compiler"></a>target_embedded_compiler | Plugin was compiled agains the embeddable kotlin compiler. Requires different classpath | Boolean | optional | False |
62+
<a id="kt_compiler_plugin-target_embedded_compiler"></a>target_embedded_compiler | Plugin was compiled against the embeddable kotlin compiler. These plugins expect shaded kotlinc dependencies, and will fail when running against a non-embeddable compiler. | Boolean | optional | False |
6363

6464

6565
<a id="#kt_jvm_binary"></a>
6666

6767
## kt_jvm_binary
6868

69-
kt_jvm_binary(<a href="#kt_jvm_binary-name">name</a>, <a href="#kt_jvm_binary-data">data</a>, <a href="#kt_jvm_binary-deps">deps</a>, <a href="#kt_jvm_binary-jvm_flags">jvm_flags</a>, <a href="#kt_jvm_binary-main_class">main_class</a>, <a href="#kt_jvm_binary-module_name">module_name</a>, <a href="#kt_jvm_binary-plugins">plugins</a>, <a href="#kt_jvm_binary-resource_jars">resource_jars</a>,
70-
<a href="#kt_jvm_binary-resource_strip_prefix">resource_strip_prefix</a>, <a href="#kt_jvm_binary-resources">resources</a>, <a href="#kt_jvm_binary-runtime_deps">runtime_deps</a>, <a href="#kt_jvm_binary-srcs">srcs</a>)
69+
kt_jvm_binary(<a href="#kt_jvm_binary-name">name</a>, <a href="#kt_jvm_binary-data">data</a>, <a href="#kt_jvm_binary-deps">deps</a>, <a href="#kt_jvm_binary-javac_opts">javac_opts</a>, <a href="#kt_jvm_binary-jvm_flags">jvm_flags</a>, <a href="#kt_jvm_binary-kotlinc_opts">kotlinc_opts</a>, <a href="#kt_jvm_binary-main_class">main_class</a>, <a href="#kt_jvm_binary-module_name">module_name</a>,
70+
<a href="#kt_jvm_binary-plugins">plugins</a>, <a href="#kt_jvm_binary-resource_jars">resource_jars</a>, <a href="#kt_jvm_binary-resource_strip_prefix">resource_strip_prefix</a>, <a href="#kt_jvm_binary-resources">resources</a>, <a href="#kt_jvm_binary-runtime_deps">runtime_deps</a>, <a href="#kt_jvm_binary-srcs">srcs</a>)
7171

7272
7373
Builds a Java archive ("jar file"), plus a wrapper shell script with the same name as the rule. The wrapper
@@ -91,8 +91,12 @@ kt_jvm_binary(<a href="#kt_jvm_binary-name">name</a>, <a href="#kt_jvm_binary-da
9191
|
9292
<a id="kt_jvm_binary-deps"></a>deps | A list of dependencies of this rule.See general comments about <code>deps</code> at [Attributes common to all build rules](https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes). | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
9393
|
94+
<a id="kt_jvm_binary-javac_opts"></a>javac_opts | Javac options to be used when compiling this target. These opts if provided will be used instead of the ones provided to the toolchain. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
95+
|
9496
<a id="kt_jvm_binary-jvm_flags"></a>jvm_flags | A list of flags to embed in the wrapper script generated for running this binary. Note: does not yet support make variable substitution. | List of strings | optional | [] |
9597
|
98+
<a id="kt_jvm_binary-kotlinc_opts"></a>kotlinc_opts | Kotlinc options to be used when compiling this target. These opts if provided will be used instead of the ones provided to the toolchain. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
99+
|
96100
<a id="kt_jvm_binary-main_class"></a>main_class | Name of class with main() method to use as entry point. | String | required | |
97101
|
98102
<a id="kt_jvm_binary-module_name"></a>module_name | The name of the module, if not provided the module name is derived from the label. --e.g., <code>//some/package/path:label_name</code> is translated to <code>some_package_path-label_name</code>. | String | optional | "" |
@@ -173,15 +177,16 @@ kt_jvm_import(<a href="#kt_jvm_import-name">name</a>, <a href="#kt_jvm_import-de
173177
|
174178
<a id="kt_jvm_import-runtime_deps"></a>runtime_deps | Additional runtime deps. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
175179
|
176-
<a id="kt_jvm_import-srcjar"></a>srcjar | The sources for the class jar. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | @io_bazel_rules_kotlin//third_party:empty.jar |
180+
<a id="kt_jvm_import-srcjar"></a>srcjar | The sources for the class jar. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | //third_party:empty.jar |
177181

178182

179183
<a id="#kt_jvm_library"></a>
180184

181185
## kt_jvm_library
182186

183-
kt_jvm_library(<a href="#kt_jvm_library-name">name</a>, <a href="#kt_jvm_library-data">data</a>, <a href="#kt_jvm_library-deps">deps</a>, <a href="#kt_jvm_library-exported_compiler_plugins">exported_compiler_plugins</a>, <a href="#kt_jvm_library-exports">exports</a>, <a href="#kt_jvm_library-module_name">module_name</a>, <a href="#kt_jvm_library-neverlink">neverlink</a>,
184-
<a href="#kt_jvm_library-plugins">plugins</a>, <a href="#kt_jvm_library-resource_jars">resource_jars</a>, <a href="#kt_jvm_library-resource_strip_prefix">resource_strip_prefix</a>, <a href="#kt_jvm_library-resources">resources</a>, <a href="#kt_jvm_library-runtime_deps">runtime_deps</a>, <a href="#kt_jvm_library-srcs">srcs</a>)
187+
kt_jvm_library(<a href="#kt_jvm_library-name">name</a>, <a href="#kt_jvm_library-data">data</a>, <a href="#kt_jvm_library-deps">deps</a>, <a href="#kt_jvm_library-exported_compiler_plugins">exported_compiler_plugins</a>, <a href="#kt_jvm_library-exports">exports</a>, <a href="#kt_jvm_library-javac_opts">javac_opts</a>, <a href="#kt_jvm_library-kotlinc_opts">kotlinc_opts</a>,
188+
<a href="#kt_jvm_library-module_name">module_name</a>, <a href="#kt_jvm_library-neverlink">neverlink</a>, <a href="#kt_jvm_library-plugins">plugins</a>, <a href="#kt_jvm_library-resource_jars">resource_jars</a>, <a href="#kt_jvm_library-resource_strip_prefix">resource_strip_prefix</a>, <a href="#kt_jvm_library-resources">resources</a>,
189+
<a href="#kt_jvm_library-runtime_deps">runtime_deps</a>, <a href="#kt_jvm_library-srcs">srcs</a>)
185190

186191
187192
This rule compiles and links Kotlin and Java sources into a .jar file.
@@ -203,6 +208,10 @@ kt_jvm_library(<a href="#kt_jvm_library-name">name</a>, <a href="#kt_jvm_library
203208
|
204209
<a id="kt_jvm_library-exports"></a>exports | Exported libraries.<br><br> Deps listed here will be made available to other rules, as if the parents explicitly depended on these deps. This is not true for regular (non-exported) deps. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
205210
|
211+
<a id="kt_jvm_library-javac_opts"></a>javac_opts | Javac options to be used when compiling this target. These opts if provided will be used instead of the ones provided to the toolchain. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
212+
|
213+
<a id="kt_jvm_library-kotlinc_opts"></a>kotlinc_opts | Kotlinc options to be used when compiling this target. These opts if provided will be used instead of the ones provided to the toolchain. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
214+
|
206215
<a id="kt_jvm_library-module_name"></a>module_name | The name of the module, if not provided the module name is derived from the label. --e.g., <code>//some/package/path:label_name</code> is translated to <code>some_package_path-label_name</code>. | String | optional | "" |
207216
|
208217
<a id="kt_jvm_library-neverlink"></a>neverlink | If true only use this library for compilation and not at runtime. | Boolean | optional | False |
@@ -224,8 +233,8 @@ kt_jvm_library(<a href="#kt_jvm_library-name">name</a>, <a href="#kt_jvm_library
224233

225234
## kt_jvm_test
226235

227-
kt_jvm_test(<a href="#kt_jvm_test-name">name</a>, <a href="#kt_jvm_test-data">data</a>, <a href="#kt_jvm_test-deps">deps</a>, <a href="#kt_jvm_test-friends">friends</a>, <a href="#kt_jvm_test-jvm_flags">jvm_flags</a>, <a href="#kt_jvm_test-main_class">main_class</a>, <a href="#kt_jvm_test-module_name">module_name</a>, <a href="#kt_jvm_test-plugins">plugins</a>, <a href="#kt_jvm_test-resource_jars">resource_jars</a>,
228-
<a href="#kt_jvm_test-resource_strip_prefix">resource_strip_prefix</a>, <a href="#kt_jvm_test-resources">resources</a>, <a href="#kt_jvm_test-runtime_deps">runtime_deps</a>, <a href="#kt_jvm_test-srcs">srcs</a>, <a href="#kt_jvm_test-test_class">test_class</a>)
236+
kt_jvm_test(<a href="#kt_jvm_test-name">name</a>, <a href="#kt_jvm_test-data">data</a>, <a href="#kt_jvm_test-deps">deps</a>, <a href="#kt_jvm_test-friends">friends</a>, <a href="#kt_jvm_test-javac_opts">javac_opts</a>, <a href="#kt_jvm_test-jvm_flags">jvm_flags</a>, <a href="#kt_jvm_test-kotlinc_opts">kotlinc_opts</a>, <a href="#kt_jvm_test-main_class">main_class</a>, <a href="#kt_jvm_test-module_name">module_name</a>,
237+
<a href="#kt_jvm_test-plugins">plugins</a>, <a href="#kt_jvm_test-resource_jars">resource_jars</a>, <a href="#kt_jvm_test-resource_strip_prefix">resource_strip_prefix</a>, <a href="#kt_jvm_test-resources">resources</a>, <a href="#kt_jvm_test-runtime_deps">runtime_deps</a>, <a href="#kt_jvm_test-srcs">srcs</a>, <a href="#kt_jvm_test-test_class">test_class</a>)
229238

230239
231240
Setup a simple kotlin_test.
@@ -250,8 +259,12 @@ kt_jvm_test(<a href="#kt_jvm_test-name">name</a>, <a href="#kt_jvm_test-data">da
250259
|
251260
<a id="kt_jvm_test-friends"></a>friends | A single Kotlin dep which allows the test code access to internal members. Currently uses the output jar of the module -- i.e., exported deps won't be included. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
252261
|
262+
<a id="kt_jvm_test-javac_opts"></a>javac_opts | Javac options to be used when compiling this target. These opts if provided will be used instead of the ones provided to the toolchain. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
263+
|
253264
<a id="kt_jvm_test-jvm_flags"></a>jvm_flags | A list of flags to embed in the wrapper script generated for running this binary. Note: does not yet support make variable substitution. | List of strings | optional | [] |
254265
|
266+
<a id="kt_jvm_test-kotlinc_opts"></a>kotlinc_opts | Kotlinc options to be used when compiling this target. These opts if provided will be used instead of the ones provided to the toolchain. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
267+
|
255268
<a id="kt_jvm_test-main_class"></a>main_class | - | String | optional | "com.google.testing.junit.runner.BazelTestRunner" |
256269
|
257270
<a id="kt_jvm_test-module_name"></a>module_name | The name of the module, if not provided the module name is derived from the label. --e.g., <code>//some/package/path:label_name</code> is translated to <code>some_package_path-label_name</code>. | String | optional | "" |
@@ -276,7 +289,7 @@ kt_jvm_test(<a href="#kt_jvm_test-name">name</a>, <a href="#kt_jvm_test-data">da
276289
## define_kt_toolchain
277290

278291
<pre>
279-
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-experimental_use_abi_jars">experimental_use_abi_jars</a>
292+
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-experimental_use_abi_jars">experimental_use_abi_jars</a>,
280293
<a href="#define_kt_toolchain-javac_options">javac_options</a>, <a href="#define_kt_toolchain-kotlinc_options">kotlinc_options</a>)
281294
</pre>
282295

examples/android/WORKSPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
workspace(name="android_example")
12
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2-
33
RULES_JVM_EXTERNAL_TAG = "2.8"
44

55
RULES_JVM_EXTERNAL_SHA = "79c9850690d7614ecdb72d68394f994fef7534b292c4867ce5e7dec0aa7bdfad"

kotlin/internal/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,6 @@ bzl_library(
5555
"//kotlin/internal/js",
5656
"//kotlin/internal/jvm",
5757
"//kotlin/internal/utils",
58+
"//kotlin/internal/repositories",
5859
],
5960
)

kotlin/internal/defs.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.#
1414

1515
# The Kotlin Toolchain type.
16-
TOOLCHAIN_TYPE = "@io_bazel_rules_kotlin//kotlin/internal:kt_toolchain_type"
16+
TOOLCHAIN_TYPE = "%s" % Label("//kotlin/internal:kt_toolchain_type")
1717

1818
# Java toolchains
1919
JAVA_TOOLCHAIN_TYPE = "@bazel_tools//tools/jdk:toolchain_type"

kotlin/internal/js/impl.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ def kt_js_library_impl(ctx):
9090
arguments = [args],
9191
progress_message = "Compiling Kotlin to JS %s { kt: %d }" % (ctx.label, len(ctx.files.srcs)),
9292
input_manifests = input_manifests,
93+
env = {
94+
"REPOSITORY_NAME": _utils.builder_workspace_name(ctx),
95+
},
9396
)
9497

9598
return [

kotlin/internal/js/js.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ kt_js_import = rule(
135135
mandatory = False,
136136
),
137137
"_importer": attr.label(
138-
default = "//kotlin/internal/js:importer",
138+
default = Label("//kotlin/internal/js:importer"),
139139
allow_files = True,
140140
executable = True,
141141
cfg = "host",

kotlin/internal/jvm/android.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ load(
1616
_kt_jvm_library = "kt_jvm_library",
1717
)
1818

19+
_ANDROID_SDK_JAR = "%s" % Label("//third_party:android_sdk")
20+
1921
def _kt_android_artifact(name, srcs = [], deps = [], plugins = [], kotlinc_opts = None, javac_opts = None, enable_data_binding = False, **kwargs):
2022
"""Delegates Android related build attributes to the native rules but uses the Kotlin builder to compile Java and
2123
Kotlin srcs. Returns a sequence of labels that a wrapping macro should export.
@@ -24,7 +26,7 @@ def _kt_android_artifact(name, srcs = [], deps = [], plugins = [], kotlinc_opts
2426
kt_name = name + "_kt"
2527

2628
# TODO(bazelbuild/rules_kotlin/issues/273): This should be retrieved from a provider.
27-
base_deps = deps + ["@io_bazel_rules_kotlin//third_party:android_sdk"]
29+
base_deps = deps + [_ANDROID_SDK_JAR]
2830

2931
native.android_library(
3032
name = base_name,

0 commit comments

Comments
 (0)