daml/bazel_tools/BUILD.bazel
Samir Talwar 6035840d8a
Upgrade Scala 2.12 to v2.12.13. (#9280)
* Upgrade Scala 2.12 to v2.12.13.

This is being pulled in anyway because of Maven/Gradle/etc's fun
"favor the most recent" resolution mechanism. The version of Akka we
depend upon transitively depends on Scala 2.12.13, so any downstream
consumers will see that as the Scala version required.

Bringing the Daml repo in line means no more confusion.

CHANGELOG_BEGIN
- [Scala Bindings] If you are using Daml on Scala 2.12, it now depends
  on Scala v2.12.13 (from v2.12.12).
CHANGELOG_END

* Scala 2.12.13 is the default version in our pinned version of nixpkgs.

* Upgrade Scala 2.13's Wartremover version.

* Rename `scala_version_rule` to `scala_version_configure`.

* Add a test case to ensure the Scala versions are the same everywhere.

* Add tests for the Scala JAR versions in maven_install_*.json

* gatling-utils: Change the sort order of the expected CSV in tests.

I don't know why this changed, but it seems to be stable.

* compatibility: `scala_version` -> `scala_version_configure`.

* Bazel: Disable the Scala version tests on Windows.

* compatibility: Upgrade Wartremover to Scala 2.12.13.
2021-03-30 11:02:18 +00:00

85 lines
3.2 KiB
Python

# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
load("//bazel_tools/sh:sh.bzl", "sh_inline_test")
load("@os_info//:os_info.bzl", "is_windows")
load("@scala_version//:index.bzl", "scala_major_version", "scala_version")
# Export Bazel sources for Bazel API docs.
exports_files(
[
"haskell.bzl",
"scala.bzl",
"haskell-c2hs.patch",
"haskell-static-linking.patch",
"haskell-optp-response.patch",
"haskell-arx.patch",
"haskell-win-sys-includes.patch",
"haskell-drop-fake-static.patch",
"pom_template.xml",
],
visibility = ["//:__subpackages__"],
)
sh_inline_test(
name = "scala_version_test",
cmd = """
set -eu
function check {{
if [[ '{expected_version}' == "$$2" ]]; then
echo >&2 "$$1 was version {expected_version}, as expected."
return 0
else
echo >&2 "Expected $$1 to have the version {expected_version}, but got the version $$2."
return 1
fi
}}
JQ="$$(canonicalize_rlocation $(rootpath {jq}))"
SCALA_BIN="$$(canonicalize_rlocation $(rootpath {scala_bin}))"
SCALA_BIN_VERSION="$$($$SCALA_BIN -version |& sed -r 's/^Scala code runner version ([^ ]+) -- .*$$/\\1/')"
function jar_version {{
echo "$$(basename "$$1")" | sed -r 's/^.*-([0-9\\.]+)\\.jar$$/\\1/'
}}
SCALA_COMPILER_JAR_VERSION="$$(jar_version $(rootpath {scala_compiler}))"
SCALA_LIBRARY_JAR_VERSION="$$(jar_version $(rootpath {scala_library}))"
SCALA_REFLECT_JAR_VERSION="$$(jar_version $(rootpath {scala_reflect}))"
function maven_version {{
$$JQ -r --arg name "$$1" '.dependency_tree.dependencies | .[] | .coord | capture("^org\\\\.scala-lang:" + $$name + ":(?<version>[0-9\\\\.]+)$$") | .version' '$(rootpath {maven_install_json})'
}}
SCALA_COMPILER_MAVEN_VERSION="$$(maven_version 'scala-compiler')"
SCALA_LIBRARY_MAVEN_VERSION="$$(maven_version 'scala-library')"
SCALA_REFLECT_MAVEN_VERSION="$$(maven_version 'scala-reflect')"
check 'scala binary' "$$SCALA_BIN_VERSION"
check '$(rootpath {scala_compiler})' "$$SCALA_COMPILER_JAR_VERSION"
check '$(rootpath {scala_library})' "$$SCALA_LIBRARY_JAR_VERSION"
check '$(rootpath {scala_reflect})' "$$SCALA_REFLECT_JAR_VERSION"
check 'org.scala-lang:scala-compiler (in {maven_install_json})' "$$SCALA_COMPILER_MAVEN_VERSION"
check 'org.scala-lang:scala-library (in {maven_install_json})' "$$SCALA_LIBRARY_MAVEN_VERSION"
check 'org.scala-lang:scala-reflect (in {maven_install_json})' "$$SCALA_REFLECT_MAVEN_VERSION"
""".format(
expected_version = scala_version,
jq = "@jq_dev_env//:bin/jq",
maven_install_json = "//:maven_install_{}.json".format(scala_major_version),
scala_bin = "@scala_nix//:bin/scala",
scala_compiler = "@maven//:org_scala_lang_scala_compiler",
scala_library = "@maven//:org_scala_lang_scala_library",
scala_reflect = "@maven//:org_scala_lang_scala_reflect",
),
data = [
"//:maven_install_{}.json".format(scala_major_version),
"@jq_dev_env//:bin/jq",
"@maven//:org_scala_lang_scala_compiler",
"@maven//:org_scala_lang_scala_library",
"@maven//:org_scala_lang_scala_reflect",
"@scala_nix//:bin/scala",
],
) if not is_windows else None