1
- load ("//scala:scala_cross_version.bzl" , "extract_major_version" , "extract_minor_version" )
1
+ load ("//scala:scala_cross_version.bzl" , "extract_major_version" , "extract_minor_version" , "version_suffix" )
2
2
3
3
def _default_scala_version ():
4
4
"""return the scala version for use in maven coordinates"""
@@ -10,6 +10,16 @@ def _validate_supported_scala_version(scala_major_version, scala_minor_version):
10
10
if scala_major_version == "2.12" and int (scala_minor_version ) < 1 :
11
11
fail ("Scala version must be newer or equal to 2.12.1 to use compiler dependency tracking." )
12
12
13
+ def _config_setting (scala_version ):
14
+ return """config_setting(
15
+ name = "scala_version{version_suffix}",
16
+ flag_values = {{":scala_version": "{version}"}},
17
+ )
18
+ """ .format (version_suffix = version_suffix (scala_version ), version = scala_version )
19
+
20
+ def _config_settings (scala_versions ):
21
+ return "" .join ([_config_setting (v ) for v in scala_versions ])
22
+
13
23
def _store_config (repository_ctx ):
14
24
# Default version
15
25
scala_version = repository_ctx .os .environ .get (
@@ -39,8 +49,18 @@ def _store_config(repository_ctx):
39
49
"ENABLE_COMPILER_DEPENDENCY_TRACKING=" + enable_compiler_dependency_tracking ,
40
50
])
41
51
52
+ build_file_content = """load("@bazel_skylib//rules:common_settings.bzl", "string_setting")
53
+ string_setting(
54
+ name = "scala_version",
55
+ build_setting_default = "{scala_version}",
56
+ values = {scala_versions},
57
+ visibility = ["//visibility:public"],
58
+ )
59
+ """ .format (scala_versions = scala_versions , scala_version = scala_version )
60
+ build_file_content += _config_settings (scala_versions )
61
+
42
62
repository_ctx .file ("config.bzl" , config_file_content )
43
- repository_ctx .file ("BUILD" )
63
+ repository_ctx .file ("BUILD" , build_file_content )
44
64
45
65
_config_repository = repository_rule (
46
66
implementation = _store_config ,
0 commit comments