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" , "sanitize_version" )
22
33def _default_scala_version ():
44 """return the scala version for use in maven coordinates"""
@@ -10,6 +10,17 @@ def _validate_supported_scala_version(scala_major_version, scala_minor_version):
1010 if scala_major_version == "2.12" and int (scala_minor_version ) < 1 :
1111 fail ("Scala version must be newer or equal to 2.12.1 to use compiler dependency tracking." )
1212
13+ def _config_setting (scala_version ):
14+ return "\n " .join ([
15+ 'config_setting(' ,
16+ ' name = "{name}",' ,
17+ ' flag_values = {{":scala_version": "{version}"}},' ,
18+ ')\n ' ,
19+ ]).format (name = sanitize_version (scala_version ), version = scala_version )
20+
21+ def _config_settings (scala_versions ):
22+ return "" .join ([_config_setting (v ) for v in scala_versions ])
23+
1324def _store_config (repository_ctx ):
1425 # Default version
1526 scala_version = repository_ctx .os .environ .get (
@@ -39,8 +50,19 @@ def _store_config(repository_ctx):
3950 "ENABLE_COMPILER_DEPENDENCY_TRACKING=" + enable_compiler_dependency_tracking ,
4051 ])
4152
53+ build_file_content = "\n " .join ([
54+ 'load("@bazel_skylib//rules:common_settings.bzl", "string_flag")' ,
55+ 'string_flag(' ,
56+ ' name = "scala_version",' ,
57+ ' build_setting_default = "{scala_version}",' ,
58+ ' values = {scala_versions},' ,
59+ ' visibility = ["//visibility:public"],' ,
60+ ')\n ' ,
61+ ]).format (scala_versions = scala_versions , scala_version = scala_version ) + \
62+ _config_settings (scala_versions )
63+
4264 repository_ctx .file ("config.bzl" , config_file_content )
43- repository_ctx .file ("BUILD" )
65+ repository_ctx .file ("BUILD" , build_file_content )
4466
4567_config_repository = repository_rule (
4668 implementation = _store_config ,
0 commit comments