From 710ba186995d6be9a13ebf0b783d21d96655c4d8 Mon Sep 17 00:00:00 2001 From: Corbin Smith Date: Wed, 5 Feb 2020 12:28:39 -0800 Subject: [PATCH] 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 --- BUILD | 17 ++ WORKSPACE | 10 ++ examples/dagger/BUILD | 1 + examples/node/BUILD | 6 +- examples/node/coroutines-helloworld/BUILD | 4 +- examples/node/express/BUILD | 8 +- examples/node/express/auth/BUILD | 2 +- kotlin/BUILD | 9 ++ kotlin/internal/BUILD | 2 +- kotlin/internal/js/BUILD | 18 +++ kotlin/internal/js/impl.bzl | 1 + kotlin/internal/jvm/android.bzl | 6 +- kotlin/internal/jvm/compile.bzl | 2 +- kotlin/internal/repositories/BUILD | 6 + .../BUILD.com_github_jetbrains_kotlin | 1 - kotlin/internal/repositories/repositories.bzl | 5 - kotlin/internal/toolchains.bzl | 2 +- kotlin/internal/utils/BUILD | 6 + kotlin/internal/utils/packager.bzl | 151 ++++++++++++++++++ src/main/kotlin/BUILD | 44 ++++- src/main/protobuf/BUILD | 1 + src/test/data/jvm/kapt/BUILD | 2 +- third_party/BUILD | 4 +- 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 + trace.profile.gz | Bin 1513 -> 0 bytes 56 files changed, 311 insertions(+), 29 deletions(-) create mode 100644 kotlin/internal/utils/packager.bzl delete mode 100644 trace.profile.gz diff --git a/BUILD b/BUILD index 788b39094..ef5d666ea 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,18 @@ test_suite( "//src/test/kotlin/io/bazel/kotlin:local_assertion_tests", ], ) + +# Release target. +release_archive( + name = "rules_kotlin_release", + dist_files = { + "BUILD": "", + "WORKSPACE": """workspace(name = "io_bazel_rules_kotlin")""", + }, + extension = "tgz", + deps = [ + "//kotlin:pkg", + "//src/main/kotlin:pkg", + "//third_party:pkg", + ], +) 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/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/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/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 898c66dc1..3b664deec 100644 --- a/kotlin/internal/BUILD +++ b/kotlin/internal/BUILD @@ -15,4 +15,4 @@ load("//kotlin/internal:toolchains.bzl", "kt_configure_toolchains") # Configures the toolchains -kt_configure_toolchains() \ No newline at end of file +kt_configure_toolchains() diff --git a/kotlin/internal/js/BUILD b/kotlin/internal/js/BUILD index 9f0a0ece3..29e4c981d 100644 --- a/kotlin/internal/js/BUILD +++ b/kotlin/internal/js/BUILD @@ -11,9 +11,27 @@ # 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", + ]), + dist_files = { + "BUILD": """ +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/android.bzl b/kotlin/internal/jvm/android.bzl index 0bfe31a3f..a1fdcfc17 100644 --- a/kotlin/internal/jvm/android.bzl +++ b/kotlin/internal/jvm/android.bzl @@ -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/repositories/BUILD b/kotlin/internal/repositories/BUILD index 9c0f139ef..533dbd785 100644 --- a/kotlin/internal/repositories/BUILD +++ b/kotlin/internal/repositories/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(["*.*"]) + ["BUILD"], +) 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/repositories.bzl b/kotlin/internal/repositories/repositories.bzl index e2831bddf..f2feffe13 100644 --- a/kotlin/internal/repositories/repositories.bzl +++ b/kotlin/internal/repositories/repositories.bzl @@ -23,10 +23,6 @@ load( "//kotlin/internal:defs.bzl", _KT_COMPILER_REPO = "KT_COMPILER_REPO", ) -load( - "//third_party/jvm:workspace.bzl", - _maven_dependencies = "maven_dependencies", -) _BAZEL_JAVA_LAUNCHER_VERSION = "0.28.1" @@ -62,7 +58,6 @@ def kotlin_repositories(compiler_release = _KOTLIN_CURRENT_COMPILER_RELEASE): 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"], diff --git a/kotlin/internal/toolchains.bzl b/kotlin/internal/toolchains.bzl index 3ff94ff9d..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", 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..7e46c4cc7 --- /dev/null +++ b/kotlin/internal/utils/packager.bzl @@ -0,0 +1,151 @@ +# 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, dist_files = {}, srcs = None, renames = {}, **kwargs): + """ + Creates an tar of the srcs, dist_files, and renamed label artifacts. + + Usage: + + //:BUILD + load("//kotlin/internal/utils:packager.bzl", "release_archive") + release_archive( + name = "release_archive", + dist_files = { + "BUILD": "", + "WORKSPACE": "workspace(name = "io_bazel_rules_kotlin")", + }, + extension = "tgz", + 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, renames, and dist_files under. Defaults to the current directory. + dist_files: dict of : for files to be generated in the distribution artifact. + renames: dict of