Skip to content

Commit 3a90803

Browse files
hvadehracopybara-github
authored andcommitted
Add test for remote_java_tools configs
PiperOrigin-RevId: 644650446 Change-Id: I2561f4583a116326e4ede6c76f94bc92abe00148
1 parent a5c7aec commit 3a90803

3 files changed

Lines changed: 54 additions & 3 deletions

File tree

java/repositories.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ load("//toolchains:jdk_build_file.bzl", "JDK_BUILD_TEMPLATE")
2020
load("//toolchains:local_java_repository.bzl", "local_java_repository")
2121
load("//toolchains:remote_java_repository.bzl", "remote_java_repository")
2222

23-
_JAVA_TOOLS_CONFIG = {
23+
# visible for tests
24+
JAVA_TOOLS_CONFIG = {
2425
"version": "v13.6.1",
2526
"release": "true",
2627
"artifacts": {
@@ -54,7 +55,7 @@ _JAVA_TOOLS_CONFIG = {
5455

5556
def java_tools_repos():
5657
""" Declares the remote java_tools repositories """
57-
for name, config in _JAVA_TOOLS_CONFIG["artifacts"].items():
58+
for name, config in JAVA_TOOLS_CONFIG["artifacts"].items():
5859
maybe(
5960
http_archive,
6061
name = "remote_" + name,

test/BUILD.bazel

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
load("//java:repositories.bzl", "REMOTE_JDK_CONFIGS")
14+
load("//java:repositories.bzl", "JAVA_TOOLS_CONFIG", "REMOTE_JDK_CONFIGS")
1515
load(":check_remotejdk_configs_match.bzl", "validate_configs")
1616

1717
sh_test(
@@ -30,4 +30,18 @@ sh_test(
3030
],
3131
)
3232

33+
sh_test(
34+
name = "check_remote_java_tools_configs_test",
35+
srcs = ["check_remote_java_tools_configs.sh"],
36+
args = [
37+
",".join([
38+
name,
39+
config["mirror_url"],
40+
config["github_url"],
41+
config["sha"],
42+
])
43+
for name, config in JAVA_TOOLS_CONFIG["artifacts"].items()
44+
],
45+
)
46+
3347
validate_configs()
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2024 The Bazel Authors. All rights reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
echo "Checking hashes for $# configs"
17+
18+
function download_and_check_hash() {
19+
name=$1
20+
url=$2
21+
hash=$3
22+
TMP_FILE=$(mktemp -q /tmp/remotejavatools.XXXXXX)
23+
echo "fetching $name from $url to ${TMP_FILE}"
24+
curl --silent -o ${TMP_FILE} -L "$url"
25+
actual_hash=`sha256sum ${TMP_FILE} | cut -d' ' -f1`
26+
if [ "${hash}" != "${actual_hash}" ]; then
27+
echo "ERROR: wrong hash for ${name}! wanted: ${hash}, got: ${actual_hash}"
28+
exit 1
29+
fi
30+
}
31+
32+
for config in "$@"; do
33+
IFS=, read -r name mirror_url gh_url hash <<< "${config}"
34+
download_and_check_hash ${name} ${mirror_url} ${hash}
35+
download_and_check_hash ${name} ${gh_url} ${hash}
36+
done

0 commit comments

Comments
 (0)