daml/bazel_tools/BUILD.bazel
Moisés Ackerman 4794454a70
Platform independence pre-check (#17955)
* Rename //bazel_tools:match-{cabal=>golden}-file

* Generate and check hash file for contents of //compiler/damlc/tests:platform-independence.dar

* Add pre-commit hook to test //compiler/damlc/tests:platform-independence-dar-hash-file-matches

* Print info when //bazel_tools:match-golden-file fails

* platform-independence-dar-check pre-commit hook runs depending on env var

* Skip platform-independence-check if RUN_PLATFORM_INDEPENDENCE_CHECK is unset

* Document dar_hash_file rules

* move platform-independence-checks warning to .envrc

* implement generate_dar_hash_file genrule in python

in particular, this allows us to produce the same output on all platforms

* fix windows

* Update rules_daml/daml.bzl

* bytes.replace does not operate in place
2023-12-07 18:18:24 +01:00

92 lines
3.4 KiB
Python

# Copyright (c) 2023 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",
"distribute_jar_cleanup.sh",
],
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
filegroup(
name = "match-golden-file",
srcs = glob(["match-golden-file.sh"]),
visibility = ["//visibility:public"],
)