Make it possible to bootstrap Bazel from original source
Related https://github.com/bazelbuild/bazel/issues/9408
When providing required `protoc` compiler and relevant tools and libraries, Bazel should be able to bootstrap itself from the original source.
This change fixes the bootstrap scripts by
- Adding missing proto compilation.
- Search for protobuf jars under /usr/share/java if the derived directory doesn't exist. (Should be available by `apt-get install libprotobuf-java`)
- Don't use the bootstrap toolchain if not bootstrapping from the dist archive. Because using that toolchain will make Bazel depend on things under derived directory, which doesn't exist if we bootstrap from Bazel original source and it's not necessary in this case.
Closes #11192.
PiperOrigin-RevId: 308215155
diff --git a/scripts/bootstrap/bootstrap.sh b/scripts/bootstrap/bootstrap.sh
index 4a86dae..f5cf4d3 100755
--- a/scripts/bootstrap/bootstrap.sh
+++ b/scripts/bootstrap/bootstrap.sh
@@ -31,13 +31,18 @@
: ${JAVA_VERSION:="1.8"}
-_BAZEL_ARGS="--java_toolchain=//src/java_tools/buildjar:bootstrap_toolchain \
+if [ -d derived ]; then
+ # Flags we need to bootstrap from the dist archive.
+ DIST_BOOTSTRAP_ARGS="--java_toolchain=//src/java_tools/buildjar:bootstrap_toolchain \
--host_java_toolchain=//src/java_tools/buildjar:bootstrap_toolchain \
- --spawn_strategy=standalone \
+ --distdir=derived/distdir"
+fi
+
+_BAZEL_ARGS="--spawn_strategy=standalone \
--nojava_header_compilation \
--strategy=Javac=worker --worker_quit_after_build --ignore_unsupported_sandboxing \
--compilation_mode=opt \
- --distdir=derived/distdir \
+ ${DIST_BOOTSTRAP_ARGS:-} \
${EXTRA_BAZEL_ARGS:-}"
if [ -z "${BAZEL-}" ]; then