Skip to content

Commit

Permalink
Allow version-aware naming for artifact repositories (#1562)
Browse files Browse the repository at this point in the history
For multiple `SCALA_VERSIONS` we will need to download artifacts for each version.
Some naming collision avoidance is needed.

Co-authored-by: mkuta <mkuta@virtuslab.com>
  • Loading branch information
aszady and mateuszkuta256 authored Apr 12, 2024
1 parent a6b26df commit 61bb9bd
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions third_party/repositories/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ load(
load(
"@io_bazel_rules_scala//scala:scala_cross_version.bzl",
"default_maven_server_urls",
"extract_major_version",
"version_suffix",
)
load(
"@io_bazel_rules_scala//scala:scala_maven_import_external.bzl",
_scala_maven_import_external = "scala_maven_import_external",
)
load("@io_bazel_rules_scala_config//:config.bzl", "SCALA_MAJOR_VERSION", "SCALA_VERSION")
load("@io_bazel_rules_scala_config//:config.bzl", "SCALA_VERSION")

artifacts_by_major_scala_version = {
"2.11": _artifacts_2_11,
Expand All @@ -57,31 +59,42 @@ scala_version_by_major_scala_version = {
}

def repositories(
scala_version = None,
for_artifact_ids = [],
maven_servers = default_maven_server_urls(),
overriden_artifacts = {},
fetch_sources = True,
validate_scala_version = False):
major_scala_version = SCALA_MAJOR_VERSION
"""
Downloads given artifacts.
If `scala_version` is provided, artifacts will be downloaded for that Scala version.
Also version-aware naming of repositories will be used (appending a suffix).
Otherwise, the default Scala version is used and repository names have no suffix.
"""

suffix = version_suffix(scala_version) if scala_version else ""
scala_version = scala_version or SCALA_VERSION
major_scala_version = extract_major_version(scala_version)

if validate_scala_version:
repository_scala_version = scala_version_by_major_scala_version[SCALA_MAJOR_VERSION]
default_version_matches = SCALA_VERSION == repository_scala_version
repository_scala_version = scala_version_by_major_scala_version[major_scala_version]
default_version_matches = scala_version == repository_scala_version

if not default_version_matches and len(overriden_artifacts) == 0:
version_message = "Scala config (%s) version does not match repository version (%s)"
fail(version_message % (SCALA_VERSION, repository_scala_version))
fail(version_message % (scala_version, repository_scala_version))

default_artifacts = artifacts_by_major_scala_version[major_scala_version]
artifacts = dict(default_artifacts.items() + overriden_artifacts.items())
for id in for_artifact_ids:
_scala_maven_import_external(
name = id,
name = id + suffix,
artifact = artifacts[id]["artifact"],
artifact_sha256 = artifacts[id]["sha256"],
licenses = ["notice"],
server_urls = maven_servers,
deps = artifacts[id].get("deps", []),
deps = [dep + suffix for dep in artifacts[id].get("deps", [])],
runtime_deps = artifacts[id].get("runtime_deps", []),
testonly_ = artifacts[id].get("testonly", False),
fetch_sources = fetch_sources,
Expand Down

0 comments on commit 61bb9bd

Please sign in to comment.