diff --git a/CompileAvoidance.md b/CompileAvoidance.md index 9882d7ff6..51c7e7fe8 100644 --- a/CompileAvoidance.md +++ b/CompileAvoidance.md @@ -12,7 +12,7 @@ This feature can be enabled through the `experimental_use_abi_jars` flag in the follows ```python -load("//kotlin:kotlin.bzl", "define_kt_toolchain") +load("//kotlin:core.bzl", "define_kt_toolchain") define_kt_toolchain( @@ -31,7 +31,7 @@ If you encounter such bugs, ABI generation can be disabled on a per target basis following tag ```python -load("//kotlin:kotlin.bzl", "kt_jvm_library") +load("//kotlin:jvm.bzl", "kt_jvm_library") kt_jvm_library( name = "framework", diff --git a/README.md b/README.md index a813994c7..18b785af3 100644 --- a/README.md +++ b/README.md @@ -91,8 +91,10 @@ http_archive( sha256 = rules_kotlin_sha, ) -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains") +load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories") kotlin_repositories() # if you want the default. Otherwise see custom kotlinc distribution below + +load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains") kt_register_toolchains() # to use the default toolchain, otherwise see toolchains below ``` @@ -109,9 +111,11 @@ http_archive( sha256 = rules_kotlin_sha, ) -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains") -kotlin_repositories() # if you want the default. Otherwise see custom kotlinc distribution below -kt_register_toolchains() # to use the default toolchain, otherwise see toolchains below +load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories") +kotlin_repositories() + +load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains") +kt_register_toolchains() ``` ## `BUILD` files @@ -119,7 +123,7 @@ kt_register_toolchains() # to use the default toolchain, otherwise see toolchain In your project's `BUILD` files, load the Kotlin rules and use them like so: ```python -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") kt_jvm_library( name = "package_name", @@ -136,7 +140,7 @@ To enable a custom toolchain (to configure language level, etc.) do the following. In a `/BUILD.bazel` file define the following: ```python -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "define_kt_toolchain") +load("@io_bazel_rules_kotlin//kotlin:core.bzl", "define_kt_toolchain") define_kt_toolchain( name = "kotlin_toolchain", @@ -158,7 +162,7 @@ To choose a different `kotlinc` distribution (1.3 and 1.4 variants supported), d in your `WORKSPACE` file (or import from a `.bzl` file: ```python -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories") +load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories") KOTLIN_VERSION = "1.3.31" KOTLINC_RELEASE_SHA = "107325d56315af4f59ff28db6837d03c2660088e3efeb7d4e41f3e01bb848d6a" @@ -192,9 +196,12 @@ local_repository( load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies") kt_download_local_dev_dependencies() -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains") -kotlin_repositories() # if you want the default. Otherwise see custom kotlinc distribution below -kt_register_toolchains() # to use the default toolchain, otherwise see toolchains below + +load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories") +kotlin_repositories() + +load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains") +kt_register_toolchains() ``` # Kotlin and Java compiler flags @@ -205,7 +212,7 @@ Note: Not all compiler flags are supported in all language versions. When this h For example you can define global compiler flags by doing: ```python -load("//kotlin:kotlin.bzl", "kt_kotlinc_options", "kt_javac_options", "define_kt_toolchain") +load("//kotlin:core.bzl", "kt_kotlinc_options", "kt_javac_options", "define_kt_toolchain") kt_kotlinc_options( name = "kt_kotlinc_options", @@ -231,7 +238,8 @@ Compiler flags that are passed to the rule definitions will be taken over the to Example: ```python -load("//kotlin:kotlin.bzl", "kt_kotlinc_options", "kt_javac_options", "kt_jvm_library") +load("//kotlin:core.bzl", "kt_kotlinc_options", "kt_javac_options", "kt_jvm_library") +load("//kotlin:jvm.bzl","kt_javac_options", "kt_jvm_library") kt_kotlinc_options( name = "kt_kotlinc_options_for_package_name", @@ -259,7 +267,8 @@ The `kt_compiler_plugin` rule allows running Kotlin compiler plugins, such as no For example, you can add allopen to your project like this: ```python -load("//kotlin:kotlin.bzl", "kt_compiler_plugin", "kt_jvm_library") +load("//kotlin:core.bzl", "kt_compiler_plugin") +load("//kotlin:jvm.bzl", "kt_jvm_library") kt_compiler_plugin( name = "open_for_testing_plugin", diff --git a/WORKSPACE b/WORKSPACE index 38f19fb5c..83e7e0726 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -17,7 +17,7 @@ load("//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies") kt_download_local_dev_dependencies() -load("//kotlin:kotlin.bzl", "kotlin_repositories") +load("//kotlin:repositories.bzl", "kotlin_repositories", "versions") kotlin_repositories() @@ -37,6 +37,9 @@ load( "android_sdk_repository", ) -android_sdk_repository(name = "androidsdk") +android_sdk_repository( + name = "androidsdk", + build_tools_version = versions.ANDROID.BUILD_TOOLS, +) android_ndk_repository(name = "androidndk") diff --git a/docs/kotlin.md b/docs/kotlin.md index 0158128cf..f7b314989 100755 --- a/docs/kotlin.md +++ b/docs/kotlin.md @@ -1,60 +1,45 @@ - + -## kt_compiler_plugin +## kt_js_import -kt_compiler_plugin(name, compile_phase, deps, id, options, stubs_phase, target_embedded_compiler) +
+kt_js_import(name, kwargs)
+
- - Define a plugin for the Kotlin compiler to run. The plugin can then be referenced in the `plugins` attribute - of the `kt_jvm_*` rules. - - An example can be found under `//examples/plugin`: - - ```bzl - kt_compiler_plugin( - name = "open_for_testing_plugin", - id = "org.jetbrains.kotlin.allopen", - options = { - "annotation": "plugin.OpenForTesting", - }, - deps = [ - "@com_github_jetbrains_kotlin//:allopen-compiler-plugin", - ], - ) - - kt_jvm_library( - name = "open_for_testing", - srcs = ["OpenForTesting.kt"], - ) - - kt_jvm_library( - name = "user", - srcs = ["User.kt"], - plugins = [":open_for_testing_plugin"], - deps = [ - ":open_for_testing", - ], - ) - ``` - - -**ATTRIBUTES** +**PARAMETERS** -| Name | Description | Type | Mandatory | Default | -| :------------- | :------------- | :------------- | :------------- | :------------- | -|name | A unique name for this target. | Name | required | | -|compile_phase | Runs the compiler plugin during kotlin compilation. Known examples: allopen, sam_with_reciever | Boolean | optional | True | -|deps | The list of libraries to be added to the compiler's plugin classpath | List of labels | optional | [] | -|id | The ID of the plugin | String | required | | -|options | Dictionary of options to be passed to the plugin. Supports the following template values: {generatedClasses}: directory for generated class output {temp}: temporary directory, discarded between invocations {generatedSources}: directory for generated source output | Dictionary: String -> String | optional | {} | -|stubs_phase | Runs the compiler plugin in kapt stub generation. | Boolean | optional | True | -|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 | + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| name |

-

| none | +| kwargs |

-

| none | + + + + +## kt_js_library + +
+kt_js_library(name, kwargs)
+
+ +**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| name |

-

| none | +| kwargs |

-

| none | + + + + ## kt_javac_options @@ -62,7 +47,7 @@ kt_compiler_plugin(name, name, warn, x_ep_disable_all_checks, x_lint, xd_suppress_notes) - Define java compiler options for kt_jvm_* rules with java sources. + Define java compiler options for `kt_jvm_*` rules with java sources. **ATTRIBUTES** @@ -81,17 +66,17 @@ kt_javac_options(name, name, data, deps, javac_opts, jvm_flags, kotlinc_opts, main_class, module_name, - plugins, resource_jars, resource_strip_prefix, resources, runtime_deps, srcs) +kt_jvm_binary(name, associates, data, deps, friends, javac_opts, jvm_flags, kotlinc_opts, + main_class, module_name, plugins, resource_jars, resource_strip_prefix, resources, + runtime_deps, srcs) - - Builds a Java archive ("jar file"), plus a wrapper shell script with the same name as the rule. The wrapper + + 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, among other things, a jar file for each library on which the binary depends. - + **Note:** This rule does not have all of the features found in [`java_binary`](https://docs.bazel.build/versions/master/be/java.html#java_binary). It is appropriate for building workspace utilities. `java_binary` should be preferred for release artefacts. - **ATTRIBUTES** @@ -100,8 +85,10 @@ kt_jvm_binary(name, name | A unique name for this target. | Name | required | | +|associates | Kotlin deps who should be considered part of the same module/compilation-unit for the purposes of "internal" access. Such deps must all share the same module space and so a target cannot associate to two deps from two different modules. | List of labels | optional | [] | |data | The list of files needed by this rule at runtime. See general comments about data at [Attributes common to all build rules](https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes). | List of labels | optional | [] | |deps | A list of dependencies of this rule.See general comments about deps at [Attributes common to all build rules](https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes). | List of labels | optional | [] | +|friends | A single Kotlin dep which allows Kotlin code in other modules access to internal members. Currently uses the output jar of the module -- i.e., exported deps won't be included. [DEPRECATED, use "associates" instead] | List of labels | optional | [] | |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. | Label | optional | None | |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 | [] | |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. | Label | optional | None | @@ -122,11 +109,11 @@ kt_jvm_binary(name, name, deps, exported_compiler_plugins, exports, jar, jars, neverlink, runtime_deps, srcjar) - - Import Kotlin jars. - + + Import Kotlin jars. + ## examples - + ```bzl # Old style usage -- reference file groups, do not used this. kt_jvm_import( @@ -136,7 +123,7 @@ kt_jvm_import(name, name, name, name, name | A unique name for this target. | Name | required | | |deps | Compile and runtime dependencies | List of labels | optional | [] | -|exported_compiler_plugins | Exported compiler plugins.

Compiler plugins listed here will be treated as if they were added in the plugins attribute of any targets that directly depend on this target. Unlike java_plugins' exported_plugins, this is not transitive | List of labels | optional | [] | -|exports | Exported libraries.

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. | List of labels | optional | [] | +|exported_compiler_plugins | Exported compiler plugins.

Compiler plugins listed here will be treated as if they were added in the plugins attribute of any targets that directly depend on this target. Unlike java_plugins' exported_plugins, this is not transitive | List of labels | optional | [] | +|exports | Exported libraries.

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. | List of labels | optional | [] | |jar | The jar listed here is equivalent to an export attribute. | Label | optional | None | -|jars | The jars listed here are equavalent to an export attribute. The label should be either to a single class jar, or one or more filegroup labels. The filegroups, when resolved, must contain only one jar containing classes, and (optionally) one peer file containing sources, named <jarname>-sources.jar.

DEPRECATED - please use jar and srcjar attributes. | List of labels | optional | [] | +|jars | The jars listed here are equavalent to an export attribute. The label should be either to a single class jar, or one or more filegroup labels. The filegroups, when resolved, must contain only one jar containing classes, and (optionally) one peer file containing sources, named <jarname>-sources.jar.

DEPRECATED - please use jar and srcjar attributes. | List of labels | optional | [] | |neverlink | If true only use this library for compilation and not at runtime. | Boolean | optional | False | |runtime_deps | Additional runtime deps. | List of labels | optional | [] | |srcjar | The sources for the class jar. | Label | optional | //third_party:empty.jar | @@ -176,9 +162,9 @@ kt_jvm_import(name, name, data, deps, exported_compiler_plugins, exports, javac_opts, kotlinc_opts, - module_name, neverlink, plugins, resource_jars, resource_strip_prefix, resources, - runtime_deps, srcs) +kt_jvm_library(name, associates, data, deps, exported_compiler_plugins, exports, friends, + javac_opts, kotlinc_opts, module_name, neverlink, plugins, resource_jars, + resource_strip_prefix, resources, runtime_deps, srcs) This rule compiles and links Kotlin and Java sources into a .jar file. @@ -190,10 +176,12 @@ kt_jvm_library(name, name | A unique name for this target. | Name | required | | +|associates | Kotlin deps who should be considered part of the same module/compilation-unit for the purposes of "internal" access. Such deps must all share the same module space and so a target cannot associate to two deps from two different modules. | List of labels | optional | [] | |data | The list of files needed by this rule at runtime. See general comments about data at [Attributes common to all build rules](https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes). | List of labels | optional | [] | |deps | A list of dependencies of this rule.See general comments about deps at [Attributes common to all build rules](https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes). | List of labels | optional | [] | -|exported_compiler_plugins | Exported compiler plugins.

Compiler plugins listed here will be treated as if they were added in the plugins attribute of any targets that directly depend on this target. Unlike java_plugins' exported_plugins, this is not transitive | List of labels | optional | [] | -|exports | Exported libraries.

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. | List of labels | optional | [] | +|exported_compiler_plugins | Exported compiler plugins.

Compiler plugins listed here will be treated as if they were added in the plugins attribute of any targets that directly depend on this target. Unlike java_plugins exported_plugins, this is not transitive | List of labels | optional | [] | +|exports | Exported libraries.

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. | List of labels | optional | [] | +|friends | A single Kotlin dep which allows Kotlin code in other modules access to internal members. Currently uses the output jar of the module -- i.e., exported deps won't be included. [DEPRECATED, use "associates" instead] | List of labels | optional | [] | |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. | Label | optional | None | |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. | Label | optional | None | |module_name | The name of the module, if not provided the module name is derived from the label. --e.g., //some/package/path:label_name is translated to some_package_path-label_name. | String | optional | "" | @@ -210,16 +198,16 @@ kt_jvm_library(name, name, data, deps, friends, javac_opts, jvm_flags, kotlinc_opts, main_class, module_name, - plugins, resource_jars, resource_strip_prefix, resources, runtime_deps, srcs, test_class) +kt_jvm_test(name, associates, data, deps, friends, javac_opts, jvm_flags, kotlinc_opts, main_class, + module_name, plugins, resource_jars, resource_strip_prefix, resources, runtime_deps, srcs, + test_class) - - Setup a simple kotlin_test. - + + Setup a simple kotlin_test. + **Notes:** * The kotlin test library is not added implicitly, it is available with the label `@com_github_jetbrains_kotlin//:kotlin-test`. - **ATTRIBUTES** @@ -228,9 +216,10 @@ kt_jvm_test(name, da | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | |name | A unique name for this target. | Name | required | | +|associates | Kotlin deps who should be considered part of the same module/compilation-unit for the purposes of "internal" access. Such deps must all share the same module space and so a target cannot associate to two deps from two different modules. | List of labels | optional | [] | |data | The list of files needed by this rule at runtime. See general comments about data at [Attributes common to all build rules](https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes). | List of labels | optional | [] | |deps | A list of dependencies of this rule.See general comments about deps at [Attributes common to all build rules](https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes). | List of labels | optional | [] | -|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. | List of labels | optional | [] | +|friends | A single Kotlin dep which allows Kotlin code in other modules access to internal members. Currently uses the output jar of the module -- i.e., exported deps won't be included. [DEPRECATED, use "associates" instead] | List of labels | optional | [] | |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. | Label | optional | None | |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 | [] | |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. | Label | optional | None | @@ -245,12 +234,154 @@ kt_jvm_test(name, da |test_class | The Java class to be loaded by the test runner. | String | optional | "" | + + + + +## ktlint_config + +ktlint_config(name, editorconfig) + + + Used to configure ktlint. + + `ktlint` can be configured to use a `.editorconfig`, as documented at + https://github.com/pinterest/ktlint/#editorconfig + + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +|name | A unique name for this target. | Name | required | | +|editorconfig | Editor config file to use | Label | optional | None | + + + + +## ktlint_fix + +ktlint_fix(name, config, srcs) + + + Lint Kotlin files and automatically fix them as needed + + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +|name | A unique name for this target. | Name | required | | +|config | ktlint_config to use | Label | optional | None | +|srcs | Source files to review and fix | List of labels | required | | + + + + +## ktlint_test + +ktlint_test(name, config, srcs) + + + Lint Kotlin files, and fail if the linter raises errors. + + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +|name | A unique name for this target. | Name | required | | +|config | ktlint_config to use | Label | optional | None | +|srcs | Source files to lint | List of labels | required | | + + + + + + +## kt_compiler_plugin + +kt_compiler_plugin(name, compile_phase, deps, id, options, stubs_phase, target_embedded_compiler) + + + Define a plugin for the Kotlin compiler to run. The plugin can then be referenced in the `plugins` attribute + of the `kt_jvm_*` rules. + + An example can be found under `//examples/plugin`: + + ```bzl + kt_compiler_plugin( + name = "open_for_testing_plugin", + id = "org.jetbrains.kotlin.allopen", + options = { + "annotation": "plugin.OpenForTesting", + }, + deps = [ + "@com_github_jetbrains_kotlin//:allopen-compiler-plugin", + ], + ) + + kt_jvm_library( + name = "open_for_testing", + srcs = ["OpenForTesting.kt"], + ) + + kt_jvm_library( + name = "user", + srcs = ["User.kt"], + plugins = [":open_for_testing_plugin"], + deps = [ + ":open_for_testing", + ], + ) + ``` + + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +|name | A unique name for this target. | Name | required | | +|compile_phase | Runs the compiler plugin during kotlin compilation. Known examples: allopen, sam_with_reciever | Boolean | optional | True | +|deps | The list of libraries to be added to the compiler's plugin classpath | List of labels | optional | [] | +|id | The ID of the plugin | String | required | | +|options | Dictionary of options to be passed to the plugin. Supports the following template values:

- {generatedClasses}: directory for generated class output - {temp}: temporary directory, discarded between invocations - {generatedSources}: directory for generated source output | Dictionary: String -> String | optional | {} | +|stubs_phase | Runs the compiler plugin in kapt stub generation. | Boolean | optional | True | +|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 | + + + + +## kt_javac_options + +kt_javac_options(name, warn, x_ep_disable_all_checks, x_lint, xd_suppress_notes) + + + Define java compiler options for `kt_jvm_*` rules with java sources. + + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +|name | A unique name for this target. | Name | required | | +|warn | Control warning behaviour. | String | optional | "report" | +|x_ep_disable_all_checks | See javac -XepDisableAllChecks documentation | Boolean | optional | False | +|x_lint | See javac -Xlint: documentation | List of strings | optional | [] | +|xd_suppress_notes | See javac -XDsuppressNotes documentation | Boolean | optional | False | + + ## kt_kotlinc_options -kt_kotlinc_options(name, include_stdlibs, warn, x_allow_jvm_ir_dependencies, - x_allow_result_return_type, x_inline_classes, x_jvm_default, +kt_kotlinc_options(name, include_stdlibs, java_parameters, warn, x_allow_jvm_ir_dependencies, + x_allow_result_return_type, x_inline_classes, x_jvm_default, x_multi_platform, x_no_optimized_callable_references, x_skip_prerelease_check, x_use_experimental, x_use_ir) @@ -265,11 +396,13 @@ kt_kotlinc_options(name, name | A unique name for this target. | Name | required | | |include_stdlibs | Don't automatically include the Kotlin standard libraries into the classpath (stdlib and reflect). | String | optional | "all" | +|java_parameters | Generate metadata for Java 1.8+ reflection on method parameters. | Boolean | optional | False | |warn | Control warning behaviour. | String | optional | "report" | |x_allow_jvm_ir_dependencies | Suppress errors thrown when using dependencies not compiled by the IR backend. | Boolean | optional | False | |x_allow_result_return_type | Enable kotlin.Result as a return type | Boolean | optional | False | |x_inline_classes | Enable experimental inline classes | Boolean | optional | False | |x_jvm_default | Specifies that a JVM default method should be generated for non-abstract Kotlin interface member. | String | optional | "off" | +|x_multi_platform | Enable experimental language support for multi-platform projects | Boolean | optional | False | |x_no_optimized_callable_references | Do not use optimized callable reference superclasses. Available from 1.4. | Boolean | optional | False | |x_skip_prerelease_check | Suppress errors thrown when using pre-release classes. | Boolean | optional | False | |x_use_experimental | Allow the experimental language features. | Boolean | optional | True | @@ -282,7 +415,9 @@ kt_kotlinc_options(name, name, language_version, api_version, jvm_target, experimental_use_abi_jars, - javac_options, kotlinc_options) + experimental_strict_kotlin_deps, experimental_report_unused_deps, + experimental_reduce_classpath_mode, experimental_multiplex_workers, javac_options, + kotlinc_options, jacocorunner) Define the Kotlin toolchain. @@ -297,83 +432,47 @@ Define the Kotlin toolchain. | api_version |

-

| None | | jvm_target |

-

| None | | experimental_use_abi_jars |

-

| False | +| experimental_strict_kotlin_deps |

-

| None | +| experimental_report_unused_deps |

-

| None | +| experimental_reduce_classpath_mode |

-

| None | +| experimental_multiplex_workers |

-

| None | | javac_options |

-

| None | | kotlinc_options |

-

| None | +| jacocorunner |

-

| None | - - -## kt_android_library - -
-kt_android_library(name, exports, visibility, kwargs)
-
- -Creates an Android sandwich library. - -`srcs`, `deps`, `plugins` are routed to `kt_jvm_library` the other android -related attributes are handled by the native `android_library` rule. - -**PARAMETERS** - - -| Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| name |

-

| none | -| exports |

-

| [] | -| visibility |

-

| None | -| kwargs |

-

| none | - - - + -## kt_js_import +## kt_register_toolchains
-kt_js_import(name, kwargs)
+kt_register_toolchains()
 
- +This macro registers the kotlin toolchain. **PARAMETERS** -| Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| name |

-

| none | -| kwargs |

-

| none | + - + -## kt_js_library +## kotlin_repositories
-kt_js_library(name, kwargs)
+kotlin_repositories(compiler_repostory_name, compiler_release)
 
- +Call this in the WORKSPACE file to setup the Kotlin rules. **PARAMETERS** | Name | Description | Default Value | | :-------------: | :-------------: | :-------------: | -| name |

-

| none | -| kwargs |

-

| none | - - - - -## kt_register_toolchains - -
-kt_register_toolchains()
-
- -This macro registers the kotlin toolchain. - -**PARAMETERS** - +| compiler_repostory_name |

-

| "com_github_jetbrains_kotlin" | +| compiler_release | (internal) dict containing "urls" and "sha256" for the Kotlin compiler. | {"urls": ["https://github.com/JetBrains/kotlin/releases/download/v1.4.20/kotlin-compiler-1.4.20.zip"], "sha256": "11db93a4d6789e3406c7f60b9f267eba26d6483dcd771eff9f85bb7e9837011f"} | diff --git a/examples/android/WORKSPACE b/examples/android/WORKSPACE index 17ea43fb1..436b73614 100644 --- a/examples/android/WORKSPACE +++ b/examples/android/WORKSPACE @@ -2,25 +2,32 @@ workspace(name = "android_example") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -SKYLIB_VERSION = "1.0.3" +# Directly load the kotlin rules from the parent repo. +local_repository( + name = "io_bazel_rules_kotlin", + path = "../..", +) + +load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies") + +kt_download_local_dev_dependencies() -SKYLIB_SHA = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c" +load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories", "versions") http_archive( name = "bazel_skylib", - sha256 = SKYLIB_SHA, - urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/%s/bazel-skylib-%s.tar.gz" % (SKYLIB_VERSION, SKYLIB_VERSION)], + sha256 = versions.SKYLIB_SHA, + urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/%s/bazel-skylib-%s.tar.gz" % ( + versions.SKYLIB_VERSION, + versions.SKYLIB_VERSION, + )], ) -RULES_JVM_EXTERNAL_TAG = "2.8" - -RULES_JVM_EXTERNAL_SHA = "79c9850690d7614ecdb72d68394f994fef7534b292c4867ce5e7dec0aa7bdfad" - http_archive( name = "rules_jvm_external", - sha256 = RULES_JVM_EXTERNAL_SHA, - strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG, - url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG, + sha256 = versions.RULES_JVM_EXTERNAL_SHA, + strip_prefix = "rules_jvm_external-%s" % versions.RULES_JVM_EXTERNAL_TAG, + url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % versions.RULES_JVM_EXTERNAL_TAG, ) load("@rules_jvm_external//:defs.bzl", "maven_install") @@ -64,28 +71,19 @@ load( "android_sdk_repository", ) -android_sdk_repository(name = "androidsdk") - -android_ndk_repository(name = "androidndk") # Required. Name *must* be "androidndk". - -# Directly load the kotlin rules from the parent repo. -local_repository( - name = "io_bazel_rules_kotlin", - path = "../..", +android_sdk_repository( + name = "androidsdk", + build_tools_version = versions.ANDROID.BUILD_TOOLS, # versions > 30.0.3 do not have the dx.jar anymore. ) -load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies") - -kt_download_local_dev_dependencies() - -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories") - -kotlin_repositories() - -register_toolchains("//bzl:experimental_toolchain") +android_ndk_repository(name = "androidndk") # Required. Name *must* be "androidndk". http_archive( name = "rules_pkg", sha256 = "4ba8f4ab0ff85f2484287ab06c0d871dcb31cc54d439457d28fd4ae14b18450a", url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz", ) + +kotlin_repositories() + +register_toolchains("//bzl:experimental_toolchain") diff --git a/examples/android/bzl/BUILD.bazel b/examples/android/bzl/BUILD.bazel index 885815c33..7cca444d3 100644 --- a/examples/android/bzl/BUILD.bazel +++ b/examples/android/bzl/BUILD.bazel @@ -1,5 +1,5 @@ -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "define_kt_toolchain") -load("@io_bazel_rules_kotlin//kotlin/internal:opts.bzl", "kt_javac_options", "kt_kotlinc_options") +load("@io_bazel_rules_kotlin//kotlin:core.bzl", "define_kt_toolchain", "kt_kotlinc_options") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_javac_options") kt_kotlinc_options( name = "default_kotlinc_options", diff --git a/examples/android/libAndroid/BUILD.bazel b/examples/android/libAndroid/BUILD.bazel index 50875718d..9e183eabe 100644 --- a/examples/android/libAndroid/BUILD.bazel +++ b/examples/android/libAndroid/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") load("@build_bazel_rules_android//android:rules.bzl", "android_library") android_library( diff --git a/examples/android/libKtAndroid/BUILD.bazel b/examples/android/libKtAndroid/BUILD.bazel index 91fc6e0b5..6a4205020 100644 --- a/examples/android/libKtAndroid/BUILD.bazel +++ b/examples/android/libKtAndroid/BUILD.bazel @@ -1,4 +1,5 @@ -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library", "kt_compiler_plugin") +load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_compiler_plugin") +load("@io_bazel_rules_kotlin//kotlin:android.bzl", "kt_android_library") load("@rules_java//java:defs.bzl", "java_plugin") kt_compiler_plugin( diff --git a/examples/anvil/WORKSPACE b/examples/anvil/WORKSPACE index e3727b0f8..51e2c4fc5 100644 --- a/examples/anvil/WORKSPACE +++ b/examples/anvil/WORKSPACE @@ -77,16 +77,6 @@ http_archive( urls = ["https://github.com/bazelbuild/rules_android/archive/v0.1.1.zip"], ) -load( - "@build_bazel_rules_android//android:rules.bzl", - "android_ndk_repository", - "android_sdk_repository", -) - -android_sdk_repository(name = "androidsdk") - -android_ndk_repository(name = "androidndk") # Required. Name *must* be "androidndk". - # Directly load the kotlin rules from the parent repo. local_repository( name = "io_bazel_rules_kotlin", @@ -97,12 +87,27 @@ load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_d kt_download_local_dev_dependencies() -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains") +load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories", "versions") kotlin_repositories() +load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains") + kt_register_toolchains() +load( + "@build_bazel_rules_android//android:rules.bzl", + "android_ndk_repository", + "android_sdk_repository", +) + +android_ndk_repository(name = "androidndk") # Required. Name *must* be "androidndk". + +android_sdk_repository( + name = "androidsdk", + build_tools_version = versions.ANDROID.BUILD_TOOLS, +) + # Skylib, for build_test, so don't bother initializing the unit test infrastructure. http_archive( name = "bazel_skylib", diff --git a/examples/anvil/app/src/main/java/com/squareup/anvil/sample/BUILD.bazel b/examples/anvil/app/src/main/java/com/squareup/anvil/sample/BUILD.bazel index ae4593703..89a5160bd 100644 --- a/examples/anvil/app/src/main/java/com/squareup/anvil/sample/BUILD.bazel +++ b/examples/anvil/app/src/main/java/com/squareup/anvil/sample/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library") +load("@io_bazel_rules_kotlin//kotlin:android.bzl", "kt_android_library") kt_android_library( name = "sample", diff --git a/examples/anvil/app/src/test/java/com/squareup/anvil/sample/BUILD.bazel b/examples/anvil/app/src/test/java/com/squareup/anvil/sample/BUILD.bazel index 602822fc2..ca7f2acdd 100644 --- a/examples/anvil/app/src/test/java/com/squareup/anvil/sample/BUILD.bazel +++ b/examples/anvil/app/src/test/java/com/squareup/anvil/sample/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_test") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_test") kt_jvm_test( name = "LoggedInComponentTest", diff --git a/examples/anvil/library/BUILD.bazel b/examples/anvil/library/BUILD.bazel index 2783c635f..b869fd731 100644 --- a/examples/anvil/library/BUILD.bazel +++ b/examples/anvil/library/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") kt_jvm_library( name = "library", diff --git a/examples/anvil/library/src/main/java/com/squareup/anvil/sample/BUILD.bazel b/examples/anvil/library/src/main/java/com/squareup/anvil/sample/BUILD.bazel index f6176b11a..2747eef6a 100644 --- a/examples/anvil/library/src/main/java/com/squareup/anvil/sample/BUILD.bazel +++ b/examples/anvil/library/src/main/java/com/squareup/anvil/sample/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") kt_jvm_library( name = "god", diff --git a/examples/anvil/scopes/BUILD.bazel b/examples/anvil/scopes/BUILD.bazel index a6be3c3d9..2971f1927 100644 --- a/examples/anvil/scopes/BUILD.bazel +++ b/examples/anvil/scopes/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") kt_jvm_library( name = "scopes", diff --git a/examples/anvil/scopes/src/main/java/com/squareup/scopes/BUILD.bazel b/examples/anvil/scopes/src/main/java/com/squareup/scopes/BUILD.bazel index 8859218fe..5f057c1ef 100644 --- a/examples/anvil/scopes/src/main/java/com/squareup/scopes/BUILD.bazel +++ b/examples/anvil/scopes/src/main/java/com/squareup/scopes/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") kt_jvm_library( name = "scopes", diff --git a/examples/anvil/third_party/BUILD.bazel b/examples/anvil/third_party/BUILD.bazel index a5edebc1f..4f416fb5e 100644 --- a/examples/anvil/third_party/BUILD.bazel +++ b/examples/anvil/third_party/BUILD.bazel @@ -1,5 +1,6 @@ load("@rules_java//java:defs.bzl", "java_library", "java_plugin") -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_compiler_plugin", "kt_jvm_library") +load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_compiler_plugin") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") java_plugin( name = "dagger_component_plugin", diff --git a/examples/associates/WORKSPACE b/examples/associates/WORKSPACE index 6fc6d8c32..611f443ab 100644 --- a/examples/associates/WORKSPACE +++ b/examples/associates/WORKSPACE @@ -33,21 +33,19 @@ load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_d kt_download_local_dev_dependencies() -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains") +load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories", "versions") kotlin_repositories() -kt_register_toolchains() - -RULES_JVM_EXTERNAL_TAG = "2.7" +load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains") -RULES_JVM_EXTERNAL_SHA = "f04b1466a00a2845106801e0c5cec96841f49ea4e7d1df88dc8e4bf31523df74" +kt_register_toolchains() http_archive( name = "rules_jvm_external", - sha256 = RULES_JVM_EXTERNAL_SHA, - strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG, - url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG, + sha256 = versions.RULES_JVM_EXTERNAL_SHA, + strip_prefix = "rules_jvm_external-%s" % versions.RULES_JVM_EXTERNAL_TAG, + url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % versions.RULES_JVM_EXTERNAL_TAG, ) load("@rules_jvm_external//:defs.bzl", "maven_install") diff --git a/examples/dagger/BUILD b/examples/dagger/BUILD index 9956a8f0d..ce69e5f14 100644 --- a/examples/dagger/BUILD +++ b/examples/dagger/BUILD @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. load("@rules_java//java:defs.bzl", "java_binary") -load("//kotlin:kotlin.bzl", "kt_jvm_library") +load("//kotlin:jvm.bzl", "kt_jvm_library") package(default_visibility = ["//visibility:private"]) diff --git a/examples/jetpack_compose/BUILD b/examples/jetpack_compose/BUILD index 54fa8e551..f86069e54 100644 --- a/examples/jetpack_compose/BUILD +++ b/examples/jetpack_compose/BUILD @@ -1,4 +1,5 @@ -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "define_kt_toolchain", "kt_compiler_plugin", "kt_javac_options", "kt_kotlinc_options") +load("@io_bazel_rules_kotlin//kotlin:core.bzl", "define_kt_toolchain", "kt_compiler_plugin", "kt_kotlinc_options") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_javac_options") load("@bazel_tools//tools/jdk:default_java_toolchain.bzl", "default_java_toolchain") # Java Toolchain diff --git a/examples/jetpack_compose/WORKSPACE b/examples/jetpack_compose/WORKSPACE index af1fc1619..65bda2f61 100644 --- a/examples/jetpack_compose/WORKSPACE +++ b/examples/jetpack_compose/WORKSPACE @@ -139,7 +139,7 @@ load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_d kt_download_local_dev_dependencies() -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories") +load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories") kotlin_repositories() diff --git a/examples/jetpack_compose/compose-ui/BUILD b/examples/jetpack_compose/compose-ui/BUILD index 0320e4d13..208587b8a 100644 --- a/examples/jetpack_compose/compose-ui/BUILD +++ b/examples/jetpack_compose/compose-ui/BUILD @@ -1,4 +1,4 @@ -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library") +load("@io_bazel_rules_kotlin//kotlin:android.bzl", "kt_android_library") kt_android_library( name = "lib", diff --git a/examples/multiplex/WORKSPACE b/examples/multiplex/WORKSPACE index 3f56849bd..48bcdd6c1 100644 --- a/examples/multiplex/WORKSPACE +++ b/examples/multiplex/WORKSPACE @@ -9,8 +9,10 @@ load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_d kt_download_local_dev_dependencies() -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains") +load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories") kotlin_repositories() +load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains") + kt_register_toolchains() diff --git a/examples/multiplex/src/BUILD.bazel b/examples/multiplex/src/BUILD.bazel index 5a3f2e7f8..d0465176d 100644 --- a/examples/multiplex/src/BUILD.bazel +++ b/examples/multiplex/src/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") kt_jvm_library( name = "big", diff --git a/examples/node/BUILD b/examples/node/BUILD index 8d687591a..303f76263 100644 --- a/examples/node/BUILD +++ b/examples/node/BUILD @@ -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. -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_js_import") +load("@io_bazel_rules_kotlin//kotlin:js.bzl", "kt_js_import") # Create kt_js_imports for KotlinX's Coroutines and Atomicfu libraries. # diff --git a/examples/node/WORKSPACE b/examples/node/WORKSPACE index 7417d5a49..13a67b6eb 100644 --- a/examples/node/WORKSPACE +++ b/examples/node/WORKSPACE @@ -1,5 +1,7 @@ workspace(name = "kotlin_node_examples") +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + # Directly load the kotlin rules from the parent repo. local_repository( name = "io_bazel_rules_kotlin", @@ -10,12 +12,27 @@ load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_d kt_download_local_dev_dependencies() -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains") +load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories", "versions") kotlin_repositories() +load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains") + kt_register_toolchains() +http_archive( + name = "rules_jvm_external", + sha256 = versions.RULES_JVM_EXTERNAL_SHA, + strip_prefix = "rules_jvm_external-%s" % versions.RULES_JVM_EXTERNAL_TAG, + url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % versions.RULES_JVM_EXTERNAL_TAG, +) + +http_archive( + name = "build_bazel_rules_nodejs", + sha256 = versions.RULES_NODEJS_SHA, + url = "https://github.com/bazelbuild/rules_nodejs/releases/download/{0}/rules_nodejs-{0}.tar.gz".format(versions.RULES_NODEJS_VERSION), +) + load("@rules_jvm_external//:defs.bzl", "maven_install") maven_install( diff --git a/examples/node/coroutines-helloworld/BUILD b/examples/node/coroutines-helloworld/BUILD index ebc7410b9..fc3efc2e0 100644 --- a/examples/node/coroutines-helloworld/BUILD +++ b/examples/node/coroutines-helloworld/BUILD @@ -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. -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_js_library") +load("@io_bazel_rules_kotlin//kotlin:js.bzl", "kt_js_library") load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary") kt_js_library( diff --git a/examples/node/express/BUILD b/examples/node/express/BUILD index a0287b17c..4675ef4f4 100644 --- a/examples/node/express/BUILD +++ b/examples/node/express/BUILD @@ -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. -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_js_library") +load("@io_bazel_rules_kotlin//kotlin:js.bzl", "kt_js_library") load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary") # routes and auth have acme prepended to the rule name as these are the names of the resulting jars. The name of the diff --git a/examples/node/express/auth/BUILD b/examples/node/express/auth/BUILD index f3fdf7cce..430dbe3f2 100644 --- a/examples/node/express/auth/BUILD +++ b/examples/node/express/auth/BUILD @@ -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. -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_js_library") +load("@io_bazel_rules_kotlin//kotlin:js.bzl", "kt_js_library") kt_js_library( name = "acme-auth", diff --git a/examples/plugin/WORKSPACE b/examples/plugin/WORKSPACE index 9bd81d0b1..a2e599f4a 100644 --- a/examples/plugin/WORKSPACE +++ b/examples/plugin/WORKSPACE @@ -21,10 +21,6 @@ http_archive( urls = ["https://github.com/bazelbuild/rules_android/archive/v0.1.1.zip"], ) -load("@rules_android//android:rules.bzl", "android_sdk_repository") - -android_sdk_repository(name = "androidsdk") - http_archive( name = "rules_jvm_external", sha256 = RULES_JVM_EXTERNAL_SHA, @@ -41,10 +37,12 @@ load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_d kt_download_local_dev_dependencies() -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains") +load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories", "versions") kotlin_repositories() +load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains") + kt_register_toolchains() load("@rules_jvm_external//:defs.bzl", "maven_install") @@ -58,3 +56,10 @@ maven_install( "https://repo1.maven.org/maven2", ], ) + +load("@rules_android//android:rules.bzl", "android_sdk_repository") + +android_sdk_repository( + name = "androidsdk", + build_tools_version = versions.ANDROID.BUILD_TOOLS, +) diff --git a/examples/plugin/src/allopen/BUILD b/examples/plugin/src/allopen/BUILD index b0b28bbe8..39f10f566 100644 --- a/examples/plugin/src/allopen/BUILD +++ b/examples/plugin/src/allopen/BUILD @@ -1,4 +1,5 @@ -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_compiler_plugin", "kt_jvm_library") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") +load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_compiler_plugin") kt_compiler_plugin( name = "open_for_testing_plugin", diff --git a/examples/plugin/src/allopennoarg/BUILD b/examples/plugin/src/allopennoarg/BUILD index c7f96f79f..be7f31afb 100644 --- a/examples/plugin/src/allopennoarg/BUILD +++ b/examples/plugin/src/allopennoarg/BUILD @@ -1,4 +1,5 @@ -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_compiler_plugin", "kt_jvm_library", "kt_jvm_test") +load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_compiler_plugin") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library", "kt_jvm_test") kt_compiler_plugin( name = "open_for_testing_plugin", diff --git a/examples/plugin/src/noarg/BUILD b/examples/plugin/src/noarg/BUILD index 1e8af6476..4d786ebc2 100644 --- a/examples/plugin/src/noarg/BUILD +++ b/examples/plugin/src/noarg/BUILD @@ -1,4 +1,5 @@ -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_compiler_plugin", "kt_jvm_library", "kt_jvm_test") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library", "kt_jvm_test") +load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_compiler_plugin") kt_compiler_plugin( name = "no_arg_plugin", diff --git a/examples/plugin/src/parcelize/BUILD b/examples/plugin/src/parcelize/BUILD index 73535c35c..e0ac8be71 100644 --- a/examples/plugin/src/parcelize/BUILD +++ b/examples/plugin/src/parcelize/BUILD @@ -1,4 +1,6 @@ -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library", "kt_compiler_plugin", "kt_jvm_library") +load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_compiler_plugin") +load("@io_bazel_rules_kotlin//kotlin:android.bzl", "kt_android_library") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") kt_compiler_plugin( name = "parcelize_plugin", diff --git a/examples/plugin/src/sam_with_receiver/BUILD b/examples/plugin/src/sam_with_receiver/BUILD index 97f1257d5..33e518485 100644 --- a/examples/plugin/src/sam_with_receiver/BUILD +++ b/examples/plugin/src/sam_with_receiver/BUILD @@ -1,4 +1,5 @@ -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_compiler_plugin", "kt_jvm_library") +load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_compiler_plugin") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") load("@rules_java//java:defs.bzl", "java_library") kt_compiler_plugin( diff --git a/examples/plugin/src/serialization/BUILD b/examples/plugin/src/serialization/BUILD index b5ace52b2..c5b0b7dad 100644 --- a/examples/plugin/src/serialization/BUILD +++ b/examples/plugin/src/serialization/BUILD @@ -1,4 +1,5 @@ -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_compiler_plugin", "kt_jvm_library", "kt_jvm_test") +load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_compiler_plugin") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library", "kt_jvm_test") kt_compiler_plugin( name = "serialization_plugin", diff --git a/examples/trivial/WORKSPACE b/examples/trivial/WORKSPACE index 9a83c4264..2e254be08 100644 --- a/examples/trivial/WORKSPACE +++ b/examples/trivial/WORKSPACE @@ -9,10 +9,12 @@ load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_d kt_download_local_dev_dependencies() -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains") +load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories") kotlin_repositories() +load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains") + kt_register_toolchains() RULES_JVM_EXTERNAL_TAG = "2.7" diff --git a/examples/trivial/app/BUILD.bazel b/examples/trivial/app/BUILD.bazel index a26a8e301..3ea87a0b4 100644 --- a/examples/trivial/app/BUILD.bazel +++ b/examples/trivial/app/BUILD.bazel @@ -1,5 +1,6 @@ load("@rules_java//java:defs.bzl", "java_binary") -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library", "ktlint_fix", "ktlint_test") +load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") +load("@io_bazel_rules_kotlin//kotlin:lint.bzl", "ktlint_fix", "ktlint_test") kt_jvm_library( name = "app_lib", diff --git a/kotlin/BUILD b/kotlin/BUILD index 53e388ac8..6e52d4ecf 100644 --- a/kotlin/BUILD +++ b/kotlin/BUILD @@ -13,13 +13,15 @@ # limitations under the License. load("//kotlin/internal/utils:packager.bzl", "release_archive") load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc") -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") release_archive( name = "pkg", srcs = glob( ["*.bzl"], - exclude = ["dependencies.bzl"], + exclude = [ + "dependencies.bzl", + "repositories.doc.bzl", + ], ), src_map = { "dependencies.release.bzl": "dependencies.bzl", @@ -30,35 +32,38 @@ release_archive( ], ) -bzl_library( - name = "kotlin", - srcs = ["kotlin.bzl"], - visibility = ["//kotlin:__subpackages__"], - deps = [ - "//kotlin/internal", - ], -) +[ + stardoc( + name = doc, + out = "%s.md" % doc, + input = "%s.bzl" % doc, + rule_template = "//kotlin:doc-templates/rule.vm", + deps = [ + "//kotlin/internal", + ], + ) + for doc in [ + "js", + "jvm", + "lint", + "core", + "repositories.doc", + ] +] -stardoc( +genrule( name = "stardoc", - out = "kotlin.md", - input = "rules.bzl", - rule_template = "//kotlin:doc-templates/rule.vm", - symbol_names = [ - "define_kt_toolchain", - "kt_js_library", - "kt_js_import", - "kt_register_toolchains", - "kt_jvm_binary", - "kt_jvm_import", - "kt_jvm_library", - "kt_jvm_test", - "kt_android_library", - "kt_compiler_plugin", - "kt_kotlinc_options", - "kt_javac_options", - ], - deps = [ - "kotlin", - ], + srcs = [doc for doc in [ + "js", + "jvm", + "lint", + "core", + "repositories.doc", + ]], + outs = ["kotlin.md"], + cmd = """ + for md in $(SRCS); do + cat "$$md" >> $@ + done + """, ) diff --git a/kotlin/android.bzl b/kotlin/android.bzl new file mode 100644 index 000000000..6095ad60b --- /dev/null +++ b/kotlin/android.bzl @@ -0,0 +1,8 @@ +load( + "//kotlin/internal/jvm:android.bzl", + _kt_android_library = "kt_android_library", + _kt_android_local_test = "kt_android_local_test", +) + +kt_android_library = _kt_android_library +kt_android_local_test = _kt_android_local_test diff --git a/kotlin/core.bzl b/kotlin/core.bzl new file mode 100644 index 000000000..894690c0e --- /dev/null +++ b/kotlin/core.bzl @@ -0,0 +1,20 @@ +load( + "//kotlin/internal:opts.bzl", + _kt_javac_options = "kt_javac_options", + _kt_kotlinc_options = "kt_kotlinc_options", +) +load( + "//kotlin/internal/jvm:jvm.bzl", + _kt_compiler_plugin = "kt_compiler_plugin", +) +load( + "//kotlin/internal:toolchains.bzl", + _define_kt_toolchain = "define_kt_toolchain", + _kt_register_toolchains = "kt_register_toolchains", +) + +define_kt_toolchain = _define_kt_toolchain +kt_register_toolchains = _kt_register_toolchains +kt_javac_options = _kt_javac_options +kt_kotlinc_options = _kt_kotlinc_options +kt_compiler_plugin = _kt_compiler_plugin diff --git a/kotlin/internal/jvm/android.bzl b/kotlin/internal/jvm/android.bzl index 058bf0452..0bd66cedb 100644 --- a/kotlin/internal/jvm/android.bzl +++ b/kotlin/internal/jvm/android.bzl @@ -1,5 +1,3 @@ -load("@rules_android//android:rules.bzl", "android_library", "android_local_test") - # Copyright 2018 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -40,7 +38,10 @@ def _kt_android_artifact( # TODO(bazelbuild/rules_kotlin/issues/273): This should be retrieved from a provider. base_deps = deps + [_ANDROID_SDK_JAR] - android_library( + + # TODO(bazelbuild/rules_kotlin/issues/556): replace with starlark + # buildifier: disable=native-android + native.android_library( name = base_name, visibility = ["//visibility:private"], exports = base_deps, @@ -70,7 +71,10 @@ def kt_android_library(name, exports = [], visibility = None, **kwargs): `srcs`, `deps`, `plugins` are routed to `kt_jvm_library` the other android related attributes are handled by the native `android_library` rule. """ - android_library( + + # TODO(bazelbuild/rules_kotlin/issues/556): replace with starlark + # buildifier: disable=native-android + native.android_library( name = name, exports = exports + _kt_android_artifact(name, **kwargs), visibility = visibility, @@ -97,7 +101,10 @@ def kt_android_local_test( related attributes are handled by the native `android_library` rule while the test attributes are picked out and handled by the `android_local_test` rule. """ - android_local_test( + + # TODO(556): replace with starlark + # buildifier: disable=native-android + native.android_local_test( name = name, deps = kwargs.get("deps", []) + _kt_android_artifact(name = name, testonly = testonly, **kwargs), jvm_flags = jvm_flags, diff --git a/kotlin/internal/jvm/jvm.bzl b/kotlin/internal/jvm/jvm.bzl index e0fecdedf..7565b3ceb 100644 --- a/kotlin/internal/jvm/jvm.bzl +++ b/kotlin/internal/jvm/jvm.bzl @@ -23,8 +23,10 @@ git_repository( remote = "https://github.com/bazelbuild/rules_kotlin.git", commit = "", ) -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains") +load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories") kotlin_repositories(kotlin_release_version = "1.4.0") + +load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains") kt_register_toolchains() ``` diff --git a/kotlin/internal/repositories/BUILD b/kotlin/internal/repositories/BUILD index 4dbe89b9e..43678f1e4 100644 --- a/kotlin/internal/repositories/BUILD +++ b/kotlin/internal/repositories/BUILD @@ -31,4 +31,8 @@ bzl_library( name = "repositories", srcs = glob(["*.bzl"]), visibility = ["//kotlin:__subpackages__"], + deps = [ + "@rules_proto//proto", + "@rules_proto//proto/private", + ], ) diff --git a/kotlin/internal/repositories/BUILD.com_github_jetbrains_kotlin b/kotlin/internal/repositories/BUILD.com_github_jetbrains_kotlin index 7f6f7b365..e7b74ca63 100644 --- a/kotlin/internal/repositories/BUILD.com_github_jetbrains_kotlin +++ b/kotlin/internal/repositories/BUILD.com_github_jetbrains_kotlin @@ -13,7 +13,8 @@ # limitations under the License. package(default_visibility = ["//visibility:public"]) -load("{{.KotlinRules}}", "kt_js_import", "kt_jvm_import") +load("@{{.KotlinRulesRepository}}//kotlin:jvm.bzl", "kt_jvm_import") +load("@{{.KotlinRulesRepository}}//kotlin:js.bzl", "kt_js_import") load("@rules_java//java:defs.bzl", "java_import") # Kotlin home filegroup containing everything that is needed. diff --git a/kotlin/internal/repositories/download.bzl b/kotlin/internal/repositories/download.bzl index 0aabac0ac..641dfc87d 100644 --- a/kotlin/internal/repositories/download.bzl +++ b/kotlin/internal/repositories/download.bzl @@ -13,7 +13,7 @@ # limitations under the versions.License. load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_jar") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") -load("//kotlin/internal/repositories:rules_android_stardoc.bzl", "rules_android_stardoc_repository") +load("//kotlin/internal/repositories:rules_stardoc.bzl", "rules_stardoc_repository") load(":versions.bzl", "versions") def kt_download_local_dev_dependencies(): @@ -33,17 +33,6 @@ def kt_download_local_dev_dependencies(): ], ) - maybe( - http_archive, - name = "rules_proto", - sha256 = versions.RULES_PROTO_SHA, - strip_prefix = "rules_proto-%s" % versions.RULES_PROTO_GIT_COMMIT, - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/%s.tar.gz" % versions.RULES_PROTO_GIT_COMMIT, - "https://github.com/bazelbuild/rules_proto/archive/%s.tar.gz" % versions.RULES_PROTO_GIT_COMMIT, - ], - ) - maybe( http_archive, name = "bazel_skylib", @@ -99,9 +88,26 @@ def kt_download_local_dev_dependencies(): url = "https://github.com/bazelbuild/stardoc/archive/%s.tar.gz" % versions.IO_BAZEL_STARDOC_VERSION, ) - rules_android_stardoc_repository( + rules_stardoc_repository( name = "rules_android", - sha = versions.ANDROID.SHA, + sha256 = versions.ANDROID.SHA, strip_prefix = "rules_android-%s" % versions.ANDROID.VERSION, urls = versions.ANDROID.URLS, + starlark_packages = [ + "android", + ], + ) + + rules_stardoc_repository( + name = "rules_proto", + sha256 = versions.RULES_PROTO_SHA, + strip_prefix = "rules_proto-%s" % versions.RULES_PROTO_GIT_COMMIT, + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/%s.tar.gz" % versions.RULES_PROTO_GIT_COMMIT, + "https://github.com/bazelbuild/rules_proto/archive/%s.tar.gz" % versions.RULES_PROTO_GIT_COMMIT, + ], + starlark_packages = [ + "proto", + "proto/private", + ], ) diff --git a/kotlin/internal/repositories/release_repositories.bzl b/kotlin/internal/repositories/release_repositories.bzl index 901b8be2f..4c104fbd6 100644 --- a/kotlin/internal/repositories/release_repositories.bzl +++ b/kotlin/internal/repositories/release_repositories.bzl @@ -24,10 +24,9 @@ load( "http_file", ) load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") -load(":tools.bzl", "absolute_target") load(":versions.bzl", "versions") -KOTLIN_RULES = absolute_target("//kotlin:kotlin.bzl") +KOTLIN_RULES = Label("//kotlin:core.bzl") def kotlin_repositories( compiler_repostory_name = _KT_COMPILER_REPO, @@ -42,7 +41,7 @@ def kotlin_repositories( name = _KT_COMPILER_REPO, urls = compiler_release["urls"], sha256 = compiler_release["sha256"], - kotlin_rules = KOTLIN_RULES, + kotlin_rules = KOTLIN_RULES.workspace_name, ) http_file( @@ -87,7 +86,6 @@ def kotlin_repositories( def _kotlin_compiler_impl(repository_ctx): """Creates the kotlinc repository.""" attr = repository_ctx.attr - repository_ctx.download_and_extract( attr.urls, sha256 = attr.sha256, @@ -101,7 +99,7 @@ def _kotlin_compiler_impl(repository_ctx): "BUILD.bazel", attr._template, substitutions = { - "{{.KotlinRules}}": attr.kotlin_rules, + "{{.KotlinRulesRepository}}": attr.kotlin_rules, }, executable = False, ) diff --git a/kotlin/internal/repositories/rules_android_stardoc.bzl b/kotlin/internal/repositories/rules_android_stardoc.bzl deleted file mode 100644 index 3ceca5076..000000000 --- a/kotlin/internal/repositories/rules_android_stardoc.bzl +++ /dev/null @@ -1,36 +0,0 @@ -# Defines a repository rule that exports rules_android bzl files and well as wrappers. - -BUILD_TEMPLATE = """ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - -bzl_library( - name = "{name}", - srcs = glob(["**/*.bzl"]), - visibility = ["//visibility:public"], -) - -""" - -def _rules_android_stardoc_repository_impl(repository_ctx): - attrs = repository_ctx.attr - repository_ctx.download_and_extract( - url = attrs.urls, - sha256 = attrs.sha, - stripPrefix = attrs.strip_prefix, - ) - repository_ctx.delete("android/BUILD") - repository_ctx.file( - "android/BUILD", - content = BUILD_TEMPLATE.format( - name = "android", - ), - ) - -rules_android_stardoc_repository = repository_rule( - implementation = _rules_android_stardoc_repository_impl, - attrs = { - "sha": attr.string(), - "strip_prefix": attr.string(), - "urls": attr.string_list(), - }, -) diff --git a/kotlin/internal/repositories/rules_stardoc.bzl b/kotlin/internal/repositories/rules_stardoc.bzl new file mode 100644 index 000000000..45499a590 --- /dev/null +++ b/kotlin/internal/repositories/rules_stardoc.bzl @@ -0,0 +1,46 @@ +# Defines a repository rule that exports rules_android bzl files and well as wrappers. + +LOAD = """ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +""" + +RULE_TEMPLATE = """ +bzl_library( + name = "{name}", + srcs = glob(["**/*.bzl"]), + visibility = ["//visibility:public"], +) +""" + +def _rules_stardoc_repository_impl(repository_ctx): + attrs = repository_ctx.attr + repository_ctx.download_and_extract( + url = attrs.urls, + sha256 = attrs.sha256, + stripPrefix = attrs.strip_prefix, + ) + print("%s prepping" % attrs.name) + for src in attrs.starlark_packages: + path = repository_ctx.path(src) + build = path.get_child("BUILD") + contents = "" + if build.exists: + contents = repository_ctx.read(build) + print("%s prepping %s" % (attrs.name, contents)) + print("%s", path.readdir()) + repository_ctx.file( + "%s/BUILD" % path, + content = LOAD + contents + RULE_TEMPLATE.format( + name = path.basename, + ), + ) + +rules_stardoc_repository = repository_rule( + implementation = _rules_stardoc_repository_impl, + attrs = { + "sha256": attr.string(), + "strip_prefix": attr.string(), + "urls": attr.string_list(), + "starlark_packages": attr.string_list(), + }, +) diff --git a/kotlin/internal/repositories/versions.bzl b/kotlin/internal/repositories/versions.bzl index a90161f3a..7badb1973 100644 --- a/kotlin/internal/repositories/versions.bzl +++ b/kotlin/internal/repositories/versions.bzl @@ -10,8 +10,8 @@ versions = struct( PROTOBUF_SHA = "cf754718b0aa945b00550ed7962ddc167167bd922b842199eeb6505e6f344852", BAZEL_DEPS_VERSION = "0.1.0", BAZEL_DEPS_SHA = "05498224710808be9687f5b9a906d11dd29ad592020246d4cd1a26eeaed0735e", - RULES_JVM_EXTERNAL_TAG = "2.7", - RULES_JVM_EXTERNAL_SHA = "f04b1466a00a2845106801e0c5cec96841f49ea4e7d1df88dc8e4bf31523df74", + RULES_JVM_EXTERNAL_TAG = "4.0", + RULES_JVM_EXTERNAL_SHA = "31701ad93dbfe544d597dbe62c9a1fdd76d81d8a9150c2bf1ecf928ecdf97169", RULES_PROTO_GIT_COMMIT = "f6b8d89b90a7956f6782a4a3609b2f0eee3ce965", RULES_PROTO_SHA = "4d421d51f9ecfe9bf96ab23b55c6f2b809cbaf0eea24952683e397decfbd0dd0", IO_BAZEL_STARDOC_VERSION = "0.4.0", @@ -27,6 +27,7 @@ versions = struct( VERSION = "0.1.1", SHA = "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806", URLS = ["https://github.com/bazelbuild/rules_android/archive/v%s.zip" % "0.1.1"], + BUILD_TOOLS = "30.0.1", ), PYTHON = struct( VERSION = "0.2.0", diff --git a/kotlin/js.bzl b/kotlin/js.bzl new file mode 100644 index 000000000..2e454a20e --- /dev/null +++ b/kotlin/js.bzl @@ -0,0 +1,8 @@ +load( + "//kotlin/internal/js:js.bzl", + _kt_js_import = "kt_js_import_macro", + _kt_js_library = "kt_js_library_macro", +) + +kt_js_import = _kt_js_import +kt_js_library = _kt_js_library diff --git a/kotlin/jvm.bzl b/kotlin/jvm.bzl new file mode 100644 index 000000000..944b8fc04 --- /dev/null +++ b/kotlin/jvm.bzl @@ -0,0 +1,17 @@ +load( + "//kotlin/internal/jvm:jvm.bzl", + _kt_jvm_binary = "kt_jvm_binary", + _kt_jvm_import = "kt_jvm_import", + _kt_jvm_library = "kt_jvm_library", + _kt_jvm_test = "kt_jvm_test", +) +load( + "//kotlin/internal:opts.bzl", + _kt_javac_options = "kt_javac_options", +) + +kt_javac_options = _kt_javac_options +kt_jvm_binary = _kt_jvm_binary +kt_jvm_import = _kt_jvm_import +kt_jvm_library = _kt_jvm_library +kt_jvm_test = _kt_jvm_test diff --git a/kotlin/kotlin.bzl b/kotlin/kotlin.bzl index 4a8fe8b00..27fcb15c3 100644 --- a/kotlin/kotlin.bzl +++ b/kotlin/kotlin.bzl @@ -13,43 +13,165 @@ # limitations under the License. load( - "//kotlin/internal/repositories:repositories.bzl", + ":repositories.bzl", _kotlin_repositories = "kotlin_repositories", ) load( - "//kotlin:rules.bzl", - _define_kt_toolchain = "define_kt_toolchain", - _kt_android_library = "kt_android_library", - _kt_android_local_test = "kt_android_local_test", - _kt_compiler_plugin = "kt_compiler_plugin", - _kt_javac_options = "kt_javac_options", - _kt_js_import = "kt_js_import", - _kt_js_library = "kt_js_library", + ":jvm.bzl", _kt_jvm_binary = "kt_jvm_binary", _kt_jvm_import = "kt_jvm_import", _kt_jvm_library = "kt_jvm_library", _kt_jvm_test = "kt_jvm_test", - _kt_kotlinc_options = "kt_kotlinc_options", - _kt_register_toolchains = "kt_register_toolchains", +) +load( + ":android.bzl", + _kt_android_library = "kt_android_library", + _kt_android_local_test = "kt_android_local_test", +) +load( + ":js.bzl", + _kt_js_import = "kt_js_import", + _kt_js_library = "kt_js_library", +) +load( + ":lint.bzl", _ktlint_config = "ktlint_config", _ktlint_fix = "ktlint_fix", _ktlint_test = "ktlint_test", ) +load( + ":core.bzl", + _define_kt_toolchain = "define_kt_toolchain", + _kt_compiler_plugin = "kt_compiler_plugin", + _kt_register_toolchains = "kt_register_toolchains", +) + +def kotlin_repositories(**kwargs): + """ + Forwarding macro for _kotlin_repositories + + Deprecated: + _kotlin_repositories should be loaded from //kotlin:repositories.bzl + """ + print("_kotlin_repositories should be loaded from //kotlin:repositories.bzl") + _kotlin_repositories(**kwargs) -kotlin_repositories = _kotlin_repositories define_kt_toolchain = _define_kt_toolchain -kt_kotlinc_options = _kt_kotlinc_options -kt_javac_options = _kt_javac_options -kt_js_library = _kt_js_library -kt_js_import = _kt_js_import kt_register_toolchains = _kt_register_toolchains -kt_jvm_binary = _kt_jvm_binary -kt_jvm_import = _kt_jvm_import -kt_jvm_library = _kt_jvm_library -kt_jvm_test = _kt_jvm_test -kt_android_library = _kt_android_library -kt_android_local_test = _kt_android_local_test kt_compiler_plugin = _kt_compiler_plugin -ktlint_config = _ktlint_config -ktlint_fix = _ktlint_fix -ktlint_test = _ktlint_test + +def kt_kotlinc_options(**kwargs): + fail("use load('//kotlin:core.bzl', kt_kotlinc_options)") + +def kt_javac_options(**kwargs): + fail("use load('//kotlin:core.bzl', kt_javac_options)") + +def kt_js_library(**kwargs): + """ + Forwarding macro for kt_js_library + + Deprecated: + kt_js_library should be loaded from //kotlin:js.bzl + """ + print("kt_js_library should be loaded from //kotlin:js.bzl") + _kt_js_library(**kwargs) + +def kt_js_import(**kwargs): + """ + Forwarding macro for kt_js_import + + Deprecated: + kt_js_import should be loaded from //kotlin:js.bzl + """ + print("kt_js_import should be loaded from //kotlin:js.bzl") + _kt_js_import(**kwargs) + +def kt_jvm_binary(**kwargs): + """ + Forwarding macro for kt_jvm_binary + + Deprecated: + kt_jvm_binary should be loaded from //kotlin:jvm.bzl + """ + print("kt_jvm_binary should be loaded from //kotlin:jvm.bzl") + _kt_jvm_binary(**kwargs) + +def kt_jvm_import(**kwargs): + """ + Forwarding macro for kt_jvm_import + + Deprecated: + kt_jvm_import should be loaded from //kotlin:jvm.bzl + """ + print("kt_jvm_import should be loaded from //kotlin:jvm.bzl") + _kt_jvm_import(**kwargs) + +def kt_jvm_library(**kwargs): + """ + Forwarding macro for kt_jvm_library + + Deprecated: + kt_jvm_library should be loaded from //kotlin:jvm.bzl + """ + print("kt_jvm_library should be loaded from //kotlin:jvm.bzl") + _kt_jvm_library(**kwargs) + +def kt_jvm_test(**kwargs): + """ + Forwarding macro for kt_jvm_test + + Deprecated: + kt_jvm_test should be loaded from //kotlin:jvm.bzl + """ + print("kt_jvm_test should be loaded from //kotlin:jvm.bzl") + _kt_jvm_test(**kwargs) + +def kt_android_library(**kwargs): + """ + Forwarding macro for kt_android_local_test + + Deprecated: + kt_android_library should be loaded from //kotlin:android.bzl + """ + print("kt_android_library should be loaded from //kotlin:android.bzl") + _kt_android_library(**kwargs) + +def kt_android_local_test(**kwargs): + """ + Forwarding macro for kt_android_local_test + + Deprecated: + kt_android_local_test should be loaded from //kotlin:android.bzl + """ + print("kt_android_local_test should be loaded from //kotlin:android.bzl") + _kt_android_local_test(**kwargs) + +def ktlint_config(**kwargs): + """ + Forwarding macro for ktlint_config + + Deprecated: + ktlint_config should be loaded from //kotlin:lint.bzl + """ + print("ktlint_config should be loaded from //kotlin:lint.bzl") + _ktlint_config(**kwargs) + +def ktlint_fix(**kwargs): + """ + Forwarding macro for ktlint_fix + + Deprecated: + ktlint_fix should be loaded from //kotlin:lint.bzl + """ + print("ktlint_fix should be loaded from //kotlin:lint.bzl") + _ktlint_fix(**kwargs) + +def ktlint_test(**kwargs): + """ + Forwarding macro for ktlint_test + + Deprecated: + ktlint_test should be loaded from //kotlin:lint.bzl + """ + print("ktlint_test should be loaded from //kotlin:lint.bzl") + _ktlint_test(**kwargs) diff --git a/kotlin/lint.bzl b/kotlin/lint.bzl new file mode 100644 index 000000000..e37c8d848 --- /dev/null +++ b/kotlin/lint.bzl @@ -0,0 +1,7 @@ +load("//kotlin/internal/lint:ktlint_config.bzl", _ktlint_config = "ktlint_config") +load("//kotlin/internal/lint:ktlint_fix.bzl", _ktlint_fix = "ktlint_fix") +load("//kotlin/internal/lint:ktlint_test.bzl", _ktlint_test = "ktlint_test") + +ktlint_fix = _ktlint_fix +ktlint_test = _ktlint_test +ktlint_config = _ktlint_config diff --git a/kotlin/repositories.bzl b/kotlin/repositories.bzl new file mode 100644 index 000000000..eb6c97eb9 --- /dev/null +++ b/kotlin/repositories.bzl @@ -0,0 +1,11 @@ +load( + "//kotlin/internal/repositories:repositories.bzl", + _kotlin_repositories = "kotlin_repositories", +) +load( + "//kotlin/internal/repositories:versions.bzl", + _versions = "versions", +) + +kotlin_repositories = _kotlin_repositories +versions = _versions diff --git a/kotlin/repositories.doc.bzl b/kotlin/repositories.doc.bzl new file mode 100644 index 000000000..ccea0d8f5 --- /dev/null +++ b/kotlin/repositories.doc.bzl @@ -0,0 +1,11 @@ +load( + "//kotlin/internal/repositories:release_repositories.bzl", + _kotlin_repositories = "kotlin_repositories", +) +load( + "//kotlin/internal/repositories:versions.bzl", + _versions = "versions", +) + +kotlin_repositories = _kotlin_repositories +versions = _versions diff --git a/kotlin/rules.bzl b/kotlin/rules.bzl deleted file mode 100644 index e4ee1180f..000000000 --- a/kotlin/rules.bzl +++ /dev/null @@ -1,64 +0,0 @@ -# Copyright 2020 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. - -# Separate starlark collection of purely rules for stardoc generation - -load( - "//kotlin/internal:toolchains.bzl", - _define_kt_toolchain = "define_kt_toolchain", - _kt_register_toolchains = "kt_register_toolchains", -) -load( - "//kotlin/internal:opts.bzl", - _kt_javac_options = "kt_javac_options", - _kt_kotlinc_options = "kt_kotlinc_options", -) -load( - "//kotlin/internal/jvm:jvm.bzl", - _kt_compiler_plugin = "kt_compiler_plugin", - _kt_jvm_binary = "kt_jvm_binary", - _kt_jvm_import = "kt_jvm_import", - _kt_jvm_library = "kt_jvm_library", - _kt_jvm_test = "kt_jvm_test", -) -load( - "//kotlin/internal/jvm:android.bzl", - _kt_android_library = "kt_android_library", - _kt_android_local_test = "kt_android_local_test", -) -load( - "//kotlin/internal/js:js.bzl", - _kt_js_import = "kt_js_import_macro", - _kt_js_library = "kt_js_library_macro", -) -load("//kotlin/internal/lint:ktlint_config.bzl", _ktlint_config = "ktlint_config") -load("//kotlin/internal/lint:ktlint_fix.bzl", _ktlint_fix = "ktlint_fix") -load("//kotlin/internal/lint:ktlint_test.bzl", _ktlint_test = "ktlint_test") - -define_kt_toolchain = _define_kt_toolchain -kt_kotlinc_options = _kt_kotlinc_options -kt_javac_options = _kt_javac_options -kt_js_library = _kt_js_library -kt_js_import = _kt_js_import -kt_register_toolchains = _kt_register_toolchains -kt_jvm_binary = _kt_jvm_binary -kt_jvm_import = _kt_jvm_import -kt_jvm_library = _kt_jvm_library -kt_jvm_test = _kt_jvm_test -kt_android_library = _kt_android_library -kt_android_local_test = _kt_android_local_test -kt_compiler_plugin = _kt_compiler_plugin -ktlint_config = _ktlint_config -ktlint_fix = _ktlint_fix -ktlint_test = _ktlint_test diff --git a/scripts/reflow_skylark b/scripts/reflow_skylark index 327cfdca1..1683d316e 100755 --- a/scripts/reflow_skylark +++ b/scripts/reflow_skylark @@ -15,7 +15,7 @@ # Note: Written on a mac please make it compatible with linux if needed. #!/usr/bin/env bash -buildifier $(find . -type f \ +buildifier --warnings=-confusing-name,-constant-glob,-duplicated-name,-function-docstring,-function-docstring-args,-function-docstring-header,-module-docstring,-name-conventions,-no-effect,-constant-glob,-provider-params,-print,-rule-impl-return,-bzl-visibility,-unnamed-macro,-uninitialized,-unreachable -lint warn $(find . -type f \ -iname "*.bzl" -or \ -name "*.bazel" -or \ -name "WORKSPACE" diff --git a/scripts/release.sh b/scripts/release.sh index b2898792e..3f988ba2d 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -17,7 +17,7 @@ TMPDIR="$1" shift -if [[ -z $TMPDIR ]]; then +if [[ -z $TMPDIR ]]; then TMPDIR="/tmp" fi BUILD_ARGS="$@" @@ -37,6 +37,11 @@ while [[ ! -f "WORKSPACE" ]]; do fi done +# lint +if ! scripts/reflow_skylark; then + fail "Lint errors" +fi + # validate if test ! -d examples; then fail "unable to find example directory: $PWD" @@ -52,7 +57,7 @@ rm -rf $ARCHIVE_DIR mkdir $ARCHIVE_DIR tar -C $ARCHIVE_DIR -xzvf bazel-bin/rules_kotlin_release.tgz -shasum -a 256 bazel-bin/rules_kotlin_release.tgz > bazel-bin/rules_kotlin_release.tgz.sha256 +shasum -a 256 bazel-bin/rules_kotlin_release.tgz >bazel-bin/rules_kotlin_release.tgz.sha256 # iterate through the examples and build them for ex in examples/*/; do diff --git a/src/main/kotlin/bootstrap.bzl b/src/main/kotlin/bootstrap.bzl index 8325e4eda..de1f9855b 100644 --- a/src/main/kotlin/bootstrap.bzl +++ b/src/main/kotlin/bootstrap.bzl @@ -13,7 +13,7 @@ # limitations under the License. load("@rules_java//java:defs.bzl", "java_binary", "java_import") load("//third_party:jarjar.bzl", "jar_jar") -load("//kotlin:kotlin.bzl", _for_ide = "kt_jvm_library") +load("//kotlin:jvm.bzl", _for_ide = "kt_jvm_library") _BOOTSTRAP_LIB_ARGS = ["-jvm-target", "1.8"] diff --git a/src/test/data/jvm/basic/BUILD b/src/test/data/jvm/basic/BUILD index 17f772e2c..f1057e4c8 100644 --- a/src/test/data/jvm/basic/BUILD +++ b/src/test/data/jvm/basic/BUILD @@ -1,5 +1,5 @@ load("@rules_java//java:defs.bzl", "java_binary", "java_library") -load("//kotlin:kotlin.bzl", "kt_jvm_binary", "kt_jvm_library") +load("//kotlin:jvm.bzl", "kt_jvm_binary", "kt_jvm_library") # Copyright 2018 The Bazel Authors. All rights reserved. # diff --git a/src/test/data/jvm/kapt/BUILD b/src/test/data/jvm/kapt/BUILD index 2f432c3bf..d3c3713b3 100644 --- a/src/test/data/jvm/kapt/BUILD +++ b/src/test/data/jvm/kapt/BUILD @@ -1,5 +1,5 @@ load("@rules_java//java:defs.bzl", "java_library", "java_plugin") -load("//kotlin:kotlin.bzl", "kt_jvm_library") +load("//kotlin:jvm.bzl", "kt_jvm_library") # Copyright 2018 The Bazel Authors. All rights reserved. # diff --git a/src/test/kotlin/io/bazel/kotlin/BUILD b/src/test/kotlin/io/bazel/kotlin/BUILD index 94adf5291..6679cff46 100644 --- a/src/test/kotlin/io/bazel/kotlin/BUILD +++ b/src/test/kotlin/io/bazel/kotlin/BUILD @@ -1,4 +1,4 @@ -load("//kotlin:kotlin.bzl", "kt_jvm_library") +load("//kotlin:jvm.bzl", "kt_jvm_library") load(":defs.bzl", "kt_rules_e2e_test") # Copyright 2018 The Bazel Authors. All rights reserved. diff --git a/src/test/kotlin/io/bazel/kotlin/builder/utils/BUILD.bazel b/src/test/kotlin/io/bazel/kotlin/builder/utils/BUILD.bazel index 9d716d33e..9e374d685 100644 --- a/src/test/kotlin/io/bazel/kotlin/builder/utils/BUILD.bazel +++ b/src/test/kotlin/io/bazel/kotlin/builder/utils/BUILD.bazel @@ -1,5 +1,5 @@ load("//src/test/kotlin/io/bazel/kotlin:defs.bzl", "kt_rules_test") -load("//kotlin:kotlin.bzl", "kt_jvm_test") +load("//kotlin:jvm.bzl", "kt_jvm_test") # Copyright 2020 The Bazel Authors. All rights reserved. # diff --git a/src/test/kotlin/io/bazel/kotlin/defs.bzl b/src/test/kotlin/io/bazel/kotlin/defs.bzl index 46739e5de..f5a4bdb24 100644 --- a/src/test/kotlin/io/bazel/kotlin/defs.bzl +++ b/src/test/kotlin/io/bazel/kotlin/defs.bzl @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. load("@rules_java//java:defs.bzl", "java_test") -load("//kotlin:kotlin.bzl", "kt_jvm_test") +load("//kotlin:jvm.bzl", "kt_jvm_test") def _get_class_name(kwargs): if len(kwargs.get("srcs", [])) == 1: diff --git a/src/test/kotlin/io/bazel/worker/BUILD.bazel b/src/test/kotlin/io/bazel/worker/BUILD.bazel index 96471b75a..75a8b0e77 100644 --- a/src/test/kotlin/io/bazel/worker/BUILD.bazel +++ b/src/test/kotlin/io/bazel/worker/BUILD.bazel @@ -1,4 +1,4 @@ -load("//kotlin:kotlin.bzl", "kt_jvm_library", "kt_jvm_test") +load("//kotlin:jvm.bzl", "kt_jvm_library", "kt_jvm_test") load("@rules_jvm_external//:defs.bzl", "artifact") kt_jvm_test(