Clean up how android repos end in the distfile
Currently, the android_sdk_repository and android_ndk_repository in the WORKSPACE are commented out by default, but the CI workers uncomment them before starting execution. Currently this isn't a problem. However, once https://github.com/bazelbuild/bazel/pull/11737 is submitted, bazel_boostrap_distfile_test and bazel_determinism_test will begin to fail, because the uncommented android_sdk_repository will execute, then fail because either ANDROID_HOME is not set or points to an invalid directory.
Since the bootstrap process should never execute Android rules, I decided it would be clearer to remove the possibility entirely by removing the repo declarations from the WORKSPACE.
The cleanups to the tools/android are more for clarity, to ensure they match the actual @bazel_tools used by built bazel. In an ideal world we'd remove much more code from the distfile and this wouldn't be present at all.
Three changes:
1. Use tools/android/BUILD.tools instead of tools/android/BUILD in the distfile.
2. Re-comment android_sdk_repository and android_ndk_repository (they aren't needed for bootstrapping).
3. Fix srcs_test to handle the case where part of the distfile is generated by a genrule.
Closes #11744.
PiperOrigin-RevId: 322143408
diff --git a/BUILD b/BUILD
index 368a48c..5d0542c 100644
--- a/BUILD
+++ b/BUILD
@@ -13,12 +13,14 @@
srcs = glob(
["*"],
exclude = [
+ "WORKSPACE", # Needs to be filtered.
"bazel-*", # convenience symlinks
"out", # IntelliJ with setup-intellij.sh
"output", # output of compile.sh
".*", # mainly .git* files
],
) + [
+ "//:WORKSPACE.filtered",
"//examples:srcs",
"//scripts:srcs",
"//site:srcs",
@@ -61,6 +63,17 @@
],
)
+genrule(
+ name = "filtered_WORKSPACE",
+ srcs = ["WORKSPACE"],
+ outs = ["WORKSPACE.filtered"],
+ cmd = "\n".join([
+ "cp $< $@",
+ # Comment out the android repos if they exist.
+ "sed -i.bak -e 's/^android_sdk_repository/# android_sdk_repository/' -e 's/^android_ndk_repository/# android_ndk_repository/' $@",
+ ]),
+)
+
pkg_tar(
name = "bootstrap-jars",
srcs = [
@@ -98,6 +111,7 @@
name = "bazel-srcs",
srcs = [":srcs"],
remap_paths = {
+ "WORKSPACE.filtered": "WORKSPACE",
# Rewrite paths coming from local repositories back into third_party.
"../googleapis": "third_party/googleapis",
"../remoteapis": "third_party/remoteapis",
diff --git a/scripts/bootstrap/compile.sh b/scripts/bootstrap/compile.sh
index de9a56f..750ff07 100755
--- a/scripts/bootstrap/compile.sh
+++ b/scripts/bootstrap/compile.sh
@@ -295,6 +295,11 @@
mkdir -p ${BAZEL_TOOLS_REPO}/tools/python
link_file "${PWD}/tools/python/BUILD.tools" "${BAZEL_TOOLS_REPO}/tools/python/BUILD"
+ # Create @bazel_tools/tools/android/BUILD
+ mkdir -p ${BAZEL_TOOLS_REPO}/tools/android
+ link_file "${PWD}/tools/android/BUILD.tools" "${BAZEL_TOOLS_REPO}/tools/android/BUILD"
+ link_children "${PWD}" tools/android "${BAZEL_TOOLS_REPO}"
+
# Create the rest of @bazel_tools//tools/...
link_children "${PWD}" tools/cpp "${BAZEL_TOOLS_REPO}"
mv -f ${BAZEL_TOOLS_REPO}/tools/cpp/BUILD.tools ${BAZEL_TOOLS_REPO}/tools/cpp/BUILD
diff --git a/src/test/shell/bazel/srcs_test.sh b/src/test/shell/bazel/srcs_test.sh
index 77c491e..1fb25f1 100755
--- a/src/test/shell/bazel/srcs_test.sh
+++ b/src/test/shell/bazel/srcs_test.sh
@@ -24,6 +24,7 @@
# Rewrite labels to file paths. This assumes any external repo is actually
# a local_repository located in third_party.
cat "${TEST_SRCDIR}/io_bazel/src/test/shell/bazel/srcs_list" \
+ | sed -e 's|@bazel_tools//||' \
| sed -e 's|@\([^/]*\)//|third_party/\1|' \
| sed -e 's|^//||' | sed -e 's|^:||' | sed -e 's|:|/|' \
| sort -u >"${SRCS_QUERY}"