Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Kotlin 1.3 in the rules_kotlin. #7

Merged
merged 3 commits into from
Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/dagger/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ kt_jvm_library(
],
deps = [
":dagger_lib",
"//third_party:kotlinx_coroutines",
"//third_party/jvm/org/jetbrains/kotlinx:kotlinx_coroutines_core",
],
)

Expand Down
4 changes: 2 additions & 2 deletions examples/dagger/src/coffee/CoffeeApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package coffee

import dagger.Component
import kotlinx.coroutines.experimental.runBlocking
import kotlinx.coroutines.runBlocking
import javax.inject.Singleton
import tea.TeaPot

Expand All @@ -30,7 +30,7 @@ class CoffeeApp {
companion object {
@JvmStatic
fun main(args: Array<String>) {
if(TeaPot.isEmpty()) {
if (TeaPot.isEmpty()) {
val coffeeShop = DaggerCoffeeApp_CoffeeShop.builder().build()
runBlocking {
coffeeShop.maker().brew()
Expand Down
6 changes: 3 additions & 3 deletions examples/dagger/src/coffee/CoffeeMaker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package coffee

import dagger.Lazy
import kotlinx.coroutines.experimental.DefaultDispatcher
import kotlinx.coroutines.experimental.withContext
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import javax.inject.Inject

class CoffeeMaker @Inject internal constructor(
Expand All @@ -28,7 +28,7 @@ class CoffeeMaker @Inject internal constructor(

suspend fun brew() {
// this function is async to verify intellij support for coroutines.
withContext(DefaultDispatcher) {
withContext(Dispatchers.Default) {
heater.get().on()
pump.pump()
println(" [_]P coffee! [_]P ")
Expand Down
8 changes: 4 additions & 4 deletions kotlin/internal/jvm/jvm.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ _implicit_deps = {
"_toolchain": attr.label(
doc = """The Kotlin JVM Runtime. it's only purpose is to enable the Android native rules to discover the Kotlin
runtime for dexing""",
default = Label("@" + _KT_COMPILER_REPO + "//:kotlin-runtime"),
default = Label("@" + _KT_COMPILER_REPO + "//:kotlin-stdlib"),
cfg = "target",
),
}
Expand Down Expand Up @@ -311,9 +311,9 @@ kt_jvm_import = rule(

# Import a single kotlin jar.
kt_jvm_import(
name = "kotlin-runtime",
jars = ["lib/kotlin-runtime.jar"],
srcjar = "lib/kotlin-runtime-sources.jar"
name = "kotlin-stdlib",
jars = ["lib/kotlin-stdlib.jar"],
srcjar = "lib/kotlin-stdlib-sources.jar"
)
```
""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ filegroup(
srcs = glob(["**"]),
)


kt_jvm_import(
name = "annotations",
jars = ["lib/annotations-13.0.jar"],
neverlink = 1,
)

# Kotlin dependencies that are internal to this repo and are meant to be loaded manually into a classloader.
[
kt_jvm_import(
Expand Down Expand Up @@ -55,7 +62,6 @@ filegroup(
visibility = ["//visibility:public"],
)
for art in [
"runtime",
"stdlib",
"stdlib-jdk7",
"stdlib-jdk8",
Expand Down
4 changes: 2 additions & 2 deletions kotlin/internal/repositories/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ _BAZEL_JAVA_LAUNCHER_VERSION = "0.8.1"

_KOTLIN_CURRENT_COMPILER_RELEASE = {
"urls": [
"https://github.com/JetBrains/kotlin/releases/download/v1.2.70/kotlin-compiler-1.2.70.zip",
"https://github.com/JetBrains/kotlin/releases/download/v1.3.21/kotlin-compiler-1.3.21.zip",
],
"sha256": "a23a40a3505e78563100b9e6cfd7f535fbf6593b69a5c470800fbafbeccf8434",
"sha256": "dbc7fbed67e0fa9a2f2ef6efd89fc1ef8d92daa38bb23c1f23914869084deb56",
}

def github_archive(name, repo, commit, build_file_content = None, sha256 = None):
Expand Down
33 changes: 13 additions & 20 deletions kotlin/internal/toolchains.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def _kotlin_toolchain_impl(ctx):
toolchain = dict(
language_version = ctx.attr.language_version,
api_version = ctx.attr.api_version,
coroutines = ctx.attr.coroutines,
debug = ctx.attr.debug,
jvm_target = ctx.attr.jvm_target,
kotlinbuilder = ctx.attr.kotlinbuilder,
Expand Down Expand Up @@ -79,19 +78,21 @@ _kt_toolchain = rule(
cfg = "host",
),
"language_version": attr.string(
doc = "this is the -languag_version flag [see](https://kotlinlang.org/docs/reference/compatibility.html)",
default = "1.2",
doc = "this is the -language_version flag [see](https://kotlinlang.org/docs/reference/compatibility.html)",
default = "1.3",
values = [
"1.1",
"1.2",
"1.3",
],
),
"api_version": attr.string(
doc = "this is the -api_version flag [see](https://kotlinlang.org/docs/reference/compatibility.html).",
default = "1.2",
default = "1.3",
values = [
"1.1",
"1.2",
"1.3",
],
),
"debug": attr.string_list(
Expand All @@ -101,24 +102,18 @@ _kt_toolchain = rule(
using `tags` attribute defined directly on the rules.""",
allow_empty = True,
),
"coroutines": attr.string(
doc = "the -Xcoroutines flag, enabled by default as it's considered production ready 1.2.0 onward.",
default = "enable",
values = [
"enable",
"warn",
"error",
],
),
"jvm_runtime": attr.label(
"jvm_runtime": attr.label_list(
doc = "The implicit jvm runtime libraries. This is internal.",
default = Label("@" + _KT_COMPILER_REPO + "//:kotlin-runtime"),
default = [
Label("@" + _KT_COMPILER_REPO + "//:kotlin-stdlib")
],
providers = [JavaInfo],
cfg = "target",
),
"jvm_stdlibs": attr.label_list(
doc = "The jvm stdlibs. This is internal.",
default = [
Label("@" + _KT_COMPILER_REPO + "//:annotations"),
Label("@" + _KT_COMPILER_REPO + "//:kotlin-stdlib"),
Label("@" + _KT_COMPILER_REPO + "//:kotlin-stdlib-jdk7"),
# JDK8 is being added blindly but I think we will probably not support bytecode levels 1.6 when the
Expand Down Expand Up @@ -159,23 +154,21 @@ def define_kt_toolchain(
name,
language_version = None,
api_version = None,
jvm_target = None,
coroutines = None):
jvm_target = None):
"""Define the Kotlin toolchain."""
impl_name = name + "_impl"
_kt_toolchain(
name = impl_name,
language_version = language_version,
api_version = api_version,
jvm_target = jvm_target,
coroutines = coroutines,
debug =
select({
"//kotlin/internal:builder_debug_trace": ["trace"],
"@io_bazel_rules_kotlin//kotlin/internal:builder_debug_trace": ["trace"],
"//conditions:default": [],
}) +
select({
"//kotlin/internal:builder_debug_timings": ["timings"],
"@io_bazel_rules_kotlin//kotlin/internal:builder_debug_timings": ["timings"],
"//conditions:default": [],
}),
visibility = ["//visibility:public"],
Expand Down
2 changes: 1 addition & 1 deletion kotlin/internal/utils/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _init_builder_args(ctx, rule_kind, module_name):
args.add("--kotlin_jvm_target", toolchain.jvm_target)
args.add("--kotlin_api_version", toolchain.api_version)
args.add("--kotlin_language_version", toolchain.language_version)
args.add("--kotlin_passthrough_flags", "-Xcoroutines=%s" % toolchain.coroutines)
args.add("--kotlin_passthrough_flags", "-Xuse-experimental=kotlin.Experimental")

debug = depset(toolchain.debug)
for tag in ctx.attr.tags:
Expand Down
2 changes: 2 additions & 0 deletions kotlin/kotlin.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ load(
)
load(
"//kotlin/internal:toolchains.bzl",
_define_kt_toolchain = "define_kt_toolchain",
_kt_register_toolchains = "kt_register_toolchains",
)
load(
Expand All @@ -37,6 +38,7 @@ load(
_kt_js_library = "kt_js_library_macro",
)

define_kt_toolchain = _define_kt_toolchain
kt_js_library = _kt_js_library
kt_js_import = _kt_js_import
kt_register_toolchains = _kt_register_toolchains
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,4 @@ java_binary(
main_class = "io.bazel.kotlin.builder.KotlinBuilderMain",
runtime_deps = [":builder_jar_jar"],
visibility = ["//visibility:public"],
)

)
1 change: 1 addition & 0 deletions src/main/kotlin/io/bazel/kotlin/builder/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ java_library(
":builder_kt",
"//src/main/protobuf:kotlin_model",
"//third_party:dagger",
"@com_github_jetbrains_kotlin//:annotations",
"@com_github_jetbrains_kotlin//:kotlin-stdlib",
"@io_bazel_rules_kotlin_com_google_protobuf_protobuf_java//jar",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,13 @@ class KotlinJvmTaskExecutor @Inject internal constructor(
*/
private fun JvmCompilationTask.getCommonArgs(): MutableList<String> {
val args = mutableListOf<String>()
val friendPaths= info.friendPathsList.map { Paths.get(it).toAbsolutePath() }
args.addAll(
"-cp", inputs.joinedClasspath,
"-api-version", info.toolchainInfo.common.apiVersion,
"-language-version", info.toolchainInfo.common.languageVersion,
"-jvm-target", info.toolchainInfo.jvm.jvmTarget,
"-Xfriend-paths=${info.friendPathsList.joinToString(File.pathSeparator)}"
"-Xfriend-paths=${friendPaths.joinToString(File.pathSeparator)}"
)

args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class SourceJarCreator(
for (entry in jar.entries()) {
if (!entry.isDirectory) {
if (isJavaSourceLike(entry.name)) {
jar.getInputStream(entry).readBytes(entry.size.toInt()).also {
jar.getInputStream(entry).readBytes().also {
addEntry(entry.name, path, it)
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/kotlin/io/bazel/kotlin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,15 @@ kt_rules_e2e_test(
friends = ["//src/test/data/jvm/basic:test_friends_library"],
)

kt_rules_e2e_test(
name = "KotlinJvm13Test",
srcs = ["KotlinJvm13Test.kt"],
)

test_suite(
name = "assertion_tests",
tests = [
"KotlinJvm13Test",
"KotlinJvmBasicAssertionTest",
"KotlinJvmDaggerExampleTest",
"KotlinJvmFriendsVisibilityTest",
Expand Down
12 changes: 12 additions & 0 deletions src/test/kotlin/io/bazel/kotlin/KotlinJvm13Test.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.bazel.kotlin

import org.junit.Test

class KotlinJvm13Test {
@Test fun testFoo() {
when (val foo = "TryIng Mixed Case".toLowerCase()) {
"trying mixed case" -> { println(foo) }
else -> {}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.bazel.kotlin

import org.junit.Ignore
import org.junit.Test


Expand All @@ -25,6 +26,9 @@ class KotlinNormalizationAssertionTest : KotlinAssertionTestCase("src/test/data/
*
* The hashes can change between kotlin compiler versions so this approach isn't sustainable.
*/
// (cgruber) per the above, this relies on hashes, which are volatile between kotlinc versions,
// so I'm disabling it.
@Ignore
@Test
fun testJarNormalization() {
jarTestCase(
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/io/bazel/kotlin/builder/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ _COMMON_DEPS = [
"//src/main/protobuf:kotlin_model",
"//third_party/jvm/com/google/truth",
"//third_party/jvm/junit",
"@io_bazel_rules_kotlin_com_google_guava_guava//jar",
"//third_party/jvm/com/google/guava",
"//third_party/jvm/com/google/code/findbugs:jsr305",
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@
import java.util.function.Consumer;
import java.util.stream.Collectors;

import static io.bazel.kotlin.builder.KotlinJvmTestBuilder.KOTLIN_ANNOTATIONS;
import static io.bazel.kotlin.builder.KotlinJvmTestBuilder.KOTLIN_STDLIB;
import static io.bazel.kotlin.builder.KotlinJvmTestBuilder.*;

@RunWith(JUnit4.class)
public class KotlinBuilderJvmKaptTest {
private static final Dep AUTO_VALUE_ANNOTATIONS =
Dep.importJar(
"autovalue",
"autovalue_annotations",
"external/io_bazel_rules_kotlin_com_google_auto_value_auto_value_annotations"
+ "/jar/io_bazel_rules_kotlin_com_google_auto_value_auto_value_annotations.jar");
private static final Dep AUTO_VALUE =
Expand All @@ -53,7 +52,7 @@ public class KotlinBuilderJvmKaptTest {
private static final Consumer<KotlinJvmTestBuilder.TaskBuilder> ADD_AUTO_VALUE_PLUGIN =
(c) -> {
c.addAnnotationProcessors(AUTO_VALUE_ANNOTATION_PROCESSOR);
c.addDirectDependencies(AUTO_VALUE_ANNOTATIONS, AUTO_VALUE, KOTLIN_STDLIB);
c.addDirectDependencies(AUTO_VALUE_ANNOTATIONS, KOTLIN_ANNOTATIONS, KOTLIN_STDLIB);
};

@Test
Expand Down
6 changes: 3 additions & 3 deletions third_party/dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ dependencies:
version: "0.45"
com.google.auto.service:
auto-service:
modules: ["", "auto-service-annotations"]
modules: ["", "annotations"]
lang: "java"
version: "1.0-rc5"
com.google.auto.value:
auto-value:
modules: ["", "auto-value-annotations"]
modules: ["", "annotations"]
lang: "java"
version: "1.6.5"
com.google.dagger:
Expand All @@ -55,7 +55,7 @@ dependencies:
kotlinx-coroutines:
modules: ["core"]
lang: "java"
version : "0.23.1"
version : "1.1.1"
org.pantsbuild:
jarjar:
lang: "java"
Expand Down
1 change: 0 additions & 1 deletion third_party/jvm/com/google/auto/service/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ java_library(
"//visibility:public",
],
exports = [
":auto_service_annotations",
"//external:jar/io_bazel_rules_kotlin_com/google/auto/service/auto_service",
],
runtime_deps = [
Expand Down
1 change: 0 additions & 1 deletion third_party/jvm/com/google/auto/value/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ java_library(
"//visibility:public",
],
exports = [
":auto_value_annotations",
"//external:jar/io_bazel_rules_kotlin_com/google/auto/value/auto_value",
],
)
Expand Down
Loading