Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for more workspace boundary files to bash completion #19268

Closed
wants to merge 1 commit into from
Closed
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
23 changes: 23 additions & 0 deletions scripts/bash_completion_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -768,4 +768,27 @@ test_info() {
'info --show_make_env '
}

test_workspace_boundary() {
# "Test that workspace boundary files are recognized"
mkdir -p sub_repo/some/pkg
touch sub_repo/some/pkg/BUILD
cd sub_repo 2>/dev/null

touch WORKSPACE.bazel
assert_expansion 'build //s' \
'build //some/'

mv WORKSPACE.bazel MODULE.bazel
assert_expansion 'build //s' \
'build //some/'

mv MODULE.bazel REPO.bazel
assert_expansion 'build //s' \
'build //some/'

rm REPO.bazel
assert_expansion 'build //s' \
'build //sub_repo/'
}

run_suite "Tests of bash completion of 'blaze' command."
10 changes: 7 additions & 3 deletions scripts/bazel-complete-template.bash
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,17 @@ _bazel__get_rule_match_pattern() {
}

# Compute workspace directory. Search for the innermost
# enclosing directory with a WORKSPACE file.
# enclosing directory with a boundary file (see
# src/main/cpp/workspace_layout.cc).
_bazel__get_workspace_path() {
local workspace=$PWD
while true; do
if [ -f "${workspace}/WORKSPACE" ]; then
if [ -f "${workspace}/WORKSPACE" ] || \
[ -f "${workspace}/WORKSPACE.bazel" ] || \
[ -f "${workspace}/MODULE.bazel" ] || \
[ -f "${workspace}/REPO.bazel" ]; then
break
elif [ -z "$workspace" -o "$workspace" = "/" ]; then
elif [ -z "$workspace" ] || [ "$workspace" = "/" ]; then
workspace=$PWD
break;
fi
Expand Down
Loading