You will create and merge the following Pull Requests.
-
Fetch the desired protobuf version and copy it in a folder
new_proto
underthird_party/protobuf
.Example: to upgrade to 3.6.1, download and unpack protobuf-all-3.6.1.zip.
-
Build the Java proto library from source and, in case you cloned an upstream version of protobuf, remove the .git folders:
cd third_party/protobuf/new_proto bazel build :protobuf_java :protobuf_java_util cp bazel-bin/libprotobuf_java.jar . cp bazel-bin/libprotobuf_java_util.jar . bazel clean --expunge rm -rf .git .gitignore .gitmodules
Reason: Bazel uses upstream protobuf from source, except for Java, as Bazel's bootstrapping scripts currently don't build protobuf Java when bootstrapping Bazel but use pre-built jars instead.
-
Modify protobuf's
BUILD
file to not build java from source, but to use the jars instead:-
In the BUILD file delete the rules listed under
Java support
. -
From the
third_party/protobuf/<old_proto>/BUILD
file copy the rules under the "Modifications made by bazel" section to the new BUILD file. The java rules in there should have the same names as the ones you just deleted under "Java support". You might need to update the names of the jars in the rules sources to the ones you just build.
-
-
Copy
third_party/protobuf/<old_proto>/com_google_protobuf_java.BUILD
to the new directory. -
From
third_party/protobuf/<old_proto>/util/python/BUILD
,third_party/protobuf/<old_proto>/examples/BUILD
, andthird_party/protobuf/<old_proto>/third_party/googletest/BUILD.bazel
: copy thelicenses
declaration and thesrcs
filegroup to the corresponding file underthird_party/protobuf/<new_proto>
. -
In
third_party/protobuf/<new_proto>/BUILD
, in thesrcs
filegroup rule, update the version number referring to the newly addedsrcs
rules. -
Rename
third_party/protobuf/<new_proto>
directory according to the protobuf version number. -
In
third_party/protobuf/BUILD
:-
Add a new variable
_NEW_PROTOBUF_VERSION
, set to value of the version. -
In the
srcs
filegroup rule, add:srcs = [ "//third_party/protobuf/" + PROTOBUF_VERSION + ":srcs", + "//third_party/protobuf/" + _NEW_PROTOBUF_VERSION + ":srcs", ],
-
-
Create a PR of these changes and merge it directly to https://bazel.googlesource.com/bazel/+/master (without the usual process of importing it to the Google-internal version control).
-
In
third_party/protobuf/BUILD
:-
rename
PROTOBUF_VERSION
to_OLD_PROTOBUF_VERSION
-
rename
_NEW_PROTOBUF_VERSION
toPROTOBUF_VERSION
-
-
In the root
WORKSPACE
file update relative paths of protobuf to point to the new version. -
Update version number in
src/main/protobuf/BUILD
andsrc/test/shell/testenv.sh
. -
Update the current version in this file.
-
Create a PR of these changes and get it imported. Some files won't be imported (those that are only hosted on GitHub); this is expected.
-
Wait for the imported PR to be pushed back to GitHub. Rebase the PR from the previous step, and merge it to https://bazel.googlesource.com/bazel/+/master .
-
Delete the
third_party/protobuf/<old_proto>
directory. -
Remove
_OLD_PROTOBUF_VERSION
fromthird_party/protobuf/BUILD
. -
Create a PR of these changes and merge it directly to https://bazel.googlesource.com/bazel/+/master .
Update this file if you found these instructions to be wrong or incomplete.
The current version of protobuf is 3.6.1.