[email protected] | 37e2a808 | 2012-02-03 21:44:54 | [diff] [blame] | 1 | # 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 | |
lukasza | ca7fac62 | 2016-10-26 18:59:22 | [diff] [blame] | 8 | # 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 | # |
| 19 | # Layout test switches: |
| 20 | # $ third_party/WebKit/Tools/Scripts/run-webkit-tests --additional-driver-f<tab> |
| 21 | # $ .../run-webkit-tests --additional-driver-flag=--site-per-pro<tab> |
qyearsley | 85380c9 | 2017-01-27 02:46:20 | [diff] [blame^] | 22 | # |
| 23 | # Blink webkit-patch sub-commands: |
| 24 | # $ third_party/WebKit/Tools/Scripts/webkit-patch reb<tab> |
lukasza | ca7fac62 | 2016-10-26 18:59:22 | [diff] [blame] | 25 | |
qyearsley | 85380c9 | 2017-01-27 02:46:20 | [diff] [blame^] | 26 | if [ -n "$BASH_SOURCE" ]; then |
| 27 | # The $BASH_SOURCE variable returns path of current script in bash. |
| 28 | chrome_source=$(cd $(dirname $BASH_SOURCE)/.. && pwd) |
| 29 | else |
| 30 | # This is here for other similar shells, e.g. zsh. |
| 31 | chrome_source=$(cd $(dirname $0)/.. && pwd) |
| 32 | fi |
[email protected] | 37e2a808 | 2012-02-03 21:44:54 | [diff] [blame] | 33 | |
| 34 | _chrome_flag() { |
| 35 | local cur targets |
| 36 | cur="${COMP_WORDS[COMP_CWORD]}" |
| 37 | targets=$(cd $chrome_source; \ |
[email protected] | 4f1594d | 2012-02-03 23:37:21 | [diff] [blame] | 38 | git ls-files '*switches*' | \ |
[email protected] | 19f3044 | 2012-02-22 01:47:44 | [diff] [blame] | 39 | xargs sed -ne 's/^[^/]*"\([^" /]\{1,\}\)".*/--\1/p') |
[email protected] | 37e2a808 | 2012-02-03 21:44:54 | [diff] [blame] | 40 | COMPREPLY=($(compgen -W "$targets" -- "$cur")) |
| 41 | return 0 |
| 42 | } |
| 43 | |
lukasza | b2789fb | 2016-10-19 23:59:50 | [diff] [blame] | 44 | _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' \ |
| 48 | "$chrome_source/testing/gtest/src/gtest.cc") |
| 49 | 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 | |
lukasza | ca7fac62 | 2016-10-26 18:59:22 | [diff] [blame] | 56 | _layout_test_flag() { |
| 57 | local cur targets webkitpy_dir prev_switch |
| 58 | 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 | |
| 75 | # Complete run-webkit-tests switches. |
| 76 | webkitpy_dir="$chrome_source/third_party/WebKit/Tools/Scripts/webkitpy" |
| 77 | targets=$(sed -ne 's/^[[:space:]]*"\(--[a-z-]\+\)",[[:space:]]*$/\1/p' \ |
| 78 | "$webkitpy_dir/layout_tests/run_webkit_tests.py") |
| 79 | COMPREPLY=($(compgen -W "$targets" -- "$cur")) |
| 80 | return 0 |
| 81 | } |
| 82 | |
qyearsley | 85380c9 | 2017-01-27 02:46:20 | [diff] [blame^] | 83 | _webkit_patch_flag() { |
| 84 | local cur targets webkit_scripts_dir |
| 85 | cur="${COMP_WORDS[COMP_CWORD]}" |
| 86 | webkit_scripts_dir=$chrome_source/third_party/WebKit/Tools/Scripts |
| 87 | targets=$($webkit_scripts_dir/webkit-patch help | grep '^ [a-z]' | \ |
| 88 | awk '{ print $1 }') |
| 89 | COMPREPLY=($(compgen -W "$targets" -- "$cur")) |
| 90 | return 0 |
| 91 | } |
| 92 | |
[email protected] | 37e2a808 | 2012-02-03 21:44:54 | [diff] [blame] | 93 | complete -F _chrome_flag google-chrome |
| 94 | complete -F _chrome_flag chrome |
[email protected] | 19f3044 | 2012-02-22 01:47:44 | [diff] [blame] | 95 | if [ $(uname) = "Darwin" ] |
| 96 | then |
| 97 | complete -F _chrome_flag Chromium |
| 98 | fi |
lukasza | b2789fb | 2016-10-19 23:59:50 | [diff] [blame] | 99 | |
| 100 | for gtest_test_executable in $( |
| 101 | cd $chrome_source; |
lukasza | 990b7f87 | 2016-10-28 19:25:08 | [diff] [blame] | 102 | git ls-files '*/BUILD.gn' | xargs sed -ne 's/^.*test("\([^"]\+\)").*$/\1/p' |
lukasza | b2789fb | 2016-10-19 23:59:50 | [diff] [blame] | 103 | ); do |
| 104 | complete -F _gtest_flag $gtest_test_executable |
| 105 | done |
lukasza | ca7fac62 | 2016-10-26 18:59:22 | [diff] [blame] | 106 | |
| 107 | complete -F _layout_test_flag run-webkit-tests |
qyearsley | 85380c9 | 2017-01-27 02:46:20 | [diff] [blame^] | 108 | complete -F _webkit_patch_flag webkit-patch |