blob: ad37b56e712d2de4cc2ce61f43d456beed8b30b3 [file] [log] [blame]
[email protected]37e2a8082012-02-03 21:44:541# Copyright (c) 2012 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5# Flag completion rule for bash.
6# To load in your shell, "source path/to/this/file".
7
lukaszaca7fac622016-10-26 18:59:228# Usage examples
9# ==============
10#
11# Browser command line switches:
12# $ out/gn/chrome --site-per-pro<tab>
13# $ google-chrome --site-per-pro<tab>
14#
15# Test switches (i.e. --gtest_* and --test-launcher-* switches):
16# $ out/gn/unit_tests --gtest_filt<tab>
17# $ out/gn/unit_tests --test-launcher-j<tab>
18#
Kent Tamuraa045a7f2018-04-25 05:08:1119# Web test switches:
20# $ third_party/blink/tools/run_web_tests.py --additional-driver-f<tab>
21# $ .../run_web_tests.py --additional-driver-flag=--site-per-pro<tab>
qyearsley85380c92017-01-27 02:46:2022#
Kent Tamurab53757e2018-04-20 17:54:4823# Blink blink_tool.py sub-commands:
24# $ third_party/blink/tools/blink_tool.py reb<tab>
lukaszaca7fac622016-10-26 18:59:2225
qyearsley85380c92017-01-27 02:46:2026if [ -n "$BASH_SOURCE" ]; then
27 # The $BASH_SOURCE variable returns path of current script in bash.
28 chrome_source=$(cd $(dirname $BASH_SOURCE)/.. && pwd)
29else
30 # This is here for other similar shells, e.g. zsh.
31 chrome_source=$(cd $(dirname $0)/.. && pwd)
32fi
[email protected]37e2a8082012-02-03 21:44:5433
34_chrome_flag() {
35 local cur targets
36 cur="${COMP_WORDS[COMP_CWORD]}"
37 targets=$(cd $chrome_source; \
[email protected]4f1594d2012-02-03 23:37:2138 git ls-files '*switches*' | \
[email protected]19f30442012-02-22 01:47:4439 xargs sed -ne 's/^[^/]*"\([^" /]\{1,\}\)".*/--\1/p')
[email protected]37e2a8082012-02-03 21:44:5440 COMPREPLY=($(compgen -W "$targets" -- "$cur"))
41 return 0
42}
43
lukaszab2789fb2016-10-19 23:59:5044_gtest_flag() {
45 local cur gtest_flags launcher_flags
46 cur="${COMP_WORDS[COMP_CWORD]}"
47 gtest_flags=$(sed -ne 's/^.*FromGTestEnv("\([^" /]\+\)".*$/--gtest_\1/p' \
Asanka Herathef7b34d2019-12-09 19:22:2048 "$chrome_source/third_party/googletest/src/googletest/src/gtest.cc")
lukaszab2789fb2016-10-19 23:59:5049 chrome_test_launcher_flags=$(sed -ne 's/^[^/]*"\([^" /]\{1,\}\)".*/--\1/p' \
50 "$chrome_source/base/test/test_switches.cc")
51 COMPREPLY=($(
52 compgen -W "$gtest_flags $chrome_test_launcher_flags" -- "$cur"))
53 return 0
54}
55
Kent Tamuraa045a7f2018-04-25 05:08:1156_web_test_flag() {
57 local cur targets blinkpy_dir prev_switch
lukaszaca7fac622016-10-26 18:59:2258 cur="${COMP_WORDS[COMP_CWORD]}"
59
60 # Complete content_shell switches if appropriate.
61 if [ "${COMP_CWORD}" -gt 2 -a "${COMP_WORDS[COMP_CWORD-1]}" = "=" ]
62 then
63 prev_switch="${COMP_WORDS[COMP_CWORD-2]}"
64 if [ "$prev_switch" = "--additional-drt-flag" -o \
65 "$prev_switch" = "--additional-driver-flag" ]
66 then
67 targets=$(cd $chrome_source; \
68 git ls-files 'content/*switches*.cc' | \
69 xargs sed -ne 's/^[^/]*"\([^" /]\{1,\}\)".*/--\1/p')
70 COMPREPLY=($(compgen -W "$targets" -- "$cur"))
71 return 0
72 fi
73 fi
74
Kent Tamuraa045a7f2018-04-25 05:08:1175 # Complete run_web_tests.py switches.
76 blinkpy_dir="$chrome_source/third_party/blink/tools/blinkpy"
lukaszaca7fac622016-10-26 18:59:2277 targets=$(sed -ne 's/^[[:space:]]*"\(--[a-z-]\+\)",[[:space:]]*$/\1/p' \
Kent Tamuraa045a7f2018-04-25 05:08:1178 "$blinkpy_dir/web_tests/run_webkit_tests.py")
lukaszaca7fac622016-10-26 18:59:2279 COMPREPLY=($(compgen -W "$targets" -- "$cur"))
80 return 0
81}
82
Kent Tamurab53757e2018-04-20 17:54:4883_blink_tool_flag() {
Kent Tamuraa045a7f2018-04-25 05:08:1184 local cur targets blink_tools_dir
qyearsley85380c92017-01-27 02:46:2085 cur="${COMP_WORDS[COMP_CWORD]}"
Kent Tamurab53757e2018-04-20 17:54:4886 blink_tools_dir=$chrome_source/third_party/blink/tools
87 targets=$($blink_tools_dir/blink_tool.py help | grep '^ [a-z]' | \
qyearsley85380c92017-01-27 02:46:2088 awk '{ print $1 }')
89 COMPREPLY=($(compgen -W "$targets" -- "$cur"))
90 return 0
91}
92
[email protected]37e2a8082012-02-03 21:44:5493complete -F _chrome_flag google-chrome
94complete -F _chrome_flag chrome
Robert Flack13d4b342019-03-28 14:17:3695complete -F _chrome_flag content_shell
[email protected]19f30442012-02-22 01:47:4496if [ $(uname) = "Darwin" ]
97then
98 complete -F _chrome_flag Chromium
99fi
lukaszab2789fb2016-10-19 23:59:50100
101for gtest_test_executable in $(
102 cd $chrome_source;
lukasza990b7f872016-10-28 19:25:08103 git ls-files '*/BUILD.gn' | xargs sed -ne 's/^.*test("\([^"]\+\)").*$/\1/p'
lukaszab2789fb2016-10-19 23:59:50104); do
105 complete -F _gtest_flag $gtest_test_executable
106done
lukaszaca7fac622016-10-26 18:59:22107
Kent Tamuraa045a7f2018-04-25 05:08:11108complete -F _web_test_flag run_web_tests.py
Kent Tamurab53757e2018-04-20 17:54:48109complete -F _blink_tool_flag blink_tool.py