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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 " Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 " Use of this source code is governed by a BSD-style license that can be
3 " found in the LICENSE file. 3 " found in the LICENSE file.
4 " 4 "
5 " Adds a "Compile this file" function, using ninja. On Mac, binds Cmd-k to 5 " Adds a "Compile this file" function, using ninja. On Mac, binds Cmd-k to
6 " this command. On Windows, Ctrl-F7 (which is the same as the VS default). 6 " 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)
7 " 7 "
8 " Adds a "Build this target" function, using ninja. This is not bound
9 " to any key by default, but can be used via the :CrBuild command.
10 " It builds 'chrome' by default, but :CrBuild target1 target2 etc works as well.
11 "
8 " Requires that gyp has already generated build.ninja files, and that ninja is 12 " Requires that gyp has already generated build.ninja files, and that ninja is
9 " in your path (which it is automatically if depot_tools is in your path). 13 " in your path (which it is automatically if depot_tools is in your path).
10 " 14 "
11 " Add the following to your .vimrc file: 15 " Add the following to your .vimrc file:
12 " so /path/to/src/tools/vim/ninja-build.vim 16 " so /path/to/src/tools/vim/ninja-build.vim
13 17
14 python << endpython 18 python << endpython
15 import os 19 import os
16 import vim 20 import vim
17 21
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 rel_mtime = os.path.getmtime(os.path.join(root, 'Release', test_path)) 53 rel_mtime = os.path.getmtime(os.path.join(root, 'Release', test_path))
50 except os.error: 54 except os.error:
51 rel_mtime = 0 55 rel_mtime = 0
52 return rel_mtime - debug_mtime >= 15 56 return rel_mtime - debug_mtime >= 15
53 configuration = 'Debug' 57 configuration = 'Debug'
54 if is_release_15s_newer('build.ninja') or is_release_15s_newer('protoc'): 58 if is_release_15s_newer('build.ninja') or is_release_15s_newer('protoc'):
55 configuration = 'Release' 59 configuration = 'Release'
56 return configuration 60 return configuration
57 61
58 62
59 def compute_ninja_command(configuration=None): 63 def compute_ninja_command_for_current_buffer(configuration=None):
60 """Returns the shell command to compile the file in the current buffer.""" 64 """Returns the shell command to compile the file in the current buffer."""
61 if not configuration: configuration = guess_configuration() 65 if not configuration: configuration = guess_configuration()
62 build_dir = os.path.join(path_to_source_root(), 'out', configuration) 66 build_dir = os.path.join(path_to_source_root(), 'out', configuration)
63 67
64 # ninja needs filepaths for the ^ syntax to be relative to the 68 # ninja needs filepaths for the ^ syntax to be relative to the
65 # build directory. 69 # build directory.
66 file_to_build = path_to_current_buffer() 70 file_to_build = path_to_current_buffer()
67 file_to_build = os.path.relpath(file_to_build, build_dir) 71 file_to_build = os.path.relpath(file_to_build, build_dir)
68 72
69 return ' '.join(['ninja', '-C', build_dir, file_to_build + '^']) 73 build_cmd = ' '.join(['ninja', '-C', build_dir, file_to_build + '^'])
70
71
72 def set_makepgr_to_single_file_ninja():
73 build_cmd = compute_ninja_command()
74 if sys.platform == 'win32': 74 if sys.platform == 'win32':
75 # Escape \ for Vim, and ^ for both Vim and shell. 75 # Escape \ for Vim, and ^ for both Vim and shell.
76 build_cmd = build_cmd.replace('\\', '\\\\').replace('^', '^^^^') 76 build_cmd = build_cmd.replace('\\', '\\\\').replace('^', '^^^^')
77 vim.command('let &makeprg=\'%s\'' % build_cmd) 77 vim.command('return "%s"' % build_cmd)
78
79
80 def compute_ninja_command_for_targets(targets='', configuration=None):
81 if not configuration: configuration = guess_configuration()
82 build_dir = os.path.join(path_to_source_root(), 'out', configuration)
83 build_cmd = ' '.join(['ninja', '-C', build_dir, targets])
84 vim.command('return "%s"' % build_cmd)
78 endpython 85 endpython
79 86
80 fun! CrCompileFile() 87 fun! s:MakeWithCustomCommand(build_cmd)
81 let l:oldmakepgr = &makeprg 88 let l:oldmakepgr = &makeprg
82 python set_makepgr_to_single_file_ninja() 89 let &makeprg=a:build_cmd
83 silent make | cwindow 90 silent make | cwindow
84 if !has('gui_running') 91 if !has('gui_running')
85 redraw! 92 redraw!
86 endif 93 endif
87 let &makeprg = l:oldmakepgr 94 let &makeprg = l:oldmakepgr
88 endfun 95 endfun
89 96
97 fun! s:NinjaCommandForCurrentBuffer()
98 python compute_ninja_command_for_current_buffer()
99 endfun
100
101 fun! s:NinjaCommandForTargets(targets)
102 python compute_ninja_command_for_targets(vim.eval('a:targets'))
103 endfun
104
105 fun! CrCompileFile()
106 call s:MakeWithCustomCommand(s:NinjaCommandForCurrentBuffer())
107 endfun
108
109 fun! CrBuild(...)
110 let l:targets = a:0 > 0 ? join(a:000, ' ') : ''
111 if (l:targets !~ "\i")
112 let l:targets = 'chrome'
113 endif
114 call s:MakeWithCustomCommand(s:NinjaCommandForTargets(l:targets))
115 endfun
116
90 command! CrCompileFile call CrCompileFile() 117 command! CrCompileFile call CrCompileFile()
118 command! -nargs=* CrBuild call CrBuild(<q-args>)
91 119
92 if has('mac') 120 if has('mac')
93 map <D-k> :CrCompileFile<cr> 121 map <D-k> :CrCompileFile<cr>
94 imap <D-k> <esc>:CrCompileFile<cr> 122 imap <D-k> <esc>:CrCompileFile<cr>
95 elseif has('win32') 123 elseif has('win32')
96 map <C-F7> :CrCompileFile<cr> 124 map <C-F7> :CrCompileFile<cr>
97 imap <C-F7> <esc>:CrCompileFile<cr> 125 imap <C-F7> <esc>:CrCompileFile<cr>
98 elseif has('unix') 126 elseif has('unix')
99 map <Leader>o :CrCompileFile<cr> 127 map <Leader>o :CrCompileFile<cr>
100 endif 128 endif
OLDNEW
« 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