1- load ("@bazel_tools//tools/build_defs/repo:http.bzl" , "http_archive" )
21load (
3- "@io_bazel_rules_scala //scala:scala_cross_version.bzl" ,
2+ "//scala:scala_cross_version.bzl" ,
43 "extract_major_version" ,
54 "extract_minor_version" ,
65 "version_suffix" ,
76 _default_maven_server_urls = "default_maven_server_urls" ,
87)
98load ("//third_party/repositories:repositories.bzl" , "repositories" )
9+ load ("@bazel_tools//tools/build_defs/repo:http.bzl" , "http_archive" )
1010load ("@io_bazel_rules_scala_config//:config.bzl" , "SCALA_VERSIONS" )
1111
1212def _dt_patched_compiler_impl (rctx ):
@@ -24,7 +24,6 @@ dt_patched_compiler = repository_rule(
2424 },
2525 implementation = _dt_patched_compiler_impl ,
2626)
27-
2827_COMPILER_SOURCE_ALIAS_TEMPLATE = """alias(
2928 name = "src",
3029 visibility = ["//visibility:public"],
@@ -69,15 +68,19 @@ def _validate_scalac_srcjar(srcjar):
6968def dt_patched_compiler_setup (scala_version , scala_compiler_srcjar = None ):
7069 scala_major_version = extract_major_version (scala_version )
7170 scala_minor_version = extract_minor_version (scala_version )
72- patch = "@io_bazel_rules_scala //dt_patches:dt_compiler_%s.patch" % scala_major_version
71+ patch = Label ( " //dt_patches:dt_compiler_%s.patch" % scala_major_version )
7372
7473 minor_version = int (scala_minor_version )
7574
7675 if scala_major_version == "2.12" :
7776 if minor_version >= 1 and minor_version <= 7 :
78- patch = "@io_bazel_rules_scala//dt_patches:dt_compiler_%s.1.patch" % scala_major_version
77+ patch = Label (
78+ "//dt_patches:dt_compiler_%s.1.patch" % scala_major_version ,
79+ )
7980 elif minor_version <= 11 :
80- patch = "@io_bazel_rules_scala//dt_patches:dt_compiler_%s.8.patch" % scala_major_version
81+ patch = Label (
82+ "//dt_patches:dt_compiler_%s.8.patch" % scala_major_version ,
83+ )
8184
8285 build_file_content = "\n " .join ([
8386 "package(default_visibility = [\" //visibility:public\" ])" ,
@@ -112,7 +115,9 @@ def dt_patched_compiler_setup(scala_version, scala_compiler_srcjar = None):
112115 integrity = srcjar .get ("integrity" ),
113116 )
114117
115- def rules_scala_setup (scala_compiler_srcjar = None ):
118+ def rules_scala_setup (
119+ scala_compiler_srcjar = None ,
120+ setup_compiler_sources = True ):
116121 if not native .existing_rule ("bazel_skylib" ):
117122 http_archive (
118123 name = "bazel_skylib" ,
@@ -165,8 +170,26 @@ def rules_scala_setup(scala_compiler_srcjar = None):
165170 url = "https://github.com/bazelbuild/rules_proto/releases/download/6.0.2/rules_proto-6.0.2.tar.gz" ,
166171 )
167172
173+ if setup_compiler_sources :
174+ srcs = {version : scala_compiler_srcjar for version in SCALA_VERSIONS }
175+ _setup_scala_compiler_sources (srcs )
176+
177+ def _setup_scala_compiler_sources (srcjars = {}):
178+ """Generates Scala compiler source repos used internally by rules_scala.
179+
180+ Args:
181+ srcjars: optional dictionary of Scala version string to compiler srcjar
182+ metadata dictionaries containing:
183+ - exactly one "label", "url", or "urls" key
184+ - optional "integrity" or "sha256" keys
185+ """
168186 for scala_version in SCALA_VERSIONS :
169- dt_patched_compiler_setup (scala_version , scala_compiler_srcjar )
187+ dt_patched_compiler_setup (scala_version , srcjars .get (scala_version ))
188+
189+ compiler_sources_repo (
190+ name = "scala_compiler_sources" ,
191+ scala_versions = SCALA_VERSIONS ,
192+ )
170193
171194 compiler_sources_repo (
172195 name = "scala_compiler_sources" ,
@@ -213,13 +236,19 @@ def scala_repositories(
213236 overriden_artifacts = {},
214237 load_dep_rules = True ,
215238 load_jar_deps = True ,
216- fetch_sources = False ):
239+ fetch_sources = False ,
240+ validate_scala_version = True ,
241+ scala_compiler_srcjars = {}):
217242 if load_dep_rules :
218- rules_scala_setup ()
243+ # When `WORKSPACE` goes away, so can this case.
244+ rules_scala_setup (setup_compiler_sources = False )
245+
246+ _setup_scala_compiler_sources (scala_compiler_srcjars )
219247
220248 if load_jar_deps :
221249 rules_scala_toolchain_deps_repositories (
222250 maven_servers ,
223251 overriden_artifacts ,
224252 fetch_sources ,
253+ validate_scala_version ,
225254 )
0 commit comments