Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -397,19 +397,19 @@ public void beforeCommand(CommandEnvironment env) throws AbruptExitException {
if (repoContentsCachePath != null
&& env.getWorkspace() != null
&& repoContentsCachePath.startsWith(env.getWorkspace())) {
// Having the repo contents cache inside the workspace is very dangerous. During the
// lifetime of a Bazel invocation, we treat files inside the workspace as immutable. This
// can cause mysterious failures if we write files inside the workspace during the
// Having the repo contents cache inside the main repo is very dangerous. During the
// lifetime of a Bazel invocation, we treat files inside the main repo as immutable. This
// can cause mysterious failures if we write files inside the main repo during the
// invocation, as is often the case with the repo contents cache.
// TODO: wyv@ - This is a crude check that disables some use cases (such as when the output
// base itself is inside the main repo). Investigate a better check.
repositoryCache.getRepoContentsCache().setPath(null);
throw new AbruptExitException(
detailedExitCode(
"""
The repo contents cache [%s] is inside the workspace [%s]. This can cause spurious \
The repo contents cache [%s] is inside the main repo [%s]. This can cause spurious \
failures. Disable the repo contents cache with `--repo_contents_cache=`, or \
specify `--repo_contents_cache=<path outside the workspace>`.
specify `--repo_contents_cache=<path outside the main repo>`.
"""
.formatted(repoContentsCachePath, env.getWorkspace()),
Code.BAD_REPO_CONTENTS_CACHE));
Expand Down
17 changes: 17 additions & 0 deletions src/test/shell/bazel/bazel_repository_cache_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -541,4 +541,21 @@ EOF
&& fail "expected failure" || :
}

function test_contents_cache_not_allowed_in_main_repo() {
# For some reason, this same test written in Python causes it to hang forever
# in the regression case, instead of failing immediately. So we write it in
# shell.
echo 'filegroup(name="foo")' > BUILD
if (bazel build --repo_contents_cache=inside foo >& $TEST_log); then
fail "expected exit code 2, got 0"
else
exit_code=$?
if [ $exit_code -ne 2 ]; then
fail "expected exit code 2, got $exit_code"
else
:
fi
fi
}

run_suite "repository cache tests"
Loading