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

[7.1.0] Offer Shell completion for top-level packages without subpackages #20879

Merged
merged 1 commit into from
Jan 16, 2024
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
15 changes: 15 additions & 0 deletions scripts/bash_completion_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -794,4 +794,19 @@ test_workspace_boundary() {
'build //sub_repo/'
}

test_complete_root_package() {
# This test only works for Bazel
if [[ ! " ${COMMAND_ALIASES[*]} " =~ " bazel " ]]; then return; fi

mkdir pkgs_repo
touch pkgs_repo/WORKSPACE
cat > pkgs_repo/BUILD <<'EOF'
cc_binary(name = "main")
EOF
cd pkgs_repo 2>/dev/null

assert_expansion 'build //' \
'build //:'
}

run_suite "Tests of bash completion of 'blaze' command."
8 changes: 8 additions & 0 deletions scripts/bazel-complete-template.bash
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,14 @@ _bazel__expand_package_name() {
fi
fi
done
# The loop over the compgen -d output above does not include the top-level
# package.
if [ -f $root$current/BUILD.bazel -o -f $root$current/BUILD ]; then
found=1
if [ "${type}" != "label-package" ]; then
echo "${current}:"
fi
fi
[ $found -gt 0 ] && break # Stop searching package path upon first match.
done
}
Expand Down
Loading