Skip to content

Commit

Permalink
Release the Kotlin rules in a simplified workspace relying on precomp…
Browse files Browse the repository at this point in the history
…iled jars. (bazelbuild#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: bazelbuild#269 (comment)

* Introduce release_archive for packaging the Kotlin rules.

Added //:rules_kotlin_release to build a release.

Issue: bazelbuild#269 (comment)

* Move maven repo back to kotlin_repos
Make examples use the release repository

Issue: bazelbuild#269 (comment)

* Move maven repo back to kotlin_repos
Make examples use the release repository

Issue: bazelbuild#269 (comment)

* Move maven repo back to kotlin_repos
Make examples use the release repository
Make git ignore profiling artifacts

Issue: bazelbuild#269 (comment)

* 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.
  • Loading branch information
restingbull committed Feb 10, 2020
1 parent f447621 commit ae70089
Show file tree
Hide file tree
Showing 71 changed files with 529 additions and 81 deletions.
20 changes: 18 additions & 2 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
- "--"
Expand All @@ -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
Expand All @@ -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/...
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
**/.ijwb
**/.aswb
**/.vscode
trace.profile.gz
16 changes: 16 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,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",
],
)
13 changes: 13 additions & 0 deletions BUILD.release.bazel
Original file line number Diff line number Diff line change
@@ -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.
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",
)
14 changes: 14 additions & 0 deletions WORKSPACE.release.bazel
Original file line number Diff line number Diff line change
@@ -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")
7 changes: 7 additions & 0 deletions examples/android/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
)
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__"],
)
6 changes: 6 additions & 0 deletions examples/node/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
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"],
)
6 changes: 6 additions & 0 deletions examples/trivial/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
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",
],
)
34 changes: 17 additions & 17 deletions kotlin/internal/BUILD
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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",
],
)
17 changes: 17 additions & 0 deletions kotlin/internal/BUILD.release.bazel
Original file line number Diff line number Diff line change
@@ -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()
13 changes: 13 additions & 0 deletions kotlin/internal/js/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
)
19 changes: 19 additions & 0 deletions kotlin/internal/js/BUILD.release.bazel
Original file line number Diff line number Diff line change
@@ -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"],
)
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

0 comments on commit ae70089

Please sign in to comment.