[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> |
| 22 | |
[email protected] | 19f3044 | 2012-02-22 01:47:44 | [diff] [blame] | 23 | chrome_source=$(cd $(dirname $BASH_SOURCE)/.. && pwd) |
[email protected] | 37e2a808 | 2012-02-03 21:44:54 | [diff] [blame] | 24 | |
| 25 | _chrome_flag() { |
| 26 | local cur targets |
| 27 | cur="${COMP_WORDS[COMP_CWORD]}" |
| 28 | targets=$(cd $chrome_source; \ |
[email protected] | 4f1594d | 2012-02-03 23:37:21 | [diff] [blame] | 29 | git ls-files '*switches*' | \ |
[email protected] | 19f3044 | 2012-02-22 01:47:44 | [diff] [blame] | 30 | xargs sed -ne 's/^[^/]*"\([^" /]\{1,\}\)".*/--\1/p') |
[email protected] | 37e2a808 | 2012-02-03 21:44:54 | [diff] [blame] | 31 | COMPREPLY=($(compgen -W "$targets" -- "$cur")) |
| 32 | return 0 |
| 33 | } |
| 34 | |
lukasza | b2789fb | 2016-10-19 23:59:50 | [diff] [blame] | 35 | _gtest_flag() { |
| 36 | local cur gtest_flags launcher_flags |
| 37 | cur="${COMP_WORDS[COMP_CWORD]}" |
| 38 | gtest_flags=$(sed -ne 's/^.*FromGTestEnv("\([^" /]\+\)".*$/--gtest_\1/p' \ |
| 39 | "$chrome_source/testing/gtest/src/gtest.cc") |
| 40 | chrome_test_launcher_flags=$(sed -ne 's/^[^/]*"\([^" /]\{1,\}\)".*/--\1/p' \ |
| 41 | "$chrome_source/base/test/test_switches.cc") |
| 42 | COMPREPLY=($( |
| 43 | compgen -W "$gtest_flags $chrome_test_launcher_flags" -- "$cur")) |
| 44 | return 0 |
| 45 | } |
| 46 | |
lukasza | ca7fac62 | 2016-10-26 18:59:22 | [diff] [blame^] | 47 | _layout_test_flag() { |
| 48 | local cur targets webkitpy_dir prev_switch |
| 49 | cur="${COMP_WORDS[COMP_CWORD]}" |
| 50 | |
| 51 | # Complete content_shell switches if appropriate. |
| 52 | if [ "${COMP_CWORD}" -gt 2 -a "${COMP_WORDS[COMP_CWORD-1]}" = "=" ] |
| 53 | then |
| 54 | prev_switch="${COMP_WORDS[COMP_CWORD-2]}" |
| 55 | if [ "$prev_switch" = "--additional-drt-flag" -o \ |
| 56 | "$prev_switch" = "--additional-driver-flag" ] |
| 57 | then |
| 58 | targets=$(cd $chrome_source; \ |
| 59 | git ls-files 'content/*switches*.cc' | \ |
| 60 | xargs sed -ne 's/^[^/]*"\([^" /]\{1,\}\)".*/--\1/p') |
| 61 | COMPREPLY=($(compgen -W "$targets" -- "$cur")) |
| 62 | return 0 |
| 63 | fi |
| 64 | fi |
| 65 | |
| 66 | # Complete run-webkit-tests switches. |
| 67 | webkitpy_dir="$chrome_source/third_party/WebKit/Tools/Scripts/webkitpy" |
| 68 | targets=$(sed -ne 's/^[[:space:]]*"\(--[a-z-]\+\)",[[:space:]]*$/\1/p' \ |
| 69 | "$webkitpy_dir/layout_tests/run_webkit_tests.py") |
| 70 | COMPREPLY=($(compgen -W "$targets" -- "$cur")) |
| 71 | return 0 |
| 72 | } |
| 73 | |
[email protected] | 37e2a808 | 2012-02-03 21:44:54 | [diff] [blame] | 74 | complete -F _chrome_flag google-chrome |
| 75 | complete -F _chrome_flag chrome |
[email protected] | 19f3044 | 2012-02-22 01:47:44 | [diff] [blame] | 76 | if [ $(uname) = "Darwin" ] |
| 77 | then |
| 78 | complete -F _chrome_flag Chromium |
| 79 | fi |
lukasza | b2789fb | 2016-10-19 23:59:50 | [diff] [blame] | 80 | |
| 81 | for gtest_test_executable in $( |
| 82 | cd $chrome_source; |
| 83 | git ls-files '*/BUILD.gn' | xargs sed -ne 's/^test("\([^"]\+\)").*$/\1/p' |
| 84 | ); do |
| 85 | complete -F _gtest_flag $gtest_test_executable |
| 86 | done |
lukasza | ca7fac62 | 2016-10-26 18:59:22 | [diff] [blame^] | 87 | |
| 88 | complete -F _layout_test_flag run-webkit-tests |