Chromium Code Reviews| Index: tools/vim/ninja-build.vim |
| diff --git a/tools/vim/ninja-build.vim b/tools/vim/ninja-build.vim |
| index af416b6d1710762661bd134f69b5d81ac62eba2a..bbcb8d965cc784b44c40ddaa65176cb5fe3d7fb4 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). |
|
tfarina
2012/10/17 01:53:02
Is there a keystroke for Linux/Unix as well?
Nico
2012/10/17 02:10:51
see line 127 (unrelated to tjis cl tho)
|
| " |
| +" 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> |