Commit 26d153d6 authored by Jakob Kummerow's avatar Jakob Kummerow Committed by Commit Bot

[bash-completion] Support cctest/unittests, and GDB

Because why not.

No-Try: true
Bug: v8:11567
Change-Id: I763d9d0c6704f3f8c5e8336e2157336e159648fe
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2762139
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Auto-Submit: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarDan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73435}
parent 4c17394d
......@@ -27,39 +27,95 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Inspired by and based on:
# http://src.chromium.org/viewvc/chrome/trunk/src/tools/bash-completion
# https://chromium.googlesource.com/chromium/src/+/master/tools/bash-completion
# Flag completion rule for bash.
# To load in your shell, "source path/to/this/file".
v8_source=$(readlink -f $(dirname $BASH_SOURCE)/..)
_v8_flag() {
local cur defines targets
cur="${COMP_WORDS[COMP_CWORD]}"
defines=$(cat $v8_source/src/flags/flag-definitions.h \
_get_v8_flags() {
# The first `sed` command joins lines when a line ends with '('.
# See http://sed.sourceforge.net/sedfaq3.html#s3.2
local flags_file="$v8_source/src/flags/flag-definitions.h"
local defines=$( \
sed -e :a -e '/($/N; s/(\n\s*/(/; ta' < "$flags_file" \
| grep "^DEFINE" \
| grep -v "DEFINE_IMPLICATION" \
| grep -v "DEFINE_NEG_IMPLICATION" \
| grep -v "DEFINE_VALUE_IMPLICATION" \
| sed -e 's/_/-/g'; \
cat $v8_source/src/flags/flag-definitions.h \
| grep "^ V(harmony_" \
grep "^ V(harmony_" "$flags_file" \
| sed -e 's/^ V/DEFINE-BOOL/' \
| sed -e 's/_/-/g' ;\
cat $v8_source/src/wasm/wasm-feature-flags.h \
| grep "^ V(" \
| sed -e 's/_/-/g'; \
grep "^ V(" $v8_source/src/wasm/wasm-feature-flags.h \
| sed -e 's/^ V(/DEFINE-BOOL(experimental-wasm-/' \
| sed -e 's/_/-/g')
targets=$(echo "$defines" \
| sed -ne 's/^DEFINE-[^(]*(\([^,]*\).*/--\1/p'; \
echo "$defines" \
| sed -ne 's/^DEFINE-BOOL(\([^,]*\).*/--no\1/p'; \
cat $v8_source/src/d8/d8.cc \
sed -ne 's/^DEFINE-[^(]*(\([^,]*\).*/--\1/p' <<< $defines
sed -ne 's/^DEFINE-BOOL(\([^,]*\).*/--no\1/p' <<< $defines
}
_get_d8_flags() {
cat $v8_source/src/d8/d8.cc \
| grep "strcmp(argv\[i\]" \
| sed -ne 's/^[^"]*"--\([^"]*\)".*/--\1/p')
COMPREPLY=($(compgen -W "$targets" -- "$cur"))
| sed -ne 's/^[^"]*"--\([^"]*\)".*/--\1/p'
}
_d8_flag() {
local targets
targets=$(_get_v8_flags ; _get_d8_flags)
COMPREPLY=($(compgen -W "$targets" -- "${COMP_WORDS[COMP_CWORD]}"))
return 0
}
_test_flag() {
local targets
targets=$(_get_v8_flags)
COMPREPLY=($(compgen -W "$targets" -- "${COMP_WORDS[COMP_CWORD]}"))
return 0
}
complete -F _v8_flag -f d8
complete -F _d8_flag -f d8
complete -F _test_flag -f cctest unittests
# Many distros set up their own GDB completion scripts. The logic below is
# careful to wrap any such functions (with additional logic), rather than
# overwriting them.
# An additional complication is that tested distros dynamically load their
# completion scripts on first use. So in order to be able to detect their
# presence, we have to force-load them first.
_maybe_setup_gdb_completions() {
# We only want to set up the wrapping once:
[[ -n "$_ORIGINAL_GDB_COMPLETIONS" ]] && return 0;
# This path works for Debian, Ubuntu, and Gentoo; other distros unknown.
# Feel free to submit patches to extend the logic.
local GDB_COMP
for GDB_COMP in "/usr/share/bash-completion/completions/gdb"; do
[[ -f "$GDB_COMP" ]] && source $GDB_COMP
done
_ORIGINAL_GDB_COMPLETIONS="$(complete -p gdb 2>/dev/null \
| sed -e 's/^.*-F \([^ ]*\).*/\1/')"
_gdb_v8_flag() {
local c i next
for (( i=1; i<$(($COMP_CWORD-1)); i++ )); do
c=${COMP_WORDS[$i]}
if [ "$c" = "-args" ] || [ "$c" = "--args" ] || [ "$c" == "--" ]; then
next=$(basename -- ${COMP_WORDS[$(($i+1))]})
if [ "$next" = "d8" ] ; then
_d8_flag
return 0
elif [ "$next" = "unittests" ] || [ "$next" = "cctest" ]; then
_test_flag
return 0
fi
fi
done
[[ -n "$_ORIGINAL_GDB_COMPLETIONS" ]] && $_ORIGINAL_GDB_COMPLETIONS
return 0
}
complete -F _gdb_v8_flag -f gdb
}
_maybe_setup_gdb_completions
unset _maybe_setup_gdb_completions
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment