Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit e44594d

Browse files
stephenjudkinsborkaehw
authored andcommitted
Allow users to configure log level from compiler config (#254)
1 parent ac845fd commit e44594d

File tree

9 files changed

+43
-1
lines changed

9 files changed

+43
-1
lines changed

docs/stardoc/providers.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ A Scala compiler plugin
439439
## ZincConfiguration
440440

441441
<pre>
442-
ZincConfiguration(<a href="#ZincConfiguration-compiler_bridge">compiler_bridge</a>, <a href="#ZincConfiguration-compile_worker">compile_worker</a>)
442+
ZincConfiguration(<a href="#ZincConfiguration-compiler_bridge">compiler_bridge</a>, <a href="#ZincConfiguration-compile_worker">compile_worker</a>, <a href="#ZincConfiguration-log_level">log_level</a>)
443443
</pre>
444444

445445
Zinc configuration.
@@ -464,6 +464,12 @@ Zinc configuration.
464464
<p>the worker label for compilation with Zinc</p>
465465
</td>
466466
</tr>
467+
<tr id="ZincConfiguration-log_level">
468+
<td><code>log_level</code></td>
469+
<td>
470+
<p>log level for the Zinc compiler</p>
471+
</td>
472+
</tr>
467473
</tbody>
468474
</table>
469475

rules/private/phases/phase_zinc_compile.bzl

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def phase_zinc_compile(ctx, g):
6262
args.add_all("--plugins", g.classpaths.plugin)
6363
args.add_all("--source_jars", g.classpaths.src_jars)
6464
args.add("--tmp", tmp.path)
65+
args.add("--log_level", zinc_configuration.log_level)
6566
args.add_all("--", g.classpaths.srcs)
6667
args.set_param_file_format("multiline")
6768
args.use_param_file("@%s", use_always = True)

rules/providers.bzl

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ ZincConfiguration = provider(
6363
fields = {
6464
"compiler_bridge": "compiled Zinc compiler bridge",
6565
"compile_worker": "the worker label for compilation with Zinc",
66+
"log_level": "log level for the Zinc compiler",
6667
},
6768
)
6869

rules/scala.bzl

+4
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,10 @@ _configure_zinc_scala = rule(
512512
"global_scalacopts": attr.string_list(
513513
doc = "Scalac options that will always be enabled.",
514514
),
515+
"log_level": attr.string(
516+
doc = "Compiler log level",
517+
default = "warn",
518+
),
515519
"deps_direct": attr.string(default = "error"),
516520
"deps_used": attr.string(default = "error"),
517521
"_compile_worker": attr.label(

rules/scala/private/provider.bzl

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def configure_zinc_scala_implementation(ctx):
4444
_ZincConfiguration(
4545
compile_worker = ctx.attr._compile_worker,
4646
compiler_bridge = ctx.file.compiler_bridge,
47+
log_level = ctx.attr.log_level,
4748
),
4849
_DepsConfiguration(
4950
direct = ctx.attr.deps_direct,

tests/compile/log_level/BUILD

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
load("@rules_scala_annex//rules:scala.bzl", "scala_binary")
2+
3+
scala_binary(
4+
name = "lib",
5+
srcs = ["Example.scala"],
6+
scala = "//scala:zinc_2_12_6_log_level_debug",
7+
deps = [],
8+
)

tests/compile/log_level/Example.scala

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Example {
2+
def foo = 42
3+
}

tests/compile/log_level/test

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash -e
2+
. "$(dirname "$0")"/../../common.sh
3+
4+
bazel build :lib > output 2>&1
5+
6+
cat output | grep "Compiling 1 Scala source"
7+
rm output

tests/scala/BUILD

+11
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,14 @@ configure_zinc_scala(
156156
version = "2.12.6",
157157
visibility = ["//scalacopts/rule:__subpackages__"],
158158
)
159+
160+
# for log_level test
161+
configure_zinc_scala(
162+
name = "zinc_2_12_6_log_level_debug",
163+
compiler_bridge = ":compiler_bridge_2_12_6",
164+
compiler_classpath = compiler_classpath_2_12_6,
165+
log_level = "debug",
166+
runtime_classpath = runtime_classpath_2_12_6,
167+
version = "2.12.6",
168+
visibility = ["//visibility:public"],
169+
)

0 commit comments

Comments
 (0)