[8.8.0] Reland: Bootstrap the distfile test with a hermetic JDK 21 (https://g… (#30533)

…ithub.com/bazelbuild/bazel/pull/30494)

Relands c143d206f6220f6501c07aa83390e68bf5b7657c (#30473), which was
rolled back in 8fd8ead59547c686ebccc418b1dc6409ed03ba96 because it broke
the macOS postsubmit.

The bootstrap prerequisites documented at
https://bazel.build/install/compile-source#bootstrap-unix-prereq require
a JDK 21, but `bazel_bootstrap_distfile_test` bootstrapped with
whichever JDK `scripts/bootstrap/buildenv.sh` happened to discover on
the machine running the test: `JAVA_HOME` if it is set, otherwise
`/usr/libexec/java_home -v 21+` on macOS or the `javac` on `PATH` on
Linux.

This adds `@rules_java//toolchains:remotejdk_21` to the runfiles of both
distfile tests and points `JAVA_HOME` at it via `setup_javabase`.
`compile.sh` runs the entire bootstrap as `"${JAVA_HOME}/bin/java" ...
--default_system_javabase="${JAVA_HOME}"`, so this single export makes
both the JVM running the bootstrapping Bazel and `@local_jdk` hermetic
and the host JDK discovery in `buildenv.sh` is never reached. The test
additionally asserts that the runtime is a JDK 21, so that it keeps
verifying the documented prerequisite instead of silently passing on a
newer host JDK.

The macOS CI machines have `JAVA_TOOL_OPTIONS` set, which makes the JVM
print an extra line in front of the `javac -version` output, so the new
JDK 21 assertion rejected a perfectly good JDK 21:

```
ERROR[bazel_bootstrap_distfile_test] expected a JDK 21 in JAVA_HOME, but got 'Picked up JAVA_TOOL_OPTIONS: -Djava.net.preferIPv6Addresses=true
javac 21.0.9'
```

`JAVA_TOOL_OPTIONS` and `_JAVA_OPTIONS` are now unset for that check,
just like `scripts/bootstrap/compile.sh` already does for the bootstrap
itself. Nothing else differs from the original commit.

On a CI machine whose default `javac` is 17, the test fails up front
with `ERROR: JDK version (1.17) is lower than 21, please set
$JAVA_HOME.`, which has nothing to do with the change under test. On a
machine with a JDK newer than 21 it instead exercises a configuration
that the installation instructions do not describe.

No

- [ ] I have added tests for the new use cases (if any). — N/A, this is
a test-only change.
- [ ] I have updated the documentation (if applicable). — N/A.

RELNOTES: None

Closes #30494.

PiperOrigin-RevId: 955890390
Change-Id: Ie5c0a30115f63a80009a7270d47f94b0168fc6e2

<!--
Thank you for contributing to Bazel!
Please read the contribution guidelines:
https://bazel.build/contribute.html
-->

### Description
<!--
Please provide a brief summary of the changes in this PR.
-->

### Motivation
<!--
Why is this change important? Does it fix a specific bug or add a new
feature?
If this PR fixes an existing issue, please link it here (e.g. "Fixes
#1234").
-->

### Build API Changes
<!--
Does this PR affect the Build API? (e.g. Starlark API, providers,
command-line flags, native rules)
If yes, please answer the following:
1. Has this been discussed in a design doc or issue? (Please link it)
2. Is the change backward compatible?
3. If it's a breaking change, what is the migration plan?
-->

No

### Checklist

- [ ] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

### Release Notes

<!--
If this is a new feature, please add 'RELNOTES[NEW]: <description>'
here.
If this is a breaking change, please add 'RELNOTES[INC]: <reason>' here.
If this change should be mentioned in release notes, please add
'RELNOTES: <reason>' here.
-->

RELNOTES: None

Commit
https://github.com/bazelbuild/bazel/commit/ec3c34a7e9a0223d135330d1edab4e2d1280329b
and
https://github.com/bazelbuild/bazel/pull/30533/commits/3a710fdb69c937152b12663ba578b44b4ad664df

---------

Co-authored-by: Xdng Yng <wyverald@gmail.com>
Co-authored-by: hvd <hvd@google.com>
8 files changed
tree: e1d2051d43e2cdf456865254e0b26af125aee7de
  1. .bazelci/
  2. .github/
  3. examples/
  4. scripts/
  5. site/
  6. src/
  7. third_party/
  8. tools/
  9. .bazelrc
  10. .bazelversion
  11. .gitattributes
  12. .gitignore
  13. AUTHORS
  14. bazel_downloader.cfg
  15. BUILD
  16. CHANGELOG.md
  17. CODE_OF_CONDUCT.md
  18. CODEOWNERS
  19. combine_distfiles.py
  20. combine_distfiles_to_tar.sh
  21. compile.sh
  22. CONTRIBUTING.md
  23. CONTRIBUTORS
  24. distdir.bzl
  25. extensions.bzl
  26. LICENSE
  27. maven_install.json
  28. MODULE.bazel
  29. MODULE.bazel.lock
  30. README.md
  31. repositories.bzl
  32. requirements.txt
  33. SECURITY.md
  34. workspace_deps.bzl
README.md

Bazel

{Fast, Correct} - Choose two

Build and test software of any size, quickly and reliably.

  • Speed up your builds and tests: Bazel rebuilds only what is necessary. With advanced local and distributed caching, optimized dependency analysis and parallel execution, you get fast and incremental builds.

  • One tool, multiple languages: Build and test Java, C++, Android, iOS, Go, and a wide variety of other language platforms. Bazel runs on Windows, macOS, and Linux.

  • Scalable: Bazel helps you scale your organization, codebase, and continuous integration solution. It handles codebases of any size, in multiple repositories or a huge monorepo.

  • Extensible to your needs: Easily add support for new languages and platforms with Bazel's familiar extension language. Share and re-use language rules written by the growing Bazel community.

Getting Started

Documentation

Reporting a Vulnerability

To report a security issue, please email security@bazel.build with a description of the issue, the steps you took to create the issue, affected versions, and, if known, mitigations for the issue. Our vulnerability management team will respond within 3 working days of your email. If the issue is confirmed as a vulnerability, we will open a Security Advisory. This project follows a 90 day disclosure timeline.

Contributing to Bazel

See CONTRIBUTING.md

Build status