pw_presubmit: Add message about the Bazel cache
Sometimes the Bazel cache gets in a bad state where it complains about
undeclared inclusions on C standard library headers. The only way to fix
this is to delete the Bazel cache. This adds a message to the presubmit
about how to clear the cache if the Bazel build fails.
Fixed: 114
Change-Id: I7c3ad45bdce919a325f721f2071e99c1e56582c0
diff --git a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
index 5a18e39..dc3408a 100755
--- a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
+++ b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
@@ -280,15 +280,21 @@
#
@filter_paths(endswith=(*format_code.C_FORMAT.extensions, '.bzl', 'BUILD'))
def bazel_test(ctx: PresubmitContext):
- call('bazel',
- 'test',
- '//...',
- '--verbose_failures',
- '--verbose_explanations',
- '--worker_verbose',
- '--symlink_prefix',
- ctx.output_directory.joinpath('bazel-'),
- cwd=ctx.repository_root)
+ try:
+ call('bazel',
+ 'test',
+ '//...',
+ '--verbose_failures',
+ '--verbose_explanations',
+ '--worker_verbose',
+ '--symlink_prefix',
+ ctx.output_directory.joinpath('bazel-'),
+ cwd=ctx.repository_root)
+ except:
+ _LOG.info('If the Bazel build inexplicably fails while the '
+ 'other builds are passing, try deleting the Bazel cache:\n'
+ ' rm -rf ~/.cache/bazel')
+ raise
BAZEL = (bazel_test, )