Skip to content

Commit 8a5bd6f

Browse files
committed
Set the right JDK version for *_for_testing repos
Removes the `build_file` parameter from `remotejdk*_for_testing` repositories in `WORKSPACE`. Updates `dist_http_archive` to parse the correct JDK version from the repo name and then generate a `BUILD` file from `JDK_BUILD_TEMPLATE` instead. Fixes several tests broken by incompatible JVM flags by ensuring that the `remotejdk` repos' `//:jdk` targets set the correct JDK version. Setting `.bazelci/presubmit.yml` Linux jobs to use Java 11 images enabled tests to pass on those platforms without this change. This was because the `--java_runtime_version` happened to match the system JDK version. Specifing the macOS and Windows build images isn't possible, necessitating the changes in this commit to fix tests broken on those platforms. --- The following series of commits introduced the `remotejdk*_for_testing` repos and a mechanism to have the "inner" Bazel reuse the "outer" Bazel's copies: - Add external repos required by tests and a "fetch all" filegroup. commit 17506af - Allow overriding all external repositories used by our integration tests. commit 99c0e6d - Move JDK repo definitions to distdir_deps.bzl commit b741116 In `.bazelci/presubmit.yml`, every job sets `--test_env=TEST_REPOSITORY_HOME=$OUTPUT_BASE/external`. This causes `testenv.sh.tmpl` to override certain repositories with their `_for_testing` variants: ```sh if [[ -n ${TEST_REPOSITORY_HOME:-} ]]; then echo "testenv.sh: Using shared repositories from $TEST_REPOSITORY_HOME." repos=( # ... "remotejdk17_macos_for_testing" # ... ) for repo in "${repos[@]}"; do reponame="${repo%"_for_testing"}" echo "common --override_repository=$reponame=$TEST_REPOSITORY_HOME/$repo" >> $TEST_TMPDIR/bazelrc done fi ``` The `WORKSPACE` file contained entries like the following, created before `@local_jdk//:BUILD.bazel` contained an explicit JDK version for its `//:jdk` target: ```py dist_http_archive( name = "remotejdk11_macos_for_testing", build_file = "@local_jdk//:BUILD.bazel", patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE, patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN, ) ``` Later, these commits added the JDK version to `JdkRuntimeInfo`: - Add version to JavaRuntimeInfo. commit 7556e11 - [6.2.0] Add version to JavaRuntimeInfo (#17913) commit 2d04c91 However, they didn't update the `dist_http_archive` entries to adjust their `build_file` parameters accordingly. As a result, the `remotejdk` repos used by the "inner" Bazel during tests all specified the same JDK version as the system JDK. Bazel resolved the correct toolchain for `--java_runtime_version`, which would contain the correct Java binaries, but contained the system JDK `version` parameter. This caused `BazelJavaSemantics` to emit JVM flags for the _wrong_ JDK version. This, in turn, broke test binaries when they ran under the _correct_ `java` binary from the JDK that differed from the system JDK version.
1 parent 58a0471 commit 8a5bd6f

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

WORKSPACE

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -433,64 +433,55 @@ dist_http_archive(
433433

434434
dist_http_archive(
435435
name = "remotejdk11_linux_for_testing",
436-
build_file = "@local_jdk//:BUILD.bazel",
437436
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
438437
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
439438
)
440439

441440
dist_http_archive(
442441
name = "remotejdk11_linux_aarch64_for_testing",
443-
build_file = "@local_jdk//:BUILD.bazel",
444442
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
445443
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
446444
)
447445

448446
dist_http_archive(
449447
name = "remotejdk11_linux_ppc64le_for_testing",
450-
build_file = "@local_jdk//:BUILD.bazel",
451448
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
452449
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
453450
)
454451

455452
dist_http_archive(
456453
name = "remotejdk11_linux_s390x_for_testing",
457-
build_file = "@local_jdk//:BUILD.bazel",
458454
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
459455
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
460456
)
461457

462458
dist_http_archive(
463459
name = "remotejdk11_macos_for_testing",
464-
build_file = "@local_jdk//:BUILD.bazel",
465460
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
466461
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
467462
)
468463

469464
dist_http_archive(
470465
name = "remotejdk11_macos_aarch64_for_testing",
471-
build_file = "@local_jdk//:BUILD.bazel",
472466
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
473467
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
474468
)
475469

476470
dist_http_archive(
477471
name = "remotejdk11_win_for_testing",
478-
build_file = "@local_jdk//:BUILD.bazel",
479472
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
480473
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
481474
)
482475

483476
dist_http_archive(
484477
name = "remotejdk11_win_arm64_for_testing",
485-
build_file = "@local_jdk//:BUILD.bazel",
486478
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
487479
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
488480
)
489481

490482
[
491483
dist_http_archive(
492484
name = "remotejdk%s_%s_for_testing" % (version, os),
493-
build_file = "@local_jdk//:BUILD.bazel",
494485
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
495486
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
496487
)

distdir.bzl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
load("//:distdir_deps.bzl", "DEPS_BY_NAME")
1717
load("//tools/build_defs/repo:http.bzl", "http_archive", "http_file", "http_jar")
18+
load("//tools/jdk:jdk_build_file.bzl", "JDK_BUILD_TEMPLATE")
1819

1920
_BUILD = """
2021
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
@@ -91,6 +92,15 @@ def dist_http_archive(name, **kwargs):
9192
kwargs["patches"] = info.get("patches")
9293
if "strip_prefix" not in kwargs:
9394
kwargs["strip_prefix"] = info.get("strip_prefix")
95+
96+
name_without_remotejdk_prefix = name.removeprefix("remotejdk")
97+
if name_without_remotejdk_prefix != name:
98+
kwargs["build_file_content"] = JDK_BUILD_TEMPLATE.replace(
99+
"___RUNTIME_VERSION___",
100+
name_without_remotejdk_prefix.split("_", 1)[0],
101+
)
102+
kwargs.pop("build_file", default=None)
103+
94104
http_archive(
95105
name = name,
96106
sha256 = info["sha256"],

0 commit comments

Comments
 (0)