From ae70089a2f672182d55ef8cd1bd97ec6d2370d6a Mon Sep 17 00:00:00 2001 From: Corbin McNeely-Smith <58151731+restingbull@users.noreply.github.com> Date: Mon, 10 Feb 2020 10:09:48 -0800 Subject: [PATCH] Release the Kotlin rules in a simplified workspace relying on precompiled jars. (#271) * Add work around for Intellij SrcJar bug: github.com/bazelbuild/intellij/issues/1616 * Move android_sdk to 3rd_party Move toolchain configuration to the toolchains.bzl Issue: https://github.com/bazelbuild/rules_kotlin/issues/269#issue-560510640 * Introduce release_archive for packaging the Kotlin rules. Added //:rules_kotlin_release to build a release. Issue: https://github.com/bazelbuild/rules_kotlin/issues/269#issue-560510640 * Move maven repo back to kotlin_repos Make examples use the release repository Issue: https://github.com/bazelbuild/rules_kotlin/issues/269#issue-560510640 * Move maven repo back to kotlin_repos Make examples use the release repository Issue: https://github.com/bazelbuild/rules_kotlin/issues/269#issue-560510640 * Move maven repo back to kotlin_repos Make examples use the release repository Make git ignore profiling artifacts Issue: https://github.com/bazelbuild/rules_kotlin/issues/269#issue-560510640 * Apply buildifier and update reflow_skylark script to run. * Removed extranous visibility. * Fixing merge errors in packager.bzl * build the release in the parent directory. * rename to retry presubmit * fix accidental target rename. --- .bazelci/presubmit.yml | 20 +++- .gitignore | 1 + BUILD | 16 +++ BUILD.release.bazel | 13 +++ WORKSPACE | 10 ++ WORKSPACE.release.bazel | 14 +++ examples/android/WORKSPACE | 7 ++ examples/dagger/BUILD | 1 + examples/node/BUILD | 6 +- examples/node/WORKSPACE | 6 + examples/node/coroutines-helloworld/BUILD | 4 +- examples/node/express/BUILD | 8 +- examples/node/express/auth/BUILD | 2 +- examples/trivial/WORKSPACE | 6 + kotlin/BUILD | 9 ++ kotlin/internal/BUILD | 34 +++--- kotlin/internal/BUILD.release.bazel | 17 +++ kotlin/internal/js/BUILD | 13 +++ kotlin/internal/js/BUILD.release.bazel | 19 ++++ kotlin/internal/js/impl.bzl | 1 + kotlin/internal/jvm/BUILD | 10 +- kotlin/internal/jvm/android.bzl | 8 +- kotlin/internal/jvm/compile.bzl | 2 +- kotlin/internal/jvm/jvm.bzl | 3 + kotlin/internal/repositories/BUILD | 12 ++ .../BUILD.com_github_jetbrains_kotlin | 1 - .../repositories/nomaven_repositories.bzl | 57 ++++++++++ kotlin/internal/repositories/repositories.bzl | 33 ++---- kotlin/internal/toolchains.bzl | 25 ++++- kotlin/internal/utils/BUILD | 6 + kotlin/internal/utils/packager.bzl | 105 ++++++++++++++++++ scripts/reflow_skylark | 12 +- src/main/kotlin/BUILD | 19 +++- src/main/kotlin/BUILD.release.bazel | 34 ++++++ src/main/protobuf/BUILD | 1 + src/test/data/jvm/kapt/BUILD | 2 +- third_party/BUILD | 19 +++- third_party/BUILD.release.bazel | 22 ++++ third_party/empty.jar | Bin 0 -> 22 bytes third_party/jvm/com/google/auto/BUILD | 1 + third_party/jvm/com/google/auto/service/BUILD | 1 + third_party/jvm/com/google/auto/value/BUILD | 1 + .../jvm/com/google/code/findbugs/BUILD | 1 + third_party/jvm/com/google/code/gson/BUILD | 1 + third_party/jvm/com/google/dagger/BUILD | 1 + third_party/jvm/com/google/errorprone/BUILD | 1 + .../jvm/com/google/googlejavaformat/BUILD | 1 + third_party/jvm/com/google/guava/BUILD | 1 + third_party/jvm/com/google/j2objc/BUILD | 1 + third_party/jvm/com/google/protobuf/BUILD | 1 + third_party/jvm/com/google/truth/BUILD | 1 + .../jvm/com/googlecode/java_diff_utils/BUILD | 1 + third_party/jvm/com/squareup/BUILD | 1 + third_party/jvm/javax/annotation/BUILD | 1 + third_party/jvm/javax/enterprise/BUILD | 1 + third_party/jvm/javax/inject/BUILD | 1 + third_party/jvm/junit/BUILD | 1 + third_party/jvm/net/ltgt/gradle/incap/BUILD | 1 + third_party/jvm/org/apache/ant/BUILD | 1 + third_party/jvm/org/apache/commons/BUILD | 1 + third_party/jvm/org/apache/maven/BUILD | 1 + third_party/jvm/org/checkerframework/BUILD | 1 + third_party/jvm/org/codehaus/mojo/BUILD | 1 + third_party/jvm/org/codehaus/plexus/BUILD | 1 + third_party/jvm/org/eclipse/sisu/BUILD | 1 + third_party/jvm/org/hamcrest/BUILD | 1 + third_party/jvm/org/jetbrains/BUILD | 1 + third_party/jvm/org/jetbrains/kotlin/BUILD | 1 + third_party/jvm/org/jetbrains/kotlinx/BUILD | 1 + third_party/jvm/org/ow2/asm/BUILD | 1 + third_party/jvm/org/pantsbuild/BUILD | 1 + 71 files changed, 529 insertions(+), 81 deletions(-) create mode 100644 BUILD.release.bazel create mode 100644 WORKSPACE.release.bazel create mode 100644 kotlin/internal/BUILD.release.bazel create mode 100644 kotlin/internal/js/BUILD.release.bazel create mode 100644 kotlin/internal/repositories/nomaven_repositories.bzl create mode 100644 kotlin/internal/utils/packager.bzl create mode 100644 src/main/kotlin/BUILD.release.bazel create mode 100644 third_party/BUILD.release.bazel create mode 100644 third_party/empty.jar diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 8027647d9..983580612 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -3,11 +3,15 @@ validate_config: 1 bazel: 1.1.0 tasks: ubuntu1604: + build_targets: + - "//:rules_kotlin_release" test_targets: - - "//:all_tests" + - "//:all_tests" ubuntu1804: test_targets: - - "//:all_tests" + - "//:all_tests" + build_targets: + - "//:rules_kotlin_release" rbe_ubuntu1604: test_targets: - "--" @@ -26,13 +30,21 @@ tasks: example-android: name: "Example - Android" platform: ubuntu1804 + shell_command: + - "cd .. && bazel build //:rules_kotlin_release_release && rm -rf /tmp/rules_kotlin_release && mkdir -p /tmp/rules_kotlin_release && tar -C /tmp/rules_kotlin_release -xvf bazel-bin/rules_kotlin_release_release.tgz" working_directory: examples/android + test_flags: + - "--override_repository=io_bazel_rules_kotlin_release=/tmp/rules_kotlin_release" test_targets: - //... examples-trivial: name: "Example - Trivial" platform: ubuntu1804 + shell_command: + - "cd .. && bazel build //:rules_kotlin_release_release && rm -rf /tmp/rules_kotlin_release && mkdir -p /tmp/rules_kotlin_release && tar -C /tmp/rules_kotlin_release -xvf bazel-bin/rules_kotlin_release_release.tgz" working_directory: examples/trivial + test_flags: + - "--override_repository=io_bazel_rules_kotlin_release=/tmp/rules_kotlin_release" include_json_profile: - build - test @@ -41,10 +53,14 @@ tasks: examples-nodejs: name: Example - Node platform: ubuntu1804 + shell_command: + - "cd bazel build //:rules_kotlin_release_release && rm -rf /tmp/rules_kotlin_release && mkdir -p /tmp/rules_kotlin_release && tar -C /tmp/rules_kotlin_release -xvf bazel-bin/rules_kotlin_release_release.tgz" working_directory: examples/node include_json_profile: - build - test + test_flags: + - "--override_repository=io_bazel_rules_kotlin_release=/tmp/rules_kotlin_release" build_targets: - //coroutines-helloworld/... - //express/... diff --git a/.gitignore b/.gitignore index 4d524fcf8..b85e86ae0 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ **/.ijwb **/.aswb **/.vscode +trace.profile.gz diff --git a/BUILD b/BUILD index 788b39094..ec516d214 100644 --- a/BUILD +++ b/BUILD @@ -11,6 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +load("//kotlin/internal/utils:packager.bzl", "release_archive") +load("//kotlin/internal/utils:utils.bzl", "utils") exports_files([ "scripts/noop.sh", @@ -33,3 +35,17 @@ test_suite( "//src/test/kotlin/io/bazel/kotlin:local_assertion_tests", ], ) + +# Release target. +release_archive( + name = "rules_kotlin_release", + src_map = { + "BUILD.release.bazel": "BUILD.bazel", + "WORKSPACE.release.bazel": "WORKSPACE", + }, + deps = [ + "//kotlin:pkg", + "//src/main/kotlin:pkg", + "//third_party:pkg", + ], +) diff --git a/BUILD.release.bazel b/BUILD.release.bazel new file mode 100644 index 000000000..cdd15e464 --- /dev/null +++ b/BUILD.release.bazel @@ -0,0 +1,13 @@ +# 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. diff --git a/WORKSPACE b/WORKSPACE index 6c2de90dd..4c0af828e 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -80,6 +80,11 @@ rbe_autoconfig( name = "buildkite_config", ) +load( + "//third_party/jvm:workspace.bzl", "maven_dependencies", +) + +maven_dependencies() load("//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains") kotlin_repositories() @@ -126,3 +131,8 @@ maven_install( ], ) +http_archive( + name = "rules_pkg", + url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz", + sha256 = "4ba8f4ab0ff85f2484287ab06c0d871dcb31cc54d439457d28fd4ae14b18450a", +) \ No newline at end of file diff --git a/WORKSPACE.release.bazel b/WORKSPACE.release.bazel new file mode 100644 index 000000000..093556198 --- /dev/null +++ b/WORKSPACE.release.bazel @@ -0,0 +1,14 @@ +# Copyright 2018 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +workspace(name = "io_bazel_rules_kotlin") \ No newline at end of file diff --git a/examples/android/WORKSPACE b/examples/android/WORKSPACE index 501407efe..f701c3868 100644 --- a/examples/android/WORKSPACE +++ b/examples/android/WORKSPACE @@ -58,6 +58,7 @@ kotlin_repositories() kt_register_toolchains() + # Skylib, for build_test, so don't bother initializing the unit test infrastructure. http_archive( name = "bazel_skylib", @@ -66,3 +67,9 @@ http_archive( "https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", ], ) + +http_archive( + name = "rules_pkg", + url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz", + sha256 = "4ba8f4ab0ff85f2484287ab06c0d871dcb31cc54d439457d28fd4ae14b18450a", +) \ No newline at end of file diff --git a/examples/dagger/BUILD b/examples/dagger/BUILD index ef4a9706e..2e1ab62b7 100644 --- a/examples/dagger/BUILD +++ b/examples/dagger/BUILD @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. load("@rules_java//java:defs.bzl", "java_binary", "java_library", "java_plugin") + package(default_visibility = ["//visibility:private"]) load("//kotlin:kotlin.bzl", "kt_jvm_library") diff --git a/examples/node/BUILD b/examples/node/BUILD index e5e7a6b38..8d687591a 100644 --- a/examples/node/BUILD +++ b/examples/node/BUILD @@ -15,14 +15,14 @@ load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_js_import") # Create kt_js_imports for KotlinX's Coroutines and Atomicfu libraries. # -# These could be imported using package.json and NPM, but they are here as an example of how to +# These could be imported using package.json and NPM, but they are here as an example of how to # use KotlinJS libraries hosted on Maven directly. # # Note: It's important that the `name`s correspond to the base name of the library only (ie. not-ending with -js/_js) kt_js_import( name = "kotlinx-coroutines-core", jars = [ - "@maven//:org_jetbrains_kotlinx_kotlinx_coroutines_core_js" + "@maven//:org_jetbrains_kotlinx_kotlinx_coroutines_core_js", ], visibility = ["//:__subpackages__"], ) @@ -30,7 +30,7 @@ kt_js_import( kt_js_import( name = "kotlinx-atomicfu", jars = [ - "@maven//:org_jetbrains_kotlinx_atomicfu_js" + "@maven//:org_jetbrains_kotlinx_atomicfu_js", ], visibility = ["//:__subpackages__"], ) diff --git a/examples/node/WORKSPACE b/examples/node/WORKSPACE index 2e614d43f..c04a1fcee 100644 --- a/examples/node/WORKSPACE +++ b/examples/node/WORKSPACE @@ -47,3 +47,9 @@ maven_install( "https://repo1.maven.org/maven2", ], ) + +http_archive( + name = "rules_pkg", + url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz", + sha256 = "4ba8f4ab0ff85f2484287ab06c0d871dcb31cc54d439457d28fd4ae14b18450a", +) \ No newline at end of file diff --git a/examples/node/coroutines-helloworld/BUILD b/examples/node/coroutines-helloworld/BUILD index c299d47f5..9ab9cdef0 100644 --- a/examples/node/coroutines-helloworld/BUILD +++ b/examples/node/coroutines-helloworld/BUILD @@ -17,16 +17,16 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") kt_js_library( name = "app", srcs = ["Main.kt"], + visibility = ["//visibility:public"], deps = [ "//:kotlinx-coroutines-core", ], - visibility = ["//visibility:public"], ) nodejs_binary( name = "coroutines-helloworld", - node_modules = "@node_ws//:node_modules", data = [":app"], entry_point = ":app.js", + node_modules = "@node_ws//:node_modules", visibility = ["//visibility:public"], ) diff --git a/examples/node/express/BUILD b/examples/node/express/BUILD index 864cabe2a..84c736630 100644 --- a/examples/node/express/BUILD +++ b/examples/node/express/BUILD @@ -20,17 +20,17 @@ kt_js_library( name = "acme-routes", srcs = [":Routes.kt"], deps = [ - "//express/auth:acme-auth", "//:kotlinx-atomicfu", "//:kotlinx-coroutines-core", + "//express/auth:acme-auth", ], ) kt_js_library( - name ="app", + name = "app", srcs = [":App.kt"], deps = [ - ":acme-routes", + ":acme-routes", "//:kotlinx-coroutines-core", ], ) @@ -38,7 +38,7 @@ kt_js_library( # The binary demonstrates an express app composed of three modules. The modules can co-exist in the same directory. nodejs_binary( name = "express", - node_modules = "@node_ws//:node_modules", data = [":app"], entry_point = ":app.js", + node_modules = "@node_ws//:node_modules", ) diff --git a/examples/node/express/auth/BUILD b/examples/node/express/auth/BUILD index 835e9d686..f3fdf7cce 100644 --- a/examples/node/express/auth/BUILD +++ b/examples/node/express/auth/BUILD @@ -16,5 +16,5 @@ load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_js_library") kt_js_library( name = "acme-auth", srcs = ["Auth.kt"], - visibility=["//visibility:public"] + visibility = ["//visibility:public"], ) diff --git a/examples/trivial/WORKSPACE b/examples/trivial/WORKSPACE index 43c484161..5c575e7eb 100644 --- a/examples/trivial/WORKSPACE +++ b/examples/trivial/WORKSPACE @@ -42,3 +42,9 @@ maven_install( "https://repo1.maven.org/maven2", ], ) + +http_archive( + name = "rules_pkg", + url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz", + sha256 = "4ba8f4ab0ff85f2484287ab06c0d871dcb31cc54d439457d28fd4ae14b18450a", +) diff --git a/kotlin/BUILD b/kotlin/BUILD index 9c0f139ef..58f2cc6e7 100644 --- a/kotlin/BUILD +++ b/kotlin/BUILD @@ -11,3 +11,12 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +load("//kotlin/internal/utils:packager.bzl", "release_archive") + +release_archive( + name = "pkg", + srcs = glob(["*.*"]) + ["BUILD"], + deps = [ + "//kotlin/internal:pkg", + ], +) diff --git a/kotlin/internal/BUILD b/kotlin/internal/BUILD index 6a985b1a2..19457111b 100644 --- a/kotlin/internal/BUILD +++ b/kotlin/internal/BUILD @@ -1,4 +1,4 @@ -# Copyright 2018 The Bazel Authors. All rights reserved. +# 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. @@ -11,23 +11,23 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -load("//kotlin/internal:toolchains.bzl", "define_kt_toolchain") -config_setting( - name = "builder_debug_timings", - values = {"define": "kt_timings=1"}, -) - -config_setting( - name = "builder_debug_trace", - values = {"define": "kt_trace=1"}, -) +load("//kotlin/internal:toolchains.bzl", "kt_configure_toolchains") +load("//kotlin/internal/utils:packager.bzl", "release_archive") -toolchain_type( - name = "kt_toolchain_type", - visibility = ["//visibility:public"], -) +# Configures the toolchains +kt_configure_toolchains() -define_kt_toolchain( - name = "default_toolchain", +release_archive( + name = "pkg", + srcs = glob(["*.bzl"]), + src_map = { + "BUILD.release.bazel": "BUILD.bazel", + }, + deps = [ + "//kotlin/internal/js:pkg", + "//kotlin/internal/jvm:pkg", + "//kotlin/internal/repositories:pkg", + "//kotlin/internal/utils:pkg", + ], ) diff --git a/kotlin/internal/BUILD.release.bazel b/kotlin/internal/BUILD.release.bazel new file mode 100644 index 000000000..d03419764 --- /dev/null +++ b/kotlin/internal/BUILD.release.bazel @@ -0,0 +1,17 @@ +# 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. + +load("//kotlin/internal:toolchains.bzl", "kt_configure_toolchains") + +kt_configure_toolchains() diff --git a/kotlin/internal/js/BUILD b/kotlin/internal/js/BUILD index 9f0a0ece3..9a6ff0ce1 100644 --- a/kotlin/internal/js/BUILD +++ b/kotlin/internal/js/BUILD @@ -11,9 +11,22 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +load("//kotlin/internal/utils:packager.bzl", "release_archive") +# TODO(https://github.com/bazelbuild/rules_kotlin/issues/270): Replace with Starlark py_binary( name = "importer", srcs = ["importer.py"], visibility = ["//visibility:public"], ) + +release_archive( + name = "pkg", + srcs = glob([ + "*.bzl", + "*.py", + ]), + src_map = { + "BUILD.release.bazel": "BUILD.bazel", + }, +) diff --git a/kotlin/internal/js/BUILD.release.bazel b/kotlin/internal/js/BUILD.release.bazel new file mode 100644 index 000000000..9f0a0ece3 --- /dev/null +++ b/kotlin/internal/js/BUILD.release.bazel @@ -0,0 +1,19 @@ +# Copyright 2018 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +py_binary( + name = "importer", + srcs = ["importer.py"], + visibility = ["//visibility:public"], +) diff --git a/kotlin/internal/js/impl.bzl b/kotlin/internal/js/impl.bzl index 92f3861ff..c596f70ac 100644 --- a/kotlin/internal/js/impl.bzl +++ b/kotlin/internal/js/impl.bzl @@ -111,6 +111,7 @@ def _strip_version(jarfile): if not jarfile.endswith(".jar"): fail("_strip_version expects paths ending with .jar") segments = jarfile[:-len(".jar")].split("-") + # Remove the last segment if all digits separated by dot parts = segments[-1].split(".") if len([p for p in parts if not p.isdigit()]) == 0: diff --git a/kotlin/internal/jvm/BUILD b/kotlin/internal/jvm/BUILD index 7027aa091..18f7d7765 100644 --- a/kotlin/internal/jvm/BUILD +++ b/kotlin/internal/jvm/BUILD @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -java_import( - name = "android_sdk", - jars = ["@bazel_tools//tools/android:android_jar"], - neverlink = 1, - visibility = ["//visibility:public"], +load("//kotlin/internal/utils:packager.bzl", "release_archive") + +release_archive( + name = "pkg", + srcs = glob(["*.bzl"]) + ["BUILD"], ) diff --git a/kotlin/internal/jvm/android.bzl b/kotlin/internal/jvm/android.bzl index a09dede2c..a1fdcfc17 100644 --- a/kotlin/internal/jvm/android.bzl +++ b/kotlin/internal/jvm/android.bzl @@ -23,7 +23,7 @@ def _kt_android_artifact(name, srcs = [], deps = [], plugins = [], **kwargs): base_name = name + "_base" kt_name = name + "_kt" - base_deps = deps + ["@io_bazel_rules_kotlin//kotlin/internal/jvm:android_sdk"] + base_deps = deps + ["@io_bazel_rules_kotlin//third_party:android_sdk"] native.android_library( name = base_name, @@ -36,7 +36,7 @@ def _kt_android_artifact(name, srcs = [], deps = [], plugins = [], **kwargs): srcs = srcs, deps = base_deps + [base_name], plugins = plugins, - testonly = kwargs.get("testonly", default=0), + testonly = kwargs.get("testonly", default = 0), visibility = ["//visibility:private"], ) return [base_name, kt_name] @@ -49,6 +49,6 @@ def kt_android_library(name, exports = [], visibility = None, **kwargs): name = name, exports = exports + _kt_android_artifact(name, **kwargs), visibility = visibility, - tags = kwargs.get("tags", default=None), - testonly = kwargs.get("testonly", default=0), + tags = kwargs.get("tags", default = None), + testonly = kwargs.get("testonly", default = 0), ) diff --git a/kotlin/internal/jvm/compile.bzl b/kotlin/internal/jvm/compile.bzl index 922c00718..bc94db1bf 100644 --- a/kotlin/internal/jvm/compile.bzl +++ b/kotlin/internal/jvm/compile.bzl @@ -232,7 +232,7 @@ def kt_jvm_compile_action(ctx, rule_kind, output_jar): progress_message = progress_message, input_manifests = input_manifests, env = { - "LC_CTYPE": "en_US.UTF-8" # For Java source files + "LC_CTYPE": "en_US.UTF-8", # For Java source files }, ) diff --git a/kotlin/internal/jvm/jvm.bzl b/kotlin/internal/jvm/jvm.bzl index aa1d0925d..deee1cdc7 100644 --- a/kotlin/internal/jvm/jvm.bzl +++ b/kotlin/internal/jvm/jvm.bzl @@ -336,6 +336,9 @@ kt_jvm_import = rule( doc = """The sources for the class jar.""", allow_single_file = True, cfg = "target", + # TODO(https://github.com/bazelbuild/intellij/issues/1616): Remove when the Intellij Aspect has the + # correct null checks. + default = "@io_bazel_rules_kotlin//third_party:empty.jar", ), "runtime_deps": attr.label_list( doc = """Additional runtime deps.""", diff --git a/kotlin/internal/repositories/BUILD b/kotlin/internal/repositories/BUILD index 9c0f139ef..36fec980f 100644 --- a/kotlin/internal/repositories/BUILD +++ b/kotlin/internal/repositories/BUILD @@ -11,3 +11,15 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +load("//kotlin/internal/utils:packager.bzl", "release_archive") + +release_archive( + name = "pkg", + srcs = [ + "BUILD", + "BUILD.com_github_jetbrains_kotlin", + ], + src_map = { + "nomaven_repositories.bzl": "repositories.bzl", + }, +) diff --git a/kotlin/internal/repositories/BUILD.com_github_jetbrains_kotlin b/kotlin/internal/repositories/BUILD.com_github_jetbrains_kotlin index 6beafa46d..31ca05885 100644 --- a/kotlin/internal/repositories/BUILD.com_github_jetbrains_kotlin +++ b/kotlin/internal/repositories/BUILD.com_github_jetbrains_kotlin @@ -22,7 +22,6 @@ filegroup( srcs = glob(["**"]), ) - kt_jvm_import( name = "annotations", jar = "lib/annotations-13.0.jar", diff --git a/kotlin/internal/repositories/nomaven_repositories.bzl b/kotlin/internal/repositories/nomaven_repositories.bzl new file mode 100644 index 000000000..0232c85dc --- /dev/null +++ b/kotlin/internal/repositories/nomaven_repositories.bzl @@ -0,0 +1,57 @@ +# Copyright 2018 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""This file contains the Kotlin compiler repository definitions. It should not be loaded directly by client workspaces. +""" + +load( + "//kotlin/internal:defs.bzl", + _KT_COMPILER_REPO = "KT_COMPILER_REPO", +) +load( + "@bazel_tools//tools/build_defs/repo:http.bzl", + _http_archive = "http_archive", + _http_file = "http_file", +) + +BAZEL_JAVA_LAUNCHER_VERSION = "0.28.1" + +KOTLIN_CURRENT_COMPILER_RELEASE = { + "urls": [ + "https://github.com/JetBrains/kotlin/releases/download/v1.3.50/kotlin-compiler-1.3.50.zip", + ], + "sha256": "69424091a6b7f52d93eed8bba2ace921b02b113dbb71388d704f8180a6bdc6ec", +} + +def kotlin_repositories(compiler_release = KOTLIN_CURRENT_COMPILER_RELEASE): + """Call this in the WORKSPACE file to setup the Kotlin rules. + + Args: + compiler_release: (internal) dict containing "urls" and "sha256" for the Kotlin compiler. + """ + _http_archive( + name = _KT_COMPILER_REPO, + urls = compiler_release["urls"], + sha256 = compiler_release["sha256"], + build_file = "@io_bazel_rules_kotlin//kotlin/internal/repositories:BUILD.com_github_jetbrains_kotlin", + strip_prefix = "kotlinc", + ) + + _http_file( + name = "kt_java_stub_template", + urls = [("https://raw.githubusercontent.com/bazelbuild/bazel/" + + BAZEL_JAVA_LAUNCHER_VERSION + + "/src/main/java/com/google/devtools/build/lib/bazel/rules/java/" + + "java_stub_template.txt")], + sha256 = "e6531a6539ec1e38fec5e20523ff4bfc883e1cc0209eb658fe82eb918eb49657", + ) diff --git a/kotlin/internal/repositories/repositories.bzl b/kotlin/internal/repositories/repositories.bzl index e2831bddf..2aec6e04c 100644 --- a/kotlin/internal/repositories/repositories.bzl +++ b/kotlin/internal/repositories/repositories.bzl @@ -27,15 +27,11 @@ load( "//third_party/jvm:workspace.bzl", _maven_dependencies = "maven_dependencies", ) - -_BAZEL_JAVA_LAUNCHER_VERSION = "0.28.1" - -_KOTLIN_CURRENT_COMPILER_RELEASE = { - "urls": [ - "https://github.com/JetBrains/kotlin/releases/download/v1.3.50/kotlin-compiler-1.3.50.zip", - ], - "sha256": "69424091a6b7f52d93eed8bba2ace921b02b113dbb71388d704f8180a6bdc6ec", -} +load( + "//kotlin/internal/repositories:nomaven_repositories.bzl", + "KOTLIN_CURRENT_COMPILER_RELEASE", + _kotlin_repositories_no_maven = "kotlin_repositories", +) def github_archive(name, repo, commit, build_file_content = None, sha256 = None): if build_file_content: @@ -56,26 +52,11 @@ def github_archive(name, repo, commit, build_file_content = None, sha256 = None) sha256 = sha256, ) -def kotlin_repositories(compiler_release = _KOTLIN_CURRENT_COMPILER_RELEASE): +def kotlin_repositories(compiler_release = KOTLIN_CURRENT_COMPILER_RELEASE): """Call this in the WORKSPACE file to setup the Kotlin rules. Args: compiler_release: (internal) dict containing "urls" and "sha256" for the Kotlin compiler. """ _maven_dependencies() - _http_archive( - name = _KT_COMPILER_REPO, - urls = compiler_release["urls"], - sha256 = compiler_release["sha256"], - build_file = "@io_bazel_rules_kotlin//kotlin/internal/repositories:BUILD.com_github_jetbrains_kotlin", - strip_prefix = "kotlinc", - ) - - _http_file( - name = "kt_java_stub_template", - urls = [("https://raw.githubusercontent.com/bazelbuild/bazel/" + - _BAZEL_JAVA_LAUNCHER_VERSION + - "/src/main/java/com/google/devtools/build/lib/bazel/rules/java/" + - "java_stub_template.txt")], - sha256 = "e6531a6539ec1e38fec5e20523ff4bfc883e1cc0209eb658fe82eb918eb49657", - ) + _kotlin_repositories_no_maven(compiler_release) diff --git a/kotlin/internal/toolchains.bzl b/kotlin/internal/toolchains.bzl index 20601a7f9..d82e73b54 100644 --- a/kotlin/internal/toolchains.bzl +++ b/kotlin/internal/toolchains.bzl @@ -117,7 +117,7 @@ _kt_toolchain = rule( "jvm_runtime": attr.label_list( doc = "The implicit jvm runtime libraries. This is internal.", default = [ - Label("@" + _KT_COMPILER_REPO + "//:kotlin-stdlib") + Label("@" + _KT_COMPILER_REPO + "//:kotlin-stdlib"), ], providers = [JavaInfo], cfg = "target", @@ -195,3 +195,26 @@ def define_kt_toolchain( toolchain = impl_name, visibility = ["//visibility:public"], ) + +def kt_configure_toolchains(): + """ + Defines the toolchain_type and default toolchain for kotlin compilation. + """ + native.config_setting( + name = "builder_debug_timings", + values = {"define": "kt_timings=1"}, + ) + + native.config_setting( + name = "builder_debug_trace", + values = {"define": "kt_trace=1"}, + ) + + native.toolchain_type( + name = "kt_toolchain_type", + visibility = ["//visibility:public"], + ) + + define_kt_toolchain( + name = "default_toolchain", + ) diff --git a/kotlin/internal/utils/BUILD b/kotlin/internal/utils/BUILD index 9c0f139ef..920f21549 100644 --- a/kotlin/internal/utils/BUILD +++ b/kotlin/internal/utils/BUILD @@ -11,3 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +load("//kotlin/internal/utils:packager.bzl", "release_archive") + +release_archive( + name = "pkg", + srcs = glob(["*.bzl"]) + ["BUILD"], +) diff --git a/kotlin/internal/utils/packager.bzl b/kotlin/internal/utils/packager.bzl new file mode 100644 index 000000000..7ba9176ea --- /dev/null +++ b/kotlin/internal/utils/packager.bzl @@ -0,0 +1,105 @@ +# 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. + +load("@rules_pkg//:pkg.bzl", "pkg_tar") + +def release_archive(name, srcs = None, src_map = {}, package_dir = None, extension = "tgz", deps = None): + """ + Creates an tar of the srcs, and renamed label artifacts. + + Usage: + + //:BUILD + load("//kotlin/internal/utils:packager.bzl", "release_archive") + release_archive( + name = "release_archive", + src_map = { + "BUILD.release.bazel.bazel": "BUILD.bazel", + "WORKSPACE.release.bazel": "WORKSPACE", + }, + deps = [ + "//dep:pkg" + ], + ) + + //dep:BUILD + load("//kotlin/internal/utils:packager.bzl", "release_archive") + release_archive( + name = "pkg", + srcs = [ + ":label_of_artifact", + ], + ) + + + Args: + name: target identifier, points to a pkg_tar target. + package_dir: directory to place the srcs, src_map, and dist_files under. Defaults to the current directory. + dist_files: dict of : for files to be generated in the distribution artifact. + src_map: dict of