Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Unified Diff: tools/vim/ninja-build.vim

Issue 11090084: Add a CrBuild command to ninja-build.vim (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698