forked from bazelbuild/rules_scala
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscala_config.bzl
60 lines (50 loc) · 2.26 KB
/
scala_config.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
load("//scala:scala_cross_version.bzl", "extract_major_version", "extract_minor_version")
def _default_scala_version():
"""return the scala version for use in maven coordinates"""
return "2.12.14"
def _validate_supported_scala_version(scala_major_version, scala_minor_version):
if scala_major_version == "2.11" and int(scala_minor_version) != 12:
fail("Scala version must be 2.11.12 to use compiler dependency tracking with 2.11.")
if scala_major_version == "2.12" and int(scala_minor_version) < 1:
fail("Scala version must be newer or equal to 2.12.1 to use compiler dependency tracking.")
def _store_config(repository_ctx):
scala_version = repository_ctx.os.environ.get(
"SCALA_VERSION",
repository_ctx.attr.scala_version,
)
enable_compiler_dependency_tracking = repository_ctx.os.environ.get(
"ENABLE_COMPILER_DEPENDENCY_TRACKING",
str(repository_ctx.attr.enable_compiler_dependency_tracking),
)
scala_major_version = extract_major_version(scala_version)
scala_minor_version = extract_minor_version(scala_version)
if enable_compiler_dependency_tracking == "True":
_validate_supported_scala_version(scala_major_version, scala_minor_version)
config_file_content = "\n".join([
"SCALA_VERSION='" + scala_version + "'",
"SCALA_MAJOR_VERSION='" + scala_major_version + "'",
"SCALA_MINOR_VERSION='" + scala_minor_version + "'",
"ENABLE_COMPILER_DEPENDENCY_TRACKING=" + enable_compiler_dependency_tracking,
])
repository_ctx.file("config.bzl", config_file_content)
repository_ctx.file("BUILD")
_config_repository = repository_rule(
implementation = _store_config,
attrs = {
"scala_version": attr.string(
mandatory = True,
),
"enable_compiler_dependency_tracking": attr.bool(
mandatory = True,
),
},
environ = ["SCALA_VERSION", "ENABLE_COMPILER_DEPENDENCY_TRACKING"],
)
def scala_config(
scala_version = _default_scala_version(),
enable_compiler_dependency_tracking = False):
_config_repository(
name = "io_bazel_rules_scala_config",
scala_version = scala_version,
enable_compiler_dependency_tracking = enable_compiler_dependency_tracking,
)