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

Side by Side Diff: tools/vim/ninja-build.vim

Issue 683113005: Update from chromium https://crrev.com/302282 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « tools/vim/chromium.ycm_extra_conf.py ('k') | tools/vim/ninja_output.py » ('j') | 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).
7 " On Linux, <Leader>o, which is \o by default ("o"=creates .o files) 7 " On Linux, <Leader>o, which is \o by default ("o"=creates .o files)
8 " 8 "
9 " Adds a "Build this target" function, using ninja. This is not bound 9 " Adds a "Build this target" function, using ninja. This is not bound
10 " to any key by default, but can be used via the :CrBuild command. 10 " to any key by default, but can be used via the :CrBuild command.
(...skipping 23 matching lines...) Expand all
34 # would find "src/v8" for files below "src/v8", as "src/v8/build/common.gypi" 34 # would find "src/v8" for files below "src/v8", as "src/v8/build/common.gypi"
35 # exists). The longer it is, the more likely it is to break when we rename 35 # exists). The longer it is, the more likely it is to break when we rename
36 # directories. 36 # directories.
37 fingerprints = ['chrome', 'net', 'v8', 'build', 'skia'] 37 fingerprints = ['chrome', 'net', 'v8', 'build', 'skia']
38 while candidate and not all( 38 while candidate and not all(
39 [os.path.isdir(os.path.join(candidate, fp)) for fp in fingerprints]): 39 [os.path.isdir(os.path.join(candidate, fp)) for fp in fingerprints]):
40 candidate = os.path.dirname(candidate) 40 candidate = os.path.dirname(candidate)
41 return candidate 41 return candidate
42 42
43 43
44 def guess_configuration(): 44 def path_to_build_dir(configuration):
45 """Default to the configuration with either a newer build.ninja or a newer 45 """Returns <chrome_root>/<output_dir>/(Release|Debug)."""
46 protoc."""
47 root = os.path.join(path_to_source_root(), 'out')
48 def is_release_15s_newer(test_path):
49 try:
50 debug_mtime = os.path.getmtime(os.path.join(root, 'Debug', test_path))
51 except os.error:
52 debug_mtime = 0
53 try:
54 rel_mtime = os.path.getmtime(os.path.join(root, 'Release', test_path))
55 except os.error:
56 rel_mtime = 0
57 return rel_mtime - debug_mtime >= 15
58 configuration = 'Debug'
59 if is_release_15s_newer('build.ninja') or is_release_15s_newer('protoc'):
60 configuration = 'Release'
61 return configuration
62 46
47 chrome_root = path_to_source_root()
48 sys.path.append(os.path.join(chrome_root, 'tools', 'vim'))
49 from ninja_output import GetNinjaOutputDirectory
50 return GetNinjaOutputDirectory(chrome_root, configuration)
63 51
64 def compute_ninja_command_for_current_buffer(configuration=None): 52 def compute_ninja_command_for_current_buffer(configuration=None):
65 """Returns the shell command to compile the file in the current buffer.""" 53 """Returns the shell command to compile the file in the current buffer."""
66 if not configuration: configuration = guess_configuration() 54 build_dir = path_to_build_dir(configuration)
67 build_dir = os.path.join(path_to_source_root(), 'out', configuration)
68 55
69 # ninja needs filepaths for the ^ syntax to be relative to the 56 # ninja needs filepaths for the ^ syntax to be relative to the
70 # build directory. 57 # build directory.
71 file_to_build = path_to_current_buffer() 58 file_to_build = path_to_current_buffer()
72 file_to_build = os.path.relpath(file_to_build, build_dir) 59 file_to_build = os.path.relpath(file_to_build, build_dir)
73 60
74 build_cmd = ' '.join(['ninja', '-C', build_dir, file_to_build + '^']) 61 build_cmd = ' '.join(['ninja', '-C', build_dir, file_to_build + '^'])
75 if sys.platform == 'win32': 62 if sys.platform == 'win32':
76 # Escape \ for Vim, and ^ for both Vim and shell. 63 # Escape \ for Vim, and ^ for both Vim and shell.
77 build_cmd = build_cmd.replace('\\', '\\\\').replace('^', '^^^^') 64 build_cmd = build_cmd.replace('\\', '\\\\').replace('^', '^^^^')
78 vim.command('return "%s"' % build_cmd) 65 vim.command('return "%s"' % build_cmd)
79 66
80 67
81 def compute_ninja_command_for_targets(targets='', configuration=None): 68 def compute_ninja_command_for_targets(targets='', configuration=None):
82 if not configuration: configuration = guess_configuration() 69 build_cmd = ' '.join(['ninja', '-C', path_to_build_dir(configuration),
83 build_dir = os.path.join(path_to_source_root(), 'out', configuration) 70 targets])
84 build_cmd = ' '.join(['ninja', '-C', build_dir, targets])
85 vim.command('return "%s"' % build_cmd) 71 vim.command('return "%s"' % build_cmd)
86 endpython 72 endpython
87 73
88 fun! s:MakeWithCustomCommand(build_cmd) 74 fun! s:MakeWithCustomCommand(build_cmd)
89 let l:oldmakepgr = &makeprg 75 let l:oldmakepgr = &makeprg
90 let &makeprg=a:build_cmd 76 let &makeprg=a:build_cmd
91 silent make | cwindow 77 silent make | cwindow
92 if !has('gui_running') 78 if !has('gui_running')
93 redraw! 79 redraw!
94 endif 80 endif
(...skipping 25 matching lines...) Expand all
120 106
121 if has('mac') 107 if has('mac')
122 map <D-k> :CrCompileFile<cr> 108 map <D-k> :CrCompileFile<cr>
123 imap <D-k> <esc>:CrCompileFile<cr> 109 imap <D-k> <esc>:CrCompileFile<cr>
124 elseif has('win32') 110 elseif has('win32')
125 map <C-F7> :CrCompileFile<cr> 111 map <C-F7> :CrCompileFile<cr>
126 imap <C-F7> <esc>:CrCompileFile<cr> 112 imap <C-F7> <esc>:CrCompileFile<cr>
127 elseif has('unix') 113 elseif has('unix')
128 map <Leader>o :CrCompileFile<cr> 114 map <Leader>o :CrCompileFile<cr>
129 endif 115 endif
OLDNEW
« no previous file with comments | « tools/vim/chromium.ycm_extra_conf.py ('k') | tools/vim/ninja_output.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698