Upgrade bazel to 5.0.0

These are the commands I used to generate the bazel xz file:

    $ wget 'https://github.com/bazelbuild/bazel/releases/download/5.0.0/bazel-5.0.0-linux-x86_64'
    $ xz bazel-5.0.0-linux-x86_64
    $ mv bazel-5.0.0-linux-x86_64.xz bazel_5.0.0.xz

I had to tweak `.bazelrc` a bit because some options were promoted
from experimental status to non-experimental status. A couple of
incompatible flags are gone now too.

I had to change some of our Java setup as per
https://github.com/bazelbuild/bazel/issues/7849. It's not obvious to
me that I did it correctly, but bazel doesn't seem to complain about
the new options I added.

The `--watchfs` in `tools/ci/buildkite.yaml` was generating this
error:

    ERROR: --watchfs as startup option is deprecated, replace it with the equivalent command option. For example, instead of 'bazel --watchfs build //foo', run 'bazel build --watchfs //foo'.

As far as I can tell, the `common --watchfs` option in our `.bazelrc`
should cover this. So I deleted the option from our buildkite config.

Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Change-Id: Ie85e68a1437c924d6dd4e7c4089e7d3d4e4cab90
diff --git a/.bazelrc b/.bazelrc
index 1c6dbde..be65a4b 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -15,7 +15,6 @@
 build --strip=never
 
 build --noincompatible_disable_nocopts
-common --noincompatible_restrict_string_escapes
 
 # Use the malloc we want.
 build --custom_malloc=//tools/cpp:malloc
@@ -78,7 +77,7 @@
 # Dump the output of the failing test to stdout.
 test --test_output=errors
 
-build --experimental_sandbox_base=/dev/shm/
+build --sandbox_base=/dev/shm/
 build --experimental_multi_threaded_digest
 
 build --sandbox_fake_hostname=true
@@ -92,7 +91,7 @@
 startup --host_jvm_args=-Dbazel.DigestFunction=SHA256
 
 build --spawn_strategy=linux-sandbox
-build --experimental_sandbox_default_allow_network=false
+build --sandbox_default_allow_network=false
 
 build --strategy=TypeScriptCompile=worker --strategy=AngularTemplateCompile=worker
 
@@ -100,7 +99,7 @@
 # Note that this doesn't quite work fully, but it should. See
 # https://github.com/bazelbuild/bazel/issues/6341 for ongoing discussion with
 # upstream about this.
-build --javabase=@openjdk_linux_archive//:jdk --host_javabase=@openjdk_linux_archive//:jdk
+build --java_runtime_version=openjdk_9 --tool_java_runtime_version=openjdk_9
 
 # Prevent falling back to the host JDK.
 startup --noautodetect_server_javabase
diff --git a/WORKSPACE b/WORKSPACE
index 1ea9cce..6ed6b7e 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -2,6 +2,7 @@
 
 load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
 load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
+load("@bazel_tools//tools/jdk:remote_java_repository.bzl", "remote_java_repository")
 load(
     "//debian:python.bzl",
     python_debs = "files",
@@ -614,20 +615,19 @@
 )
 
 # Java9 JDK.
-http_archive(
+remote_java_repository(
     name = "openjdk_linux_archive",
-    build_file_content = """
-java_runtime(
-    name = 'jdk',
-    srcs = glob(['**']),
-    visibility = ['//visibility:public'],
-)
-""",
+    exec_compatible_with = [
+        "@platforms//cpu:x86_64",
+        "@platforms//os:linux",
+    ],
+    prefix = "openjdk",
     sha256 = "f27cb933de4f9e7fe9a703486cf44c84bc8e9f138be0c270c9e5716a32367e87",
     strip_prefix = "zulu9.0.7.1-jdk9.0.7-linux_x64-allmodules",
     urls = [
         "https://www.frc971.org/Build-Dependencies/zulu9.0.7.1-jdk9.0.7-linux_x64-allmodules.tar.gz",
     ],
+    version = "9",
 )
 
 local_repository(
diff --git a/tools/bazel b/tools/bazel
index e72b44e..da9008b 100755
--- a/tools/bazel
+++ b/tools/bazel
@@ -24,7 +24,7 @@
   exec "${BAZEL_OVERRIDE}" "$@"
 fi
 
-readonly VERSION="4.2.2"
+readonly VERSION="5.0.0"
 
 readonly DOWNLOAD_DIR="${HOME}/.cache/bazel"
 # Directory to unpack bazel into.  This must change whenever bazel changes.
diff --git a/tools/ci/buildkite.yaml b/tools/ci/buildkite.yaml
index c4af4a4..e20c523 100644
--- a/tools/ci/buildkite.yaml
+++ b/tools/ci/buildkite.yaml
@@ -1,5 +1,5 @@
 env:
-  STARTUP: --max_idle_secs=0 --watchfs
+  STARTUP: --max_idle_secs=0
   COMMON: -c opt --stamp=no --curses=yes --symlink_prefix=/ --disk_cache=~/.cache/bazel/disk_cache/ --repo_env=FRC971_RUNNING_IN_CI=1
   TARGETS: //... @com_github_google_glog//... @com_google_ceres_solver//... @com_github_rawrtc_rawrtc//... @com_google_googletest//...
   M4F_TARGETS: //...