Chromium Code Reviews| OLD | NEW |
|---|---|
| 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). |
| 7 " | 7 " |
| 8 " Requires that gyp has already generated build.ninja files, and that ninja is | 8 " 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). | 9 " in your path (which it is automatically if depot_tools is in your path). |
| 10 " | 10 " |
|
Nico
2012/10/15 22:41:35
Can you mention this up here too?
enne (OOO)
2012/10/16 00:09:17
Done.
| |
| 11 " Add the following to your .vimrc file: | 11 " Add the following to your .vimrc file: |
| 12 " so /path/to/src/tools/vim/ninja-build.vim | 12 " so /path/to/src/tools/vim/ninja-build.vim |
| 13 | 13 |
| 14 python << endpython | 14 python << endpython |
| 15 import os | 15 import os |
| 16 import vim | 16 import vim |
| 17 | 17 |
| 18 | 18 |
| 19 def path_to_current_buffer(): | 19 def path_to_current_buffer(): |
| 20 """Returns the absolute path of the current buffer.""" | 20 """Returns the absolute path of the current buffer.""" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 49 rel_mtime = os.path.getmtime(os.path.join(root, 'Release', test_path)) | 49 rel_mtime = os.path.getmtime(os.path.join(root, 'Release', test_path)) |
| 50 except os.error: | 50 except os.error: |
| 51 rel_mtime = 0 | 51 rel_mtime = 0 |
| 52 return rel_mtime - debug_mtime >= 15 | 52 return rel_mtime - debug_mtime >= 15 |
| 53 configuration = 'Debug' | 53 configuration = 'Debug' |
| 54 if is_release_15s_newer('build.ninja') or is_release_15s_newer('protoc'): | 54 if is_release_15s_newer('build.ninja') or is_release_15s_newer('protoc'): |
| 55 configuration = 'Release' | 55 configuration = 'Release' |
| 56 return configuration | 56 return configuration |
| 57 | 57 |
| 58 | 58 |
| 59 def compute_ninja_command(configuration=None): | 59 def compute_ninja_command_for_current_buffer(configuration=None): |
| 60 """Returns the shell command to compile the file in the current buffer.""" | 60 """Returns the shell command to compile the file in the current buffer.""" |
| 61 if not configuration: configuration = guess_configuration() | 61 if not configuration: configuration = guess_configuration() |
| 62 build_dir = os.path.join(path_to_source_root(), 'out', configuration) | 62 build_dir = os.path.join(path_to_source_root(), 'out', configuration) |
| 63 | 63 |
| 64 # ninja needs filepaths for the ^ syntax to be relative to the | 64 # ninja needs filepaths for the ^ syntax to be relative to the |
| 65 # build directory. | 65 # build directory. |
| 66 file_to_build = path_to_current_buffer() | 66 file_to_build = path_to_current_buffer() |
| 67 file_to_build = os.path.relpath(file_to_build, build_dir) | 67 file_to_build = os.path.relpath(file_to_build, build_dir) |
| 68 | 68 |
| 69 return ' '.join(['ninja', '-C', build_dir, file_to_build + '^']) | 69 return ' '.join(['ninja', '-C', build_dir, file_to_build + '^']) |
| 70 | 70 |
| 71 | 71 |
| 72 def set_makepgr_to_single_file_ninja(): | 72 def set_makepgr_to_single_file_ninja(): |
| 73 build_cmd = compute_ninja_command() | 73 build_cmd = compute_ninja_command_for_current_buffer() |
| 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('let &makeprg=\'%s\'' % build_cmd) |
| 78 | |
| 79 | |
| 80 def compute_ninja_command_for_target(target='', configuration=None): | |
| 81 if not configuration: configuration = guess_configuration() | |
| 82 build_dir = os.path.join(path_to_source_root(), 'out', configuration) | |
| 83 return ' '.join(['ninja', '-C', build_dir, target]) | |
| 84 | |
| 85 | |
| 86 def set_makepgr_to_target_ninja(target=''): | |
| 87 vim.command('let &makeprg=\'%s\'' % compute_ninja_command_for_target(target)) | |
| 78 endpython | 88 endpython |
| 79 | 89 |
| 80 fun! CrCompileFile() | 90 fun! CrCompileFile() |
| 81 let l:oldmakepgr = &makeprg | 91 let l:oldmakepgr = &makeprg |
| 82 python set_makepgr_to_single_file_ninja() | 92 python set_makepgr_to_single_file_ninja() |
| 83 silent make | cwindow | 93 silent make | cwindow |
| 84 if !has('gui_running') | 94 if !has('gui_running') |
| 85 redraw! | 95 redraw! |
| 86 endif | 96 endif |
| 87 let &makeprg = l:oldmakepgr | 97 let &makeprg = l:oldmakepgr |
| 88 endfun | 98 endfun |
| 89 | 99 |
| 100 fun! CrCompileTarget(...) | |
|
Nico
2012/10/15 22:41:35
This does more than just compiling. Maybe CrBuildT
enne (OOO)
2012/10/16 00:09:17
I have mixed feelings about default building chrom
| |
| 101 let l:oldmakepgr = &makeprg | |
| 102 let l:target = a:0 > 0 ? a:1 : '' | |
| 103 python set_makepgr_to_target_ninja(vim.eval('l:target')) | |
| 104 silent make | cwindow | |
| 105 if !has('gui_running') | |
| 106 redraw! | |
| 107 endif | |
| 108 let &makeprg = l:oldmakepgr | |
| 109 endfun | |
|
Nico
2012/10/15 22:41:35
Can you think of a way to not make this function l
enne (OOO)
2012/10/16 00:09:17
Yeah, yeah. I was optimizing for minimal vimscrip
| |
| 110 | |
| 90 command! CrCompileFile call CrCompileFile() | 111 command! CrCompileFile call CrCompileFile() |
| 112 command! -nargs=? CrCompileTarget call CrCompileTarget(<args>) | |
| 91 | 113 |
| 92 if has('mac') | 114 if has('mac') |
| 93 map <D-k> :CrCompileFile<cr> | 115 map <D-k> :CrCompileFile<cr> |
| 94 imap <D-k> <esc>:CrCompileFile<cr> | 116 imap <D-k> <esc>:CrCompileFile<cr> |
| 95 elseif has('win32') | 117 elseif has('win32') |
| 96 map <C-F7> :CrCompileFile<cr> | 118 map <C-F7> :CrCompileFile<cr> |
| 97 imap <C-F7> <esc>:CrCompileFile<cr> | 119 imap <C-F7> <esc>:CrCompileFile<cr> |
| 98 elseif has('unix') | 120 elseif has('unix') |
| 99 map <Leader>o :CrCompileFile<cr> | 121 map <Leader>o :CrCompileFile<cr> |
| 100 endif | 122 endif |
| OLD | NEW |