summaryrefslogtreecommitdiffstats
path: root/tools/vim
diff options
context:
space:
mode:
authorenne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-16 05:49:56 +0000
committerenne@chromium.org <enne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-16 05:49:56 +0000
commit91b43bf676d4727c833f66c744ef1ff4a1930c2b (patch)
tree174e84e5f15c7be98c3203efbeebfee0873e4204 /tools/vim
parent169adebb59774f88757a940621998440c590336b (diff)
downloadchromium_src-91b43bf676d4727c833f66c744ef1ff4a1930c2b.zip
chromium_src-91b43bf676d4727c833f66c744ef1ff4a1930c2b.tar.gz
chromium_src-91b43bf676d4727c833f66c744ef1ff4a1930c2b.tar.bz2
Add a CrBuild command to ninja-build.vim
BUG=none Review URL: https://codereview.chromium.org/11090084 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162079 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/vim')
-rw-r--r--tools/vim/ninja-build.vim46
1 files changed, 37 insertions, 9 deletions
diff --git a/tools/vim/ninja-build.vim b/tools/vim/ninja-build.vim
index af416b6..bbcb8d9 100644
--- a/tools/vim/ninja-build.vim
+++ b/tools/vim/ninja-build.vim
@@ -5,6 +5,10 @@
" Adds a "Compile this file" function, using ninja. On Mac, binds Cmd-k to
" this command. On Windows, Ctrl-F7 (which is the same as the VS default).
"
+" Adds a "Build this target" function, using ninja. This is not bound
+" to any key by default, but can be used via the :CrBuild command.
+" It builds 'chrome' by default, but :CrBuild target1 target2 etc works as well.
+"
" Requires that gyp has already generated build.ninja files, and that ninja is
" in your path (which it is automatically if depot_tools is in your path).
"
@@ -56,7 +60,7 @@ def guess_configuration():
return configuration
-def compute_ninja_command(configuration=None):
+def compute_ninja_command_for_current_buffer(configuration=None):
"""Returns the shell command to compile the file in the current buffer."""
if not configuration: configuration = guess_configuration()
build_dir = os.path.join(path_to_source_root(), 'out', configuration)
@@ -66,20 +70,23 @@ def compute_ninja_command(configuration=None):
file_to_build = path_to_current_buffer()
file_to_build = os.path.relpath(file_to_build, build_dir)
- return ' '.join(['ninja', '-C', build_dir, file_to_build + '^'])
-
-
-def set_makepgr_to_single_file_ninja():
- build_cmd = compute_ninja_command()
+ build_cmd = ' '.join(['ninja', '-C', build_dir, file_to_build + '^'])
if sys.platform == 'win32':
# Escape \ for Vim, and ^ for both Vim and shell.
build_cmd = build_cmd.replace('\\', '\\\\').replace('^', '^^^^')
- vim.command('let &makeprg=\'%s\'' % build_cmd)
+ vim.command('return "%s"' % build_cmd)
+
+
+def compute_ninja_command_for_targets(targets='', configuration=None):
+ if not configuration: configuration = guess_configuration()
+ build_dir = os.path.join(path_to_source_root(), 'out', configuration)
+ build_cmd = ' '.join(['ninja', '-C', build_dir, targets])
+ vim.command('return "%s"' % build_cmd)
endpython
-fun! CrCompileFile()
+fun! s:MakeWithCustomCommand(build_cmd)
let l:oldmakepgr = &makeprg
- python set_makepgr_to_single_file_ninja()
+ let &makeprg=a:build_cmd
silent make | cwindow
if !has('gui_running')
redraw!
@@ -87,7 +94,28 @@ fun! CrCompileFile()
let &makeprg = l:oldmakepgr
endfun
+fun! s:NinjaCommandForCurrentBuffer()
+ python compute_ninja_command_for_current_buffer()
+endfun
+
+fun! s:NinjaCommandForTargets(targets)
+ python compute_ninja_command_for_targets(vim.eval('a:targets'))
+endfun
+
+fun! CrCompileFile()
+ call s:MakeWithCustomCommand(s:NinjaCommandForCurrentBuffer())
+endfun
+
+fun! CrBuild(...)
+ let l:targets = a:0 > 0 ? join(a:000, ' ') : ''
+ if (l:targets !~ "\i")
+ let l:targets = 'chrome'
+ endif
+ call s:MakeWithCustomCommand(s:NinjaCommandForTargets(l:targets))
+endfun
+
command! CrCompileFile call CrCompileFile()
+command! -nargs=* CrBuild call CrBuild(<q-args>)
if has('mac')
map <D-k> :CrCompileFile<cr>