Update Protobuf to 3.11.3

Closes #10651.

PiperOrigin-RevId: 294910709
diff --git a/WORKSPACE b/WORKSPACE
index 5826aa9..8b97995 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -55,12 +55,6 @@
     actual = "//third_party:guava",
 )
 
-# Used by //third_party/protobuf:protobuf_python
-bind(
-    name = "six",
-    actual = "//third_party/py/six",
-)
-
 http_archive(
     name = "bazel_j2objc",
     # Computed using "shasum -a 256 j2objc-2.5.zip"
@@ -99,10 +93,18 @@
     actual = "@bazel_tools//tools/objc:xcrunwrapper",
 )
 
-new_local_repository(
+http_archive(
     name = "com_google_protobuf",
-    build_file = "./third_party/protobuf/3.6.1/BUILD",
-    path = "./third_party/protobuf/3.6.1/",
+    patch_args = ["-p1"],
+    patches = ["@io_bazel//third_party/protobuf:3.11.3.patch"],
+    patch_cmds = EXPORT_WORKSPACE_IN_BUILD_FILE,
+    patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_FILE_WIN,
+    sha256 = "cf754718b0aa945b00550ed7962ddc167167bd922b842199eeb6505e6f344852",
+    strip_prefix = "protobuf-3.11.3",
+    urls = [
+        "https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v3.11.3.tar.gz",
+        "https://github.com/protocolbuffers/protobuf/archive/v3.11.3.tar.gz",
+    ],
 )
 
 # This is a mock version of bazelbuild/rules_python that contains only
@@ -144,7 +146,6 @@
     # Keep in sync with the archives fetched as part of building bazel.
     archives = [
         "e0b0291b2c51fbe5a7cfa14473a1ae850f94f021.zip",
-        "f83cb8dd6f5658bc574ccd873e25197055265d1c.tar.gz",
         "java_tools_javac11_linux-v7.0.zip",
         "java_tools_javac11_windows-v7.0.zip",
         "java_tools_javac11_darwin-v7.0.zip",
@@ -153,6 +154,8 @@
         "8ccf4f1c351928b55d5dddf3672e3667f6978d60.tar.gz",
         "0.16.2.zip",
         "android_tools_pkg-0.14.tar.gz",
+        # bazelbuild/bazel-skylib
+        "f83cb8dd6f5658bc574ccd873e25197055265d1c.tar.gz",
         # bazelbuild/platforms
         "46993efdd33b73649796c5fc5c9efb193ae19d51.zip",
         # bazelbuild/rules_java
@@ -165,11 +168,12 @@
         "rules_pkg-0.2.4.tar.gz",
         # bazelbuild/rules_proto
         "97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
+        # protocolbuffers/protobuf
+        "v3.11.3.tar.gz",
     ],
     dirname = "derived/distdir",
     sha256 = {
         "e0b0291b2c51fbe5a7cfa14473a1ae850f94f021.zip": "fe2e04f91ce8c59d49d91b8102edc6627c6fa2906c1b0e7346f01419ec4f419d",
-        "f83cb8dd6f5658bc574ccd873e25197055265d1c.tar.gz": "ba5d15ca230efca96320085d8e4d58da826d1f81b444ef8afccd8b23e0799b52",
         "java_tools_javac11_linux-v7.0.zip": "3ff465e82954a70f49982610dd63f6f651beaa83c707dd637870b0e41cdcd2f0",
         "java_tools_javac11_windows-v7.0.zip": "11d90a147919e74d11870cdd58c4ee5de3062c08d11b16aa72d3f3bbfa9497a0",
         "java_tools_javac11_darwin-v7.0.zip": "373a4226906ae9ba908550da16e133c4cd1f01b8973af82b9a2eb6903cb4d645",
@@ -178,6 +182,8 @@
         "8ccf4f1c351928b55d5dddf3672e3667f6978d60.tar.gz": "d868ce50d592ef4aad7dec4dd32ae68d2151261913450fac8390b3fd474bb898",
         "0.16.2.zip": "9b72bb0aea72d7cbcfc82a01b1e25bf3d85f791e790ddec16c65e2d906382ee0",
         "android_tools_pkg-0.14.tar.gz": "a3a951838448483e7af25afd10671b266cc6283104b4a2a427d31cac12cf0912",  # built at 6c63d70ef9c11a662b8323c0ae4f6d3ac53b1a60
+        # bazelbuild/bazel-skylib
+        "f83cb8dd6f5658bc574ccd873e25197055265d1c.tar.gz": "ba5d15ca230efca96320085d8e4d58da826d1f81b444ef8afccd8b23e0799b52",
         # bazelbuild/platforms
         "46993efdd33b73649796c5fc5c9efb193ae19d51.zip": "66184688debeeefcc2a16a2f80b03f514deac8346fe888fb7e691a52c023dd88",
         # bazelbuild/rules_java
@@ -190,16 +196,14 @@
         "rules_pkg-0.2.4.tar.gz": "4ba8f4ab0ff85f2484287ab06c0d871dcb31cc54d439457d28fd4ae14b18450a",
         # bazelbuild/rules_proto
         "97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz": "602e7161d9195e50246177e7c55b2f39950a9cf7366f74ed5f22fd45750cd208",
+        # protocolbuffers/protobuf
+        "v3.11.3.tar.gz": "cf754718b0aa945b00550ed7962ddc167167bd922b842199eeb6505e6f344852",
     },
     urls = {
         "e0b0291b2c51fbe5a7cfa14473a1ae850f94f021.zip": [
             "https://mirror.bazel.build/github.com/google/desugar_jdk_libs/archive/e0b0291b2c51fbe5a7cfa14473a1ae850f94f021.zip",
             "https://github.com/google/desugar_jdk_libs/archive/e0b0291b2c51fbe5a7cfa14473a1ae850f94f021.zip",
         ],
-        "f83cb8dd6f5658bc574ccd873e25197055265d1c.tar.gz": [
-            "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/archive/f83cb8dd6f5658bc574ccd873e25197055265d1c.tar.gz",
-            "https://github.com/bazelbuild/bazel-skylib/archive/f83cb8dd6f5658bc574ccd873e25197055265d1c.tar.gz",
-        ],
         "java_tools_javac11_linux-v7.0.zip": [
             "https://mirror.bazel.build/bazel_java_tools/releases/javac11/v7.0/java_tools_javac11_linux-v7.0.zip",
         ],
@@ -227,6 +231,11 @@
         "android_tools_pkg-0.14.tar.gz": [
             "https://mirror.bazel.build/bazel_android_tools/android_tools_pkg-0.14.tar.gz",
         ],
+        # bazelbuild/bazel-skylib
+        "f83cb8dd6f5658bc574ccd873e25197055265d1c.tar.gz": [
+            "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/archive/f83cb8dd6f5658bc574ccd873e25197055265d1c.tar.gz",
+            "https://github.com/bazelbuild/bazel-skylib/archive/f83cb8dd6f5658bc574ccd873e25197055265d1c.tar.gz",
+        ],
         # bazelbuild/platforms
         "46993efdd33b73649796c5fc5c9efb193ae19d51.zip": [
             "https://mirror.bazel.build/github.com/bazelbuild/platforms/archive/46993efdd33b73649796c5fc5c9efb193ae19d51.zip",
@@ -257,6 +266,11 @@
             "https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
             "https://github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
         ],
+        # protocolbuffers/protobuf
+        "v3.11.3.tar.gz": [
+            "https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v3.11.3.tar.gz",
+            "https://github.com/protocolbuffers/protobuf/archive/v3.11.3.tar.gz",
+        ],
     },
 )
 
@@ -417,6 +431,8 @@
 
 http_archive(
     name = "bazel_skylib",
+    patch_cmds = EXPORT_WORKSPACE_IN_BUILD_FILE,
+    patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_FILE_WIN,
     # Commit f83cb8dd6f5658bc574ccd873e25197055265d1c of 2018-11-26
     sha256 = "ba5d15ca230efca96320085d8e4d58da826d1f81b444ef8afccd8b23e0799b52",
     strip_prefix = "bazel-skylib-f83cb8dd6f5658bc574ccd873e25197055265d1c",
@@ -500,6 +516,8 @@
         "zulu11.29.3-ca-jdk11.0.2-macosx_x64.zip",
         "zulu11.29.3-ca-jdk11.0.2-win_x64.zip",
         "android_tools_pkg-0.14.tar.gz",
+        # bazelbuild/bazel-skylib
+        "f83cb8dd6f5658bc574ccd873e25197055265d1c.tar.gz",
         # bazelbuild/platforms
         "46993efdd33b73649796c5fc5c9efb193ae19d51.zip",
         # bazelbuild/rules_java
@@ -508,6 +526,8 @@
         "8bd6cd75d03c01bb82561a96d9c1f9f7157b13d0.zip",
         # bazelbuild/rules_proto
         "97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
+        # protocolbuffers/protobuf
+        "v3.11.3.tar.gz",
     ],
     dirname = "test_WORKSPACE/distdir",
     sha256 = {
@@ -531,6 +551,8 @@
         "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.14.tar.gz": "a3a951838448483e7af25afd10671b266cc6283104b4a2a427d31cac12cf0912",  # built at 6c63d70ef9c11a662b8323c0ae4f6d3ac53b1a60
+        # bazelbuild/bazel-skylib
+        "f83cb8dd6f5658bc574ccd873e25197055265d1c.tar.gz": "ba5d15ca230efca96320085d8e4d58da826d1f81b444ef8afccd8b23e0799b52",
         # bazelbuild/platforms
         "46993efdd33b73649796c5fc5c9efb193ae19d51.zip": "66184688debeeefcc2a16a2f80b03f514deac8346fe888fb7e691a52c023dd88",
         # bazelbuild/rules_java
@@ -539,6 +561,8 @@
         "8bd6cd75d03c01bb82561a96d9c1f9f7157b13d0.zip": "1d4dbbd1e1e9b57d40bb0ade51c9e882da7658d5bfbf22bbd15b68e7879d761f",
         # bazelbuild/rules_proto
         "97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz": "602e7161d9195e50246177e7c55b2f39950a9cf7366f74ed5f22fd45750cd208",
+        # protocolbuffers/protobuf
+        "v3.11.3.tar.gz": "cf754718b0aa945b00550ed7962ddc167167bd922b842199eeb6505e6f344852",
     },
     urls = {
         "zulu9.0.7.1-jdk9.0.7-linux_x64-allmodules.tar.gz": ["https://mirror.bazel.build/openjdk/azul-zulu-9.0.7.1-jdk9.0.7/zulu9.0.7.1-jdk9.0.7-linux_x64-allmodules.tar.gz"],
@@ -563,6 +587,11 @@
         "android_tools_pkg-0.14.tar.gz": [
             "https://mirror.bazel.build/bazel_android_tools/android_tools_pkg-0.14.tar.gz",
         ],
+        # bazelbuild/bazel-skylib
+        "f83cb8dd6f5658bc574ccd873e25197055265d1c.tar.gz": [
+            "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/archive/f83cb8dd6f5658bc574ccd873e25197055265d1c.tar.gz",
+            "https://github.com/bazelbuild/bazel-skylib/archive/f83cb8dd6f5658bc574ccd873e25197055265d1c.tar.gz",
+        ],
         # bazelbuild/platforms
         "46993efdd33b73649796c5fc5c9efb193ae19d51.zip": [
             "https://mirror.bazel.build/github.com/bazelbuild/platforms/archive/46993efdd33b73649796c5fc5c9efb193ae19d51.zip",
@@ -583,6 +612,11 @@
             "https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
             "https://github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
         ],
+        # protocolbuffers/protobuf
+        "v3.11.3.tar.gz": [
+            "https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v3.11.3.tar.gz",
+            "https://github.com/protocolbuffers/protobuf/archive/v3.11.3.tar.gz",
+        ],
     },
 )
 
diff --git a/src/BUILD b/src/BUILD
index ce5cd0d..8e255be 100644
--- a/src/BUILD
+++ b/src/BUILD
@@ -726,6 +726,7 @@
     name = "test_repos",
     srcs = [
         "@android_tools_for_testing//:WORKSPACE",
+        "@bazel_skylib//:WORKSPACE",
         "@bazel_toolchains//:WORKSPACE",
         "@com_google_protobuf//:WORKSPACE",
         "@openjdk10_darwin_archive//:WORKSPACE",
diff --git a/src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java b/src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java
index d23cbdb..1920af2 100644
--- a/src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java
+++ b/src/test/java/com/google/devtools/build/lib/blackbox/framework/BlackBoxTestEnvironment.java
@@ -96,9 +96,9 @@
             "    strip_prefix = 'rules_proto-97d8af4dc474595af3900dd85cb3a29ad28cc313',",
             "    urls = [",
             "        'https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/"
-                + "97d8af4dc474595af3900dd85cb3a29ad28cc313.zip',",
+                + "97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz',",
             "        'https://github.com/bazelbuild/rules_proto/archive/"
-                + "97d8af4dc474595af3900dd85cb3a29ad28cc313.zip',",
+                + "97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz',",
             "    ],",
             ")");
   }
diff --git a/src/test/shell/bazel/bazel_proto_library_test.sh b/src/test/shell/bazel/bazel_proto_library_test.sh
index 2ae7481..6ff835b 100755
--- a/src/test/shell/bazel/bazel_proto_library_test.sh
+++ b/src/test/shell/bazel/bazel_proto_library_test.sh
@@ -56,24 +56,30 @@
     strip_prefix = "rules_proto-97d8af4dc474595af3900dd85cb3a29ad28cc313",
     sha256 = "602e7161d9195e50246177e7c55b2f39950a9cf7366f74ed5f22fd45750cd208",
     urls = [
-        "https://mirror.bazel.build/github.com/bazelbuild/rules_proto/97d8af4dc474595af3900dd85cb3a29ad28cc313.zip",
-        "https://github.com/bazelbuild/rules_proto/97d8af4dc474595af3900dd85cb3a29ad28cc313.zip",
+        "https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
+        "https://github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
     ],
 )
 load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
 rules_proto_dependencies()
 rules_proto_toolchains()
 
-# java_lite_proto_library rules implicitly depend on @com_google_protobuf_javalite//:javalite_toolchain,
-# which is the JavaLite proto runtime (base classes and common utilities).
-http_archive(
-    name = "com_google_protobuf_javalite",
-    sha256 = "d8a2fed3708781196f92e1e7e7e713cf66804bd2944894401057214aff4f468e",
-    strip_prefix = "protobuf-5e8916e881c573c5d83980197a6f783c132d4276",
-    urls = [
-        "https://mirror.bazel.build/github.com/google/protobuf/archive/5e8916e881c573c5d83980197a6f783c132d4276.zip",
-        "https://github.com/google/protobuf/archive/5e8916e881c573c5d83980197a6f783c132d4276.zip",
-    ],
+# @com_google_protobuf//:protoc depends on @io_bazel//third_party/zlib.
+new_local_repository(
+    name = "io_bazel",
+    path = "$(dirname $(rlocation io_bazel/third_party/rules_python/rules_python.WORKSPACE))/../..",
+    build_file_content = "# Intentionally left empty.",
+    workspace_file_content = "workspace(name = 'io_bazel')",
+)
+
+# TODO(#9029): May require some adjustment if/when we depend on the real
+# @rules_python in the real source tree, since this third_party/ package won't
+# be available.
+new_local_repository(
+    name = "rules_python",
+    path = "$(dirname $(rlocation io_bazel/third_party/rules_python/rules_python.WORKSPACE))",
+    build_file = "$(rlocation io_bazel/third_party/rules_python/BUILD)",
+    workspace_file = "$(rlocation io_bazel/third_party/rules_python/rules_python.WORKSPACE)",
 )
 EOF
 }
diff --git a/src/test/shell/integration/BUILD b/src/test/shell/integration/BUILD
index 197d3fb..eeb3826 100644
--- a/src/test/shell/integration/BUILD
+++ b/src/test/shell/integration/BUILD
@@ -334,7 +334,6 @@
     srcs = ["modify_execution_info_test.sh"],
     data = [
         ":test-deps",
-        "//third_party/protobuf/3.6.1:srcs",
         "@bazel_tools//tools/bash/runfiles",
     ],
 )
diff --git a/src/test/shell/integration/modify_execution_info_test.sh b/src/test/shell/integration/modify_execution_info_test.sh
index 17ea834..61b0ab5 100755
--- a/src/test/shell/integration/modify_execution_info_test.sh
+++ b/src/test/shell/integration/modify_execution_info_test.sh
@@ -153,10 +153,25 @@
   if [[ "$PRODUCT_NAME" = "bazel" ]]; then
     # proto_library requires this external workspace.
     cat >> WORKSPACE << EOF
+http_archive(
+    name = "rules_proto",
+    strip_prefix = "rules_proto-97d8af4dc474595af3900dd85cb3a29ad28cc313",
+    sha256 = "602e7161d9195e50246177e7c55b2f39950a9cf7366f74ed5f22fd45750cd208",
+    urls = [
+        "https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
+        "https://github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
+    ],
+)
+load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
+rules_proto_dependencies()
+rules_proto_toolchains()
+
+# @com_google_protobuf//:protoc depends on @io_bazel//third_party/zlib.
 new_local_repository(
-    name = "com_google_protobuf",
-    path = "$(dirname $(rlocation io_bazel/third_party/protobuf/3.6.1/BUILD))",
-    build_file = "$(rlocation io_bazel/third_party/protobuf/3.6.1/BUILD)",
+    name = "io_bazel",
+    path = "$(dirname $(rlocation io_bazel/third_party/rules_python/rules_python.WORKSPACE))/../..",
+    build_file_content = "# Intentionally left empty.",
+    workspace_file_content = "workspace(name = 'io_bazel')",
 )
 
 # TODO(#9029): May require some adjustment if/when we depend on the real
diff --git a/src/test/shell/testenv.sh b/src/test/shell/testenv.sh
index 7570363..808f92e 100755
--- a/src/test/shell/testenv.sh
+++ b/src/test/shell/testenv.sh
@@ -287,6 +287,7 @@
 
     repos=(
         "android_tools_for_testing"
+        "bazel_skylib"
         "bazel_toolchains"
         "com_google_protobuf"
         "openjdk10_darwin_archive"