-
Notifications
You must be signed in to change notification settings - Fork 277
/
scala_toolchain.bzl
114 lines (101 loc) · 4.22 KB
/
scala_toolchain.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
load(
"@io_bazel_rules_scala//scala:providers.bzl",
_ScalacProvider = "ScalacProvider",
)
def _compute_dependency_mode(input_dependency_mode, input_plus_one_deps_mode):
if input_plus_one_deps_mode == "on":
return "plus-one"
if input_dependency_mode == "":
return "direct"
return input_dependency_mode
def _compute_strict_deps_mode(input_strict_deps_mode, dependency_mode):
if dependency_mode == "direct":
return "off"
if input_strict_deps_mode == "default":
if dependency_mode == "transitive":
return "error"
else:
return "off"
return input_strict_deps_mode
def _compute_dependency_tracking_method(input_dependency_tracking_method):
if input_dependency_tracking_method == "default":
return "high-level"
return input_dependency_tracking_method
def _scala_toolchain_impl(ctx):
if ctx.attr.plus_one_deps_mode != "":
print(
"Setting plus_one_deps_mode on toolchain is deprecated." +
"Use 'dependency_mode = \"plus-one\"' instead",
)
if ctx.attr.dependency_mode != "" and ctx.attr.plus_one_deps_mode != "":
fail("Cannot set both dependency_mode and plus_one_deps_mode on toolchain")
if ctx.fragments.java.strict_java_deps != "default" and ctx.fragments.java.strict_java_deps != "off":
dependency_mode = "transitive"
strict_deps_mode = ctx.fragments.java.strict_java_deps
unused_dependency_checker_mode = "off"
dependency_tracking_method = "high-level"
else:
dependency_mode = _compute_dependency_mode(
ctx.attr.dependency_mode,
ctx.attr.plus_one_deps_mode,
)
strict_deps_mode = _compute_strict_deps_mode(
ctx.attr.strict_deps_mode,
dependency_mode,
)
unused_dependency_checker_mode = ctx.attr.unused_dependency_checker_mode
dependency_tracking_method = _compute_dependency_tracking_method(ctx.attr.dependency_tracking_method)
# Final quality checks to possibly detect buggy code above
if dependency_mode not in ("direct", "plus-one", "transitive"):
fail("Internal error: invalid dependency_mode " + dependency_mode)
if strict_deps_mode not in ("off", "warn", "error"):
fail("Internal error: invalid strict_deps_mode " + strict_deps_mode)
if dependency_tracking_method not in ("ast", "high-level"):
fail("Internal error: invalid dependency_tracking_method " + dependency_tracking_method)
toolchain = platform_common.ToolchainInfo(
scalacopts = ctx.attr.scalacopts,
scalac_provider_attr = ctx.attr.scalac_provider_attr,
dependency_mode = dependency_mode,
strict_deps_mode = strict_deps_mode,
unused_dependency_checker_mode = unused_dependency_checker_mode,
dependency_tracking_method = dependency_tracking_method,
enable_code_coverage_aspect = ctx.attr.enable_code_coverage_aspect,
scalac_jvm_flags = ctx.attr.scalac_jvm_flags,
scala_test_jvm_flags = ctx.attr.scala_test_jvm_flags,
)
return [toolchain]
scala_toolchain = rule(
_scala_toolchain_impl,
attrs = {
"scalacopts": attr.string_list(),
"scalac_provider_attr": attr.label(
default = "@io_bazel_rules_scala//scala:scalac_default",
providers = [_ScalacProvider],
),
"dependency_mode": attr.string(
values = ["direct", "plus-one", "transitive", ""],
),
"strict_deps_mode": attr.string(
default = "default",
values = ["off", "warn", "error", "default"],
),
"unused_dependency_checker_mode": attr.string(
default = "off",
values = ["off", "warn", "error"],
),
"dependency_tracking_method": attr.string(
default = "default",
values = ["ast", "high-level", "default"],
),
"plus_one_deps_mode": attr.string(
values = ["off", "on", ""],
),
"enable_code_coverage_aspect": attr.string(
default = "off",
values = ["off", "on"],
),
"scalac_jvm_flags": attr.string_list(),
"scala_test_jvm_flags": attr.string_list(),
},
fragments = ["java"],
)