Skip to content

Commit

Permalink
Introduce release_archive for packaging the Kotlin rules.
Browse files Browse the repository at this point in the history
Added //:rules_kotlin_release to build a release.

Issue: #269 (comment)
  • Loading branch information
Corbin Smith committed Feb 5, 2020
1 parent 7d99a44 commit 710ba18
Show file tree
Hide file tree
Showing 56 changed files with 311 additions and 29 deletions.
17 changes: 17 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
],
)
10 changes: 10 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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",
)
1 change: 1 addition & 0 deletions examples/dagger/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions examples/node/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ 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__"],
)

kt_js_import(
name = "kotlinx-atomicfu",
jars = [
"@maven//:org_jetbrains_kotlinx_atomicfu_js"
"@maven//:org_jetbrains_kotlinx_atomicfu_js",
],
visibility = ["//:__subpackages__"],
)
4 changes: 2 additions & 2 deletions examples/node/coroutines-helloworld/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
8 changes: 4 additions & 4 deletions examples/node/express/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ 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",
],
)

# 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",
)
2 changes: 1 addition & 1 deletion examples/node/express/auth/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
9 changes: 9 additions & 0 deletions kotlin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
2 changes: 1 addition & 1 deletion kotlin/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
load("//kotlin/internal:toolchains.bzl", "kt_configure_toolchains")

# Configures the toolchains
kt_configure_toolchains()
kt_configure_toolchains()
18 changes: 18 additions & 0 deletions kotlin/internal/js/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)""",
},
)
1 change: 1 addition & 0 deletions kotlin/internal/js/impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions kotlin/internal/jvm/android.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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),
)
2 changes: 1 addition & 1 deletion kotlin/internal/jvm/compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
)

Expand Down
6 changes: 6 additions & 0 deletions kotlin/internal/repositories/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ filegroup(
srcs = glob(["**"]),
)


kt_jvm_import(
name = "annotations",
jar = "lib/annotations-13.0.jar",
Expand Down
5 changes: 0 additions & 5 deletions kotlin/internal/repositories/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"],
Expand Down
2 changes: 1 addition & 1 deletion kotlin/internal/toolchains.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions kotlin/internal/utils/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
Loading

0 comments on commit 710ba18

Please sign in to comment.