Skip to content

Commit

Permalink
Remove hard coding "io_bazel_rules_kotlin" to allow alternative names. (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
restingbull authored Dec 30, 2020
1 parent 73695e3 commit 404d3b3
Show file tree
Hide file tree
Showing 25 changed files with 189 additions and 138 deletions.
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# 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.
workspace(name = "io_bazel_rules_kotlin")
workspace(name = "dev_io_bazel_rules_kotlin")

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

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

kotlin_repositories()

kt_register_toolchains()
register_toolchains("@dev_io_bazel_rules_kotlin//kotlin/internal:default_toolchain")

# Creates toolchain configuration for remote execution with BuildKite CI
# for rbe_ubuntu1604
Expand Down
35 changes: 24 additions & 11 deletions docs/kotlin.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,25 @@ kt_compiler_plugin(<a href="#kt_compiler_plugin-name">name</a>, <a href="#kt_com
|
<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 | |
|
<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 |
<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 |
|
<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 | [] |
|
<a id="kt_compiler_plugin-id"></a>id | The ID of the plugin | String | required | |
|
<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 | {} |
|
<a id="kt_compiler_plugin-stubs_phase"></a>stubs_phase | Runs the compiler plugin before compile. | Boolean | optional | False |
<a id="kt_compiler_plugin-stubs_phase"></a>stubs_phase | Runs the compiler plugin in kapt stub generation. | Boolean | optional | True |
|
<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 |
<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 |


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

## kt_jvm_binary

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>,
<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>)
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>,
<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>)

Builds a Java archive ("jar file"), plus a wrapper shell script with the same name as the rule. The wrapper
Expand All @@ -91,8 +91,12 @@ kt_jvm_binary(<a href="#kt_jvm_binary-name">name</a>, <a href="#kt_jvm_binary-da
|
<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 | [] |
|
<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 |
|
<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 | [] |
|
<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 |
|
<a id="kt_jvm_binary-main_class"></a>main_class | Name of class with main() method to use as entry point. | String | required | |
|
<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 | "" |
Expand Down Expand Up @@ -173,15 +177,16 @@ kt_jvm_import(<a href="#kt_jvm_import-name">name</a>, <a href="#kt_jvm_import-de
|
<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 | [] |
|
<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 |
<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 |


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

## kt_jvm_library

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>,
<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>)
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>,
<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>,
<a href="#kt_jvm_library-runtime_deps">runtime_deps</a>, <a href="#kt_jvm_library-srcs">srcs</a>)

This rule compiles and links Kotlin and Java sources into a .jar file.
Expand All @@ -203,6 +208,10 @@ kt_jvm_library(<a href="#kt_jvm_library-name">name</a>, <a href="#kt_jvm_library
|
<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 | [] |
|
<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 |
|
<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 |
|
<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 | "" |
|
<a id="kt_jvm_library-neverlink"></a>neverlink | If true only use this library for compilation and not at runtime. | Boolean | optional | False |
Expand All @@ -224,8 +233,8 @@ kt_jvm_library(<a href="#kt_jvm_library-name">name</a>, <a href="#kt_jvm_library

## kt_jvm_test

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>,
<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>)
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>,
<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>)

Setup a simple kotlin_test.
Expand All @@ -250,8 +259,12 @@ kt_jvm_test(<a href="#kt_jvm_test-name">name</a>, <a href="#kt_jvm_test-data">da
|
<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 | [] |
|
<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 |
|
<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 | [] |
|
<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 |
|
<a id="kt_jvm_test-main_class"></a>main_class | - | String | optional | "com.google.testing.junit.runner.BazelTestRunner" |
|
<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 | "" |
Expand All @@ -276,7 +289,7 @@ kt_jvm_test(<a href="#kt_jvm_test-name">name</a>, <a href="#kt_jvm_test-data">da
## define_kt_toolchain

<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-experimental_use_abi_jars">experimental_use_abi_jars</a>
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>,
<a href="#define_kt_toolchain-javac_options">javac_options</a>, <a href="#define_kt_toolchain-kotlinc_options">kotlinc_options</a>)
</pre>

Expand Down
2 changes: 1 addition & 1 deletion examples/android/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
workspace(name="android_example")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

RULES_JVM_EXTERNAL_TAG = "2.8"

RULES_JVM_EXTERNAL_SHA = "79c9850690d7614ecdb72d68394f994fef7534b292c4867ce5e7dec0aa7bdfad"
Expand Down
1 change: 1 addition & 0 deletions kotlin/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ bzl_library(
"//kotlin/internal/js",
"//kotlin/internal/jvm",
"//kotlin/internal/utils",
"//kotlin/internal/repositories",
],
)
2 changes: 1 addition & 1 deletion kotlin/internal/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.#

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

# Java toolchains
JAVA_TOOLCHAIN_TYPE = "@bazel_tools//tools/jdk:toolchain_type"
Expand Down
3 changes: 3 additions & 0 deletions kotlin/internal/js/impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ def kt_js_library_impl(ctx):
arguments = [args],
progress_message = "Compiling Kotlin to JS %s { kt: %d }" % (ctx.label, len(ctx.files.srcs)),
input_manifests = input_manifests,
env = {
"REPOSITORY_NAME": _utils.builder_workspace_name(ctx),
},
)

return [
Expand Down
2 changes: 1 addition & 1 deletion kotlin/internal/js/js.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ kt_js_import = rule(
mandatory = False,
),
"_importer": attr.label(
default = "//kotlin/internal/js:importer",
default = Label("//kotlin/internal/js:importer"),
allow_files = True,
executable = True,
cfg = "host",
Expand Down
4 changes: 3 additions & 1 deletion kotlin/internal/jvm/android.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ load(
_kt_jvm_library = "kt_jvm_library",
)

_ANDROID_SDK_JAR = "%s" % Label("//third_party:android_sdk")

def _kt_android_artifact(name, srcs = [], deps = [], plugins = [], kotlinc_opts = None, javac_opts = None, enable_data_binding = False, **kwargs):
"""Delegates Android related build attributes to the native rules but uses the Kotlin builder to compile Java and
Kotlin srcs. Returns a sequence of labels that a wrapping macro should export.
Expand All @@ -24,7 +26,7 @@ def _kt_android_artifact(name, srcs = [], deps = [], plugins = [], kotlinc_opts
kt_name = name + "_kt"

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

native.android_library(
name = base_name,
Expand Down
Loading

0 comments on commit 404d3b3

Please sign in to comment.