add ubuntu1604 and ubuntu1804 as rbe platforms
  - use rbe_autoconfig
  - mark slow tests as highcpu

Closes #8852.

PiperOrigin-RevId: 257594268
diff --git a/.bazelrc b/.bazelrc
index 5a0bfe2..1ad4a27 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -1,30 +1,45 @@
-# Configuration to build and test Bazel itself on RBE.
-build:remote --host_javabase=@bazel_rbe_toolchains//configs/bazel_0.26.0/bazel-ubuntu1804/java:jdk
-build:remote --javabase=@bazel_rbe_toolchains//configs/bazel_0.26.0/bazel-ubuntu1804/java:jdk
-build:remote --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
-build:remote --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
-build:remote --crosstool_top=@bazel_rbe_toolchains//configs/bazel_0.26.0/bazel-ubuntu1804/cc:toolchain
-
-build:remote --extra_toolchains=@bazel_rbe_toolchains//configs/bazel_0.26.0/bazel-ubuntu1804/config:cc-toolchain
-build:remote --extra_execution_platforms=@bazel_rbe_toolchains//configs/bazel_0.26.0/bazel-ubuntu1804:default_platform
-build:remote --extra_execution_platforms=//:rbe_highcpu_platform
-build:remote --host_platform=@bazel_rbe_toolchains//configs/bazel_0.26.0/bazel-ubuntu1804:default_platform
-build:remote --platforms=@bazel_rbe_toolchains//configs/bazel_0.26.0/bazel-ubuntu1804:default_platform
-
- # TODO(ishikhman): Remove this flag after upgrading Bazel to 0.27.0
-build:remote --incompatible_list_based_execution_strategy_selection
-
-build:remote --define=EXECUTOR=remote
-
-build:remote --remote_instance_name=projects/bazel-untrusted/instances/default_instance
-build:remote --remote_executor=grpcs://remotebuildexecution.googleapis.com
-build:remote --remote_timeout=600
-build:remote --google_default_credentials
-
-build:remote --jobs=100
-build:remote --action_env=PATH=/bin:/usr/bin:/usr/local/bin
-build:remote --disk_cache=
-
 # Flags for Android
-build:remote --noexperimental_check_desugar_deps # Workaround for singlejar incompatibility with RBE
 build --android_aapt=aapt2 # Turn aapt2 on by default for Bazel's own Android builds and tests.
+
+# Shared configuration flags to build and test Bazel on RBE.
+build:remote_shared --define=EXECUTOR=remote
+build:remote_shared --remote_instance_name=projects/bazel-untrusted/instances/default_instance
+build:remote_shared --remote_executor=grpcs://remotebuildexecution.googleapis.com
+build:remote_shared --remote_timeout=600
+build:remote_shared --google_default_credentials
+build:remote_shared --jobs=100
+build:remote_shared --action_env=PATH=/bin:/usr/bin:/usr/local/bin
+build:remote_shared --disk_cache=
+# Workaround for singlejar incompatibility with RBE
+build:remote_shared --noexperimental_check_desugar_deps
+
+# Configuration to build and test Bazel on RBE on Ubuntu 18.04 with Java 11
+build:ubuntu1804_java11 --host_javabase=@rbe_ubuntu1804_java11//java:jdk
+build:ubuntu1804_java11 --javabase=@rbe_ubuntu1804_java11//java:jdk
+build:ubuntu1804_java11 --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_java9
+build:ubuntu1804_java11 --java_toolchain=@bazel_tools//tools/jdk:toolchain_java9
+build:ubuntu1804_java11 --crosstool_top=@rbe_ubuntu1804_java11//cc:toolchain
+build:ubuntu1804_java11 --extra_toolchains=@rbe_ubuntu1804_java11//config:cc-toolchain
+build:ubuntu1804_java11 --extra_execution_platforms=//:rbe_ubuntu1804_java11_platform
+build:ubuntu1804_java11 --extra_execution_platforms=//:rbe_ubuntu1804_java11_highcpu_platform
+build:ubuntu1804_java11 --host_platform=//:rbe_ubuntu1804_java11_platform
+build:ubuntu1804_java11 --platforms=//:rbe_ubuntu1804_java11_platform
+build:ubuntu1804_java11 --config=remote_shared
+
+# Configuration to build and test Bazel on RBE on Ubuntu 18.04 with Java 11
+build:ubuntu1604_java8 --host_javabase=@rbe_ubuntu1604_java8//java:jdk
+build:ubuntu1604_java8 --javabase=@rbe_ubuntu1604_java8//java:jdk
+build:ubuntu1604_java8 --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
+build:ubuntu1604_java8 --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
+build:ubuntu1604_java8 --crosstool_top=@rbe_ubuntu1604_java8//cc:toolchain
+build:ubuntu1604_java8 --extra_toolchains=@rbe_ubuntu1604_java8//config:cc-toolchain
+build:ubuntu1604_java8 --extra_execution_platforms=//:rbe_ubuntu1604_java8_platform
+build:ubuntu1604_java8 --extra_execution_platforms=//:rbe_ubuntu1604_java8_highcpu_platform
+build:ubuntu1604_java8 --host_platform=//:rbe_ubuntu1604_java8_platform
+build:ubuntu1604_java8 --platforms=//:rbe_ubuntu1604_java8_platform
+build:ubuntu1604_java8 --config=remote_shared
+
+# Alias
+build:remote --config=ubuntu1604_java8
+
+
diff --git a/BUILD b/BUILD
index 311525e..95af0d0 100644
--- a/BUILD
+++ b/BUILD
@@ -154,19 +154,43 @@
     parents = ["@bazel_tools//platforms:host_platform"],
 )
 
-# The highcpu RBE platform where heavy actions run on. In order to
-# use this platform add the highcpu_machine constraint to your target.
-platform(
-    name = "rbe_highcpu_platform",
-    constraint_values = [
-        "//:highcpu_machine",
-    ],
-    parents = ["@bazel_rbe_toolchains//configs/bazel_0.25.0/bazel-ubuntu1804:default_platform"],
-    remote_execution_properties = """
-        {PARENT_REMOTE_EXECUTION_PROPERTIES}
-        properties: {
-          name: "gceMachineType"
-          value: "n1-highcpu-32"
-        }
-        """,
-)
+REMOTE_PLATFORMS = ("rbe_ubuntu1604_java8", "rbe_ubuntu1804_java11")
+
+[
+    platform(
+        name = platform_name + "_platform",
+        parents = ["@" + platform_name + "//config:platform"],
+        remote_execution_properties = """
+            {PARENT_REMOTE_EXECUTION_PROPERTIES}
+            properties: {
+                name: "dockerNetwork"
+                value: "standard"
+            }
+            properties: {
+                name: "dockerPrivileged"
+                value: "true"
+            }
+            """,
+    )
+    for platform_name in REMOTE_PLATFORMS
+]
+
+[
+    # The highcpu RBE platform where heavy actions run on. In order to
+    # use this platform add the highcpu_machine constraint to your target.
+    platform(
+        name = platform_name + "_highcpu_platform",
+        constraint_values = [
+            "//:highcpu_machine",
+        ],
+        parents = ["//:" + platform_name + "_platform"],
+        remote_execution_properties = """
+            {PARENT_REMOTE_EXECUTION_PROPERTIES}
+            properties: {
+                name: "gceMachineType"
+                value: "n1-highcpu-16"
+            }
+            """,
+    )
+    for platform_name in REMOTE_PLATFORMS
+]
diff --git a/WORKSPACE b/WORKSPACE
index 04401d4..95cc34a2 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -123,6 +123,8 @@
         "7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip",
         # bazelbuild/rules_cc
         "0d5f3f2768c6ca2faca0079a997a97ce22997a0c.zip",
+        # bazelbuild/bazel-toolchains
+        "0.27.1.tar.gz",
     ],
     dirname = "derived/distdir",
     sha256 = {
@@ -135,13 +137,15 @@
         "1ca560df1cf6e280f987af2f8d08a5edc7ac6b54.tar.gz": "3ca1b3d453a977aeda60dd335feb812771addfd0d0c61751b34b9681aa4d6534",
         "8ccf4f1c351928b55d5dddf3672e3667f6978d60.tar.gz": "d868ce50d592ef4aad7dec4dd32ae68d2151261913450fac8390b3fd474bb898",
         "0.16.2.zip": "9b72bb0aea72d7cbcfc82a01b1e25bf3d85f791e790ddec16c65e2d906382ee0",
-        "android_tools_pkg-0.7.tar.gz": "a8e48f2fdee2c34b31f45bd47ce050a75ac774f19e0a1f6694fa49fc11d88718", # built at 6bb5ae2a8353d75867ac9136d374df7916450449
+        "android_tools_pkg-0.7.tar.gz": "a8e48f2fdee2c34b31f45bd47ce050a75ac774f19e0a1f6694fa49fc11d88718",  # built at 6bb5ae2a8353d75867ac9136d374df7916450449
         # bazelbuild/platforms
         "441afe1bfdadd6236988e9cac159df6b5a9f5a98.zip": "a07fe5e75964361885db725039c2ba673f0ee0313d971ae4f50c9b18cd28b0b5",
         # bazelbuild/rules_java
         "7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip": "bc81f1ba47ef5cc68ad32225c3d0e70b8c6f6077663835438da8d5733f917598",
         # bazelbuild/rules_cc
         "0d5f3f2768c6ca2faca0079a997a97ce22997a0c.zip": "36fa66d4d49debd71d05fba55c1353b522e8caef4a20f8080a3d17cdda001d89",
+        # bazelbuild/bazel-toolchains
+        "0.27.1.tar.gz": "28cb3666da80fbc62d4c46814f5468dd5d0b59f9064c0b933eee3140d706d330",
     },
     urls = {
         "e0b0291b2c51fbe5a7cfa14473a1ae850f94f021.zip": [
@@ -194,6 +198,11 @@
             "https://mirror.bazel.build/github.com/bazelbuild/rules_cc/archive/0d5f3f2768c6ca2faca0079a997a97ce22997a0c.zip",
             "https://github.com/bazelbuild/rules_cc/archive/0d5f3f2768c6ca2faca0079a997a97ce22997a0c.zip",
         ],
+        # bazelbuild/bazel-toolchains
+        "0.27.1.tar.gz": [
+            "https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/archive/0.27.1.tar.gz",
+            "https://github.com/bazelbuild/bazel-toolchains/archive/0.27.1.tar.gz",
+        ],
     },
 )
 
@@ -349,22 +358,30 @@
 
 http_archive(
     name = "bazel_toolchains",
-    sha256 = "67335b3563d9b67dc2550b8f27cc689b64fadac491e69ce78763d9ba894cc5cc",
-    strip_prefix = "bazel-toolchains-cddc376d428ada2927ad359211c3e356bd9c9fbb",
+    sha256 = "28cb3666da80fbc62d4c46814f5468dd5d0b59f9064c0b933eee3140d706d330",
+    strip_prefix = "bazel-toolchains-0.27.1",
     urls = [
-        "https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/archive/cddc376d428ada2927ad359211c3e356bd9c9fbb.tar.gz",
-        "https://github.com/bazelbuild/bazel-toolchains/archive/cddc376d428ada2927ad359211c3e356bd9c9fbb.tar.gz",
+        "https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/archive/0.27.1.tar.gz",
+        "https://github.com/bazelbuild/bazel-toolchains/archive/0.27.1.tar.gz",
     ],
 )
 
-http_archive(
-    name = "bazel_rbe_toolchains",
-    sha256 = "e2b8644caa15235a488e831264e5dcb014e2cdf3b697319bc1e9d6b0fff0b4b9",
-    strip_prefix = "bazel_rbe_toolchains-01529a65d21abdf71635ff0c2472043a567ecded",
-    urls = [
-        "https://mirror.bazel.build/github.com/buchgr/bazel_rbe_toolchains/archive/01529a65d21abdf71635ff0c2472043a567ecded.tar.gz",
-        "https://github.com/buchgr/bazel_rbe_toolchains/archive/01529a65d21abdf71635ff0c2472043a567ecded.tar.gz",
-    ],
+load("@bazel_toolchains//rules:rbe_repo.bzl", "rbe_autoconfig")
+
+rbe_autoconfig(
+    name = "rbe_ubuntu1804_java11",
+    detect_java_home = True,
+    registry = "gcr.io",
+    repository = "bazel-public/ubuntu1804/bazel",
+    tag = "java11",
+)
+
+rbe_autoconfig(
+    name = "rbe_ubuntu1604_java8",
+    detect_java_home = True,
+    registry = "gcr.io",
+    repository = "bazel-public/ubuntu1604/bazel",
+    tag = "java8",
 )
 
 # Creates toolchain configuration for remote execution with BuildKite CI
@@ -472,7 +489,7 @@
         "zulu11.29.3-ca-jdk11.0.2-linux_x64.tar.gz": "f3f44b6235508e87b760bf37a49e186cc1fa4e9cd28384c4dbf5a33991921e08",
         "zulu11.29.3-ca-jdk11.0.2-macosx_x64.zip": "059f8e3484bf07b63a8f2820d5f528f473eff1befdb1896ee4f8ff06be3b8d8f",
         "zulu11.29.3-ca-jdk11.0.2-win_x64.zip": "e1f5b4ce1b9148140fae2fcfb8a96d1c9b7eac5b8df0e13fbcad9b8561284880",
-        "android_tools_pkg-0.7.tar.gz": "a8e48f2fdee2c34b31f45bd47ce050a75ac774f19e0a1f6694fa49fc11d88718", # built at 6bb5ae2a8353d75867ac9136d374df7916450449
+        "android_tools_pkg-0.7.tar.gz": "a8e48f2fdee2c34b31f45bd47ce050a75ac774f19e0a1f6694fa49fc11d88718",  # built at 6bb5ae2a8353d75867ac9136d374df7916450449
         # bazelbuild/platforms
         "441afe1bfdadd6236988e9cac159df6b5a9f5a98.zip": "a07fe5e75964361885db725039c2ba673f0ee0313d971ae4f50c9b18cd28b0b5",
         # bazelbuild/rules_java
@@ -511,7 +528,7 @@
         # bazelbuild/rules_java
         "7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip": [
             "https://mirror.bazel.build/github.com/bazelbuild/rules_java/archive/7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip",
-            "https://github.com/bazelbuild/rules_java/archive/7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip"
+            "https://github.com/bazelbuild/rules_java/archive/7cf3cefd652008d0a64a419c34c13bdca6c8f178.zip",
         ],
         # bazelbuild/rules_cc
         "0d5f3f2768c6ca2faca0079a997a97ce22997a0c.zip": [
@@ -581,11 +598,11 @@
 http_archive(
     name = "platforms",
     sha256 = "a07fe5e75964361885db725039c2ba673f0ee0313d971ae4f50c9b18cd28b0b5",
+    strip_prefix = "platforms-441afe1bfdadd6236988e9cac159df6b5a9f5a98",
     urls = [
         "https://mirror.bazel.build/github.com/bazelbuild/platforms/archive/441afe1bfdadd6236988e9cac159df6b5a9f5a98.zip",
         "https://github.com/bazelbuild/platforms/archive/441afe1bfdadd6236988e9cac159df6b5a9f5a98.zip",
     ],
-    strip_prefix = "platforms-441afe1bfdadd6236988e9cac159df6b5a9f5a98"
 )
 
 http_archive(
diff --git a/src/test/shell/bazel/BUILD b/src/test/shell/bazel/BUILD
index 6675f7458..e061999 100644
--- a/src/test/shell/bazel/BUILD
+++ b/src/test/shell/bazel/BUILD
@@ -193,6 +193,7 @@
         "//src/test/shell/bazel/testdata:jdk_http_archives_filegroup",
         "@bazel_tools//tools/bash/runfiles",
     ],
+    exec_compatible_with = ["//:highcpu_machine"],
 )
 
 sh_test(
@@ -220,6 +221,7 @@
         "//src/test/shell/bazel/testdata:jdk_http_archives_filegroup",
         "@bazel_tools//tools/bash/runfiles",
     ],
+    exec_compatible_with = ["//:highcpu_machine"],
 )
 
 JAVA_VERSIONS = ("9", "10", "11", "12")
@@ -248,6 +250,7 @@
             "//src/test/shell/bazel/testdata:jdk_http_archives_filegroup",
             "@bazel_tools//tools/bash/runfiles",
         ],
+        exec_compatible_with = ["//:highcpu_machine"],
     )
     for java_version in JAVA_VERSIONS
 ]