switch to JavaInfo as the constructor for the JavaInfo
diff --git a/kotlin/builder/src/io/bazel/kotlin/builder/tasks/jvm/KotlinJvmTaskExecutor.kt b/kotlin/builder/src/io/bazel/kotlin/builder/tasks/jvm/KotlinJvmTaskExecutor.kt
index 75dcab5..4b249cb 100644
--- a/kotlin/builder/src/io/bazel/kotlin/builder/tasks/jvm/KotlinJvmTaskExecutor.kt
+++ b/kotlin/builder/src/io/bazel/kotlin/builder/tasks/jvm/KotlinJvmTaskExecutor.kt
@@ -38,19 +38,25 @@
class Result(val timings: List<String>, val command: CompilationTask)
fun compile(command: CompilationTask): Result {
- val context = Context()
- val commandWithApSources = context.execute("kapt") {
- runAnnotationProcessors(command)
+ // fix error handling
+ try {
+ val context = Context()
+ val commandWithApSources = context.execute("kapt") {
+ runAnnotationProcessors(command)
+ }
+ compileClasses(context, commandWithApSources)
+ context.execute("create jar") {
+ outputJarCreator.createOutputJar(commandWithApSources)
+ }
+ produceSourceJar(commandWithApSources)
+ context.execute("generate jdeps") {
+ jDepsGenerator.generateJDeps(commandWithApSources)
+ }
+ return Result(context.timings, commandWithApSources)
+
+ } catch (ex: Throwable) {
+ throw RuntimeException(ex)
}
- compileClasses(context, commandWithApSources)
- context.execute("create jar") {
- outputJarCreator.createOutputJar(commandWithApSources)
- }
- produceSourceJar(commandWithApSources)
- context.execute("generate jdeps") {
- jDepsGenerator.generateJDeps(commandWithApSources)
- }
- return Result(context.timings, commandWithApSources)
}
private fun produceSourceJar(command: CompilationTask) {
diff --git a/kotlin/internal/compile.bzl b/kotlin/internal/compile.bzl
index 71f1d48..0444853 100644
--- a/kotlin/internal/compile.bzl
+++ b/kotlin/internal/compile.bzl
@@ -103,52 +103,6 @@
input_manifests = input_manifests
)
-def _select_std_libs(ctx):
- return ctx.toolchains[kt.defs.TOOLCHAIN_TYPE].jvm_stdlibs
-
-def _make_java_provider(ctx, srcs, input_deps=[], auto_deps=[]):
- """Creates the java_provider for a Kotlin target.
-
- This macro is distinct from the kotlin_make_providers as collecting the java_info is useful before the DefaultInfo is
- created.
-
- Args:
- ctx: The ctx of the rule in scope when this macro is called. The macro will pick up the following entities from
- the rule ctx:
- * The default output jar.
- * The `deps` for this provider.
- * Optionally `exports` (see java rules).
- * The `_kotlin_runtime` implicit dependency.
- Returns:
- A JavaInfo provider.
- """
- runtime = ctx.toolchains[kt.defs.TOOLCHAIN_TYPE].jvm_runtime
- deps=utils.collect_all_jars(input_deps)
- exported_deps=utils.collect_all_jars(getattr(ctx.attr, "exports", []))
-
- my_compile_jars = exported_deps.compile_jars + [ctx.outputs.jar]
- my_runtime_jars = exported_deps.transitive_runtime_jars + [ctx.outputs.jar]
-
- my_transitive_compile_jars = my_compile_jars + deps.transitive_compile_time_jars + exported_deps.transitive_compile_time_jars + auto_deps
- my_transitive_runtime_jars = my_runtime_jars + deps.transitive_runtime_jars + exported_deps.transitive_runtime_jars + runtime + auto_deps
-
- # collect the runtime jars from the runtime_deps attribute.
- for jar in ctx.attr.runtime_deps:
- my_transitive_runtime_jars += jar[JavaInfo].transitive_runtime_jars
-
- return java_common.create_provider(
- use_ijar = False,
- # A list or set of output source jars that contain the uncompiled source files including the source files
- # generated by annotation processors if the case.
- source_jars = [ctx.outputs.srcjar],
- # A list or a set of jars that should be used at compilation for a given target.
- compile_time_jars = my_compile_jars,
- # A list or a set of jars that should be used at runtime for a given target.
- runtime_jars = my_runtime_jars,
- transitive_compile_time_jars = my_transitive_compile_jars,
- transitive_runtime_jars = my_transitive_runtime_jars
- )
-
def _make_providers(ctx, java_info, module_name, transitive_files=depset(order="default")):
kotlin_info=kt.info.KtInfo(
srcs=ctx.files.srcs,
@@ -159,7 +113,7 @@
jars = [struct(
class_jar = ctx.outputs.jar,
ijar = None,
- source_jars = java_info.source_jars
+ source_jars = [ctx.outputs.srcjar]
)]
),
)
@@ -204,21 +158,43 @@
# If we setup indirection than the first entry in the merge list is the result of the kotlin compile action.
output_merge_list=[ kt_compile_output_jar ] + output_merge_list
- kotlin_auto_deps=_select_std_libs(ctx)
-
- deps = ctx.attr.deps + getattr(ctx.attr, "friends", [])
-
srcs = utils.partition_srcs(ctx.files.srcs)
if (len(srcs.kt) + len(srcs.java) == 0) and len(srcs.src_jars) == 0:
fail("no sources provided")
+ toolchain=ctx.toolchains[kt.defs.TOOLCHAIN_TYPE]
+
+ deps = [
+ d[JavaInfo]
+ for d in (
+ toolchain.jvm_stdlibs +
+ getattr(ctx.attr, "friends", []) +
+ ctx.attr.deps
+ )
+ ]
+
+ runtime_deps = [
+ d[JavaInfo]
+ for d in (
+ ctx.attr.runtime_deps +
+ [toolchain.jvm_runtime]
+ )
+ ]
+
+ exports = [
+ d[JavaInfo]
+ for d in (
+ getattr(ctx.attr, "exports", [])
+ )
+ ]
+
# setup the compile action.
_kotlin_do_compile_action(
ctx,
rule_kind = rule_kind,
output_jar = kt_compile_output_jar,
- compile_jars = utils.collect_jars_for_compile(deps) + kotlin_auto_deps,
+ compile_jars = java_common.merge(deps).compile_jars,
module_name = module_name,
friend_paths = friend_paths,
srcs = srcs
@@ -229,7 +205,17 @@
utils.actions.fold_jars(ctx, rule_kind, output_jar, output_merge_list)
# create the java provider but the kotlin and default provider cannot be created here.
- return _make_java_provider(ctx, srcs, deps, kotlin_auto_deps)
+
+ return JavaInfo(
+ output_jar = ctx.outputs.jar,
+ compile_jar = ctx.outputs.jar,
+ source_jar = ctx.outputs.srcjar,
+# jdeps = ctx.outputs.jdeps,
+ deps = deps,
+ runtime_deps = runtime_deps,
+ exports = exports,
+ neverlink = getattr(ctx.attr, "neverlink", False)
+ )
compile = struct(
compile_action = _compile_action,
diff --git a/kotlin/internal/utils.bzl b/kotlin/internal/utils.bzl
index eaab3db..c141584 100644
--- a/kotlin/internal/utils.bzl
+++ b/kotlin/internal/utils.bzl
@@ -52,54 +52,6 @@
all_srcs = kt + java,
src_jars = depset(src_jars)
)
-
-# DEPSET UTILS #################################################################################################################################################
-def _select_compile_jars(dep):
- """selects the correct compile time jar from a java provider"""
- if not JavaInfo in dep:
- return []
- is_kotlin_provider = kt.info.KtInfo in dep
- java_provider = dep[JavaInfo]
- if is_kotlin_provider:
- return java_provider.full_compile_jars
- elif dep.label.workspace_root == "external/com_github_jetbrains_kotlin":
- return java_provider.full_compile_jars
- else:
- return java_provider.compile_jars
-
-def _collect_jars_for_compile(deps):
- """creates the compile jar depset, this should be strict including only the output jars of the listed dependencies.
- """
- compile_jars = depset()
- for d in deps:
- compile_jars += _select_compile_jars(d)
- return compile_jars
-
-def _collect_all_jars(deps):
- """
- Merges a list of java providers into a struct of depsets.
- """
- compile_jars = depset()
- runtime_jars = depset()
- transitive_runtime_jars = depset()
- transitive_compile_time_jars = depset()
-
- for dep_target in deps:
- if JavaInfo in dep_target:
- java_provider = dep_target[JavaInfo]
- compile_jars += java_provider.compile_jars
- # the runtime_jar compile_jar seperation is here to support the exports concept.
- runtime_jars += java_provider.full_compile_jars
- transitive_compile_time_jars += java_provider.transitive_compile_time_jars
- transitive_runtime_jars += java_provider.transitive_runtime_jars
-
- return struct (
- compile_jars = compile_jars,
- runtime_jars = runtime_jars,
- transitive_runtime_jars = transitive_runtime_jars,
- transitive_compile_time_jars = transitive_compile_time_jars
- )
-
# RESOURCE JARS ################################################################################################################################################
_CONVENTIONAL_RESOURCE_PATHS = [
"src/main/resources",
@@ -217,8 +169,6 @@
fold_jars = _fold_jars_action,
write_launcher = _write_launcher_action,
),
- collect_all_jars = _collect_all_jars,
- collect_jars_for_compile = _collect_jars_for_compile,
restore_label = _restore_label,
derive_module_name = _derive_module_name,
partition_srcs = _partition_srcs
diff --git a/kotlin/kotlin.bzl b/kotlin/kotlin.bzl
index acd1b1f..87decf2 100644
--- a/kotlin/kotlin.bzl
+++ b/kotlin/kotlin.bzl
@@ -159,7 +159,7 @@
default = [],
allow_files = [".srcjar", ".kt", ".java"],
),
- "deps": attr.label_list(aspects = [_kt_jvm_plugin_aspect]),
+ "deps": attr.label_list(aspects = [_kt_jvm_plugin_aspect], providers=[JavaInfo]),
"runtime_deps": attr.label_list(default = []),
"resources": attr.label_list(
default = [],
@@ -222,7 +222,8 @@
########################################################################################################################
kt_jvm_library = rule(
attrs = dict(_common_attr.items() + {
- "exports": attr.label_list(default = []),
+ "exports": attr.label_list(default = [], providers=[JavaInfo]),
+ "neverlink": attr.bool(default=False),
}.items()),
outputs = _common_outputs,
toolchains = [_kt.defs.TOOLCHAIN_TYPE],
@@ -247,6 +248,7 @@
deps: A list of dependencies of this rule.See general comments about `deps` at [Attributes common to all build rules](https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes).
module_name: The name of the module, if not provided the module name is derived from the label. --e.g., `//some/package/path:label_name` is translated to
`some_package_path-label_name`.
+ neverlink: If true only use this library for compilation and not at runtime.
"""
kt_jvm_binary = rule(
@@ -278,6 +280,7 @@
),
"friends": attr.label_list(
default = [],
+ providers = [JavaInfo]
),
"test_class": attr.string(),
"main_class": attr.string(default="com.google.testing.junit.runner.BazelTestRunner"),
diff --git a/kotlin/toolchains.bzl b/kotlin/toolchains.bzl
index 733bc06..814cc52 100644
--- a/kotlin/toolchains.bzl
+++ b/kotlin/toolchains.bzl
@@ -84,13 +84,15 @@
_kt_jvm_attrs = dict(_common_attrs.items() + {
"jvm_runtime": attr.label(
default = Label("@" + _KT_COMPILER_REPO + "//:kotlin-runtime"),
+ providers = [JavaInfo]
),
"jvm_stdlibs": attr.label_list(
default = [
Label("@" + _KT_COMPILER_REPO + "//:kotlin-stdlib"),
Label("@" + _KT_COMPILER_REPO + "//:kotlin-stdlib-jdk7"),
Label("@" + _KT_COMPILER_REPO + "//:kotlin-stdlib-jdk8"),
- ]
+ ],
+ providers = [JavaInfo]
),
"jvm_target": attr.string(
default = "1.8",
@@ -114,8 +116,8 @@
kotlinbuilder = ctx.attr.kotlinbuilder,
kotlin_home = ctx.files.kotlin_home,
- jvm_runtime = ctx.files.jvm_runtime,
- jvm_stdlibs = ctx.files.jvm_stdlibs
+ jvm_runtime = ctx.attr.jvm_runtime,
+ jvm_stdlibs = ctx.attr.jvm_stdlibs
)
return struct(providers=[toolchain])