Skip to content

Commit

Permalink
Extract load_rules_dependencies macro
Browse files Browse the repository at this point in the history
Requested by @simuons in #1633 to make `rules_scala_setup` and
`scala_repositories` more readable while maintaining the existing APIs.
  • Loading branch information
mbland committed Nov 12, 2024
1 parent 3ddf04c commit 5fdf891
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions scala/private/macros/scala_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ def dt_patched_compiler_setup(scala_version, scala_compiler_srcjar = None):
integrity = srcjar.get("integrity"),
)

def rules_scala_setup(
scala_compiler_srcjar = None,
setup_compiler_sources = True):
def load_rules_dependencies():
if not native.existing_rule("bazel_skylib"):
http_archive(
name = "bazel_skylib",
Expand Down Expand Up @@ -172,11 +170,7 @@ def rules_scala_setup(
url = "https://github.com/bazelbuild/rules_proto/releases/download/6.0.2/rules_proto-6.0.2.tar.gz",
)

if setup_compiler_sources:
srcs = {version: scala_compiler_srcjar for version in SCALA_VERSIONS}
_setup_scala_compiler_sources(srcs)

def _setup_scala_compiler_sources(srcjars = {}):
def setup_scala_compiler_sources(srcjars = {}):
"""Generates Scala compiler source repos used internally by rules_scala.
Args:
Expand All @@ -193,6 +187,13 @@ def _setup_scala_compiler_sources(srcjars = {}):
scala_versions = SCALA_VERSIONS,
)

def rules_scala_setup(scala_compiler_srcjar = None):
load_rules_dependencies()
setup_scala_compiler_sources({
version: scala_compiler_srcjar
for version in SCALA_VERSIONS
})

def _artifact_ids(scala_version):
return [
"io_bazel_rules_scala_scala_library",
Expand Down Expand Up @@ -240,9 +241,9 @@ def scala_repositories(
scala_compiler_srcjars = {}):
if load_dep_rules:
# When `WORKSPACE` goes away, so can this case.
rules_scala_setup(setup_compiler_sources = False)
load_rules_dependencies()

_setup_scala_compiler_sources(scala_compiler_srcjars)
setup_scala_compiler_sources(scala_compiler_srcjars)

if load_jar_deps:
rules_scala_toolchain_deps_repositories(
Expand Down

0 comments on commit 5fdf891

Please sign in to comment.