diff options
Diffstat (limited to 'tools/vim')
-rw-r--r-- | tools/vim/chromium.ycm_extra_conf.py | 37 | ||||
-rw-r--r-- | tools/vim/ninja-build.vim | 32 | ||||
-rw-r--r-- | tools/vim/ninja_output.py | 44 |
3 files changed, 56 insertions, 57 deletions
diff --git a/tools/vim/chromium.ycm_extra_conf.py b/tools/vim/chromium.ycm_extra_conf.py index 2e5318b..c0de648 100644 --- a/tools/vim/chromium.ycm_extra_conf.py +++ b/tools/vim/chromium.ycm_extra_conf.py @@ -40,6 +40,7 @@ import os import os.path import subprocess +import sys # Flags from YCM's default config. @@ -77,40 +78,6 @@ def FindChromeSrcFromFilename(filename): return os.path.join(curdir, 'src') -# Largely copied from ninja-build.vim (guess_configuration) -def GetNinjaOutputDirectory(chrome_root): - """Returns <chrome_root>/<output_dir>/(Release|Debug). - - The configuration chosen is the one most recently generated/built. Detects - a custom output_dir specified by GYP_GENERATOR_FLAGS.""" - - output_dir = 'out' - generator_flags = os.getenv('GYP_GENERATOR_FLAGS', '').split(' ') - for flag in generator_flags: - name_value = flag.split('=', 1) - if len(name_value) == 2 and name_value[0] == 'output_dir': - output_dir = name_value[1] - - root = os.path.join(chrome_root, output_dir) - debug_path = os.path.join(root, 'Debug') - release_path = os.path.join(root, 'Release') - - def is_release_15s_newer(test_path): - try: - debug_mtime = os.path.getmtime(os.path.join(debug_path, test_path)) - except os.error: - debug_mtime = 0 - try: - rel_mtime = os.path.getmtime(os.path.join(release_path, test_path)) - except os.error: - rel_mtime = 0 - return rel_mtime - debug_mtime >= 15 - - if is_release_15s_newer('build.ninja') or is_release_15s_newer('protoc'): - return release_path - return debug_path - - def GetClangCommandFromNinjaForFilename(chrome_root, filename): """Returns the command line to build |filename|. @@ -166,6 +133,8 @@ def GetClangCommandFromNinjaForFilename(chrome_root, filename): # try to use the default flags. return chrome_flags + sys.path.append(os.path.join(chrome_root, 'tools', 'vim')) + from ninja_output import GetNinjaOutputDirectory out_dir = os.path.realpath(GetNinjaOutputDirectory(chrome_root)) # Ninja needs the path to the source file relative to the output build diff --git a/tools/vim/ninja-build.vim b/tools/vim/ninja-build.vim index 852c5a9..6e14cba2 100644 --- a/tools/vim/ninja-build.vim +++ b/tools/vim/ninja-build.vim @@ -41,30 +41,17 @@ def path_to_source_root(): return candidate -def guess_configuration(): - """Default to the configuration with either a newer build.ninja or a newer - protoc.""" - root = os.path.join(path_to_source_root(), 'out') - def is_release_15s_newer(test_path): - try: - debug_mtime = os.path.getmtime(os.path.join(root, 'Debug', test_path)) - except os.error: - debug_mtime = 0 - try: - rel_mtime = os.path.getmtime(os.path.join(root, 'Release', test_path)) - except os.error: - rel_mtime = 0 - return rel_mtime - debug_mtime >= 15 - configuration = 'Debug' - if is_release_15s_newer('build.ninja') or is_release_15s_newer('protoc'): - configuration = 'Release' - return configuration +def path_to_build_dir(configuration): + """Returns <chrome_root>/<output_dir>/(Release|Debug).""" + chrome_root = path_to_source_root() + sys.path.append(os.path.join(chrome_root, 'tools', 'vim')) + from ninja_output import GetNinjaOutputDirectory + return GetNinjaOutputDirectory(chrome_root, configuration) 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) + build_dir = path_to_build_dir(configuration) # ninja needs filepaths for the ^ syntax to be relative to the # build directory. @@ -79,9 +66,8 @@ def compute_ninja_command_for_current_buffer(configuration=None): 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]) + build_cmd = ' '.join(['ninja', '-C', path_to_build_dir(configuration), + targets]) vim.command('return "%s"' % build_cmd) endpython diff --git a/tools/vim/ninja_output.py b/tools/vim/ninja_output.py new file mode 100644 index 0000000..f6d41d5 --- /dev/null +++ b/tools/vim/ninja_output.py @@ -0,0 +1,44 @@ +# Copyright 2014 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + + +import os +import os.path + + +def GetNinjaOutputDirectory(chrome_root, configuration=None): + """Returns <chrome_root>/<output_dir>/(Release|Debug). + + The configuration chosen is the one most recently generated/built, but can be + overriden via the <configuration> parameter. Detects a custom output_dir + specified by GYP_GENERATOR_FLAGS.""" + + output_dir = 'out' + generator_flags = os.getenv('GYP_GENERATOR_FLAGS', '').split(' ') + for flag in generator_flags: + name_value = flag.split('=', 1) + if len(name_value) == 2 and name_value[0] == 'output_dir': + output_dir = name_value[1] + + root = os.path.join(chrome_root, output_dir) + if configuration: + return os.path.join(root, configuration) + + debug_path = os.path.join(root, 'Debug') + release_path = os.path.join(root, 'Release') + + def is_release_15s_newer(test_path): + try: + debug_mtime = os.path.getmtime(os.path.join(debug_path, test_path)) + except os.error: + debug_mtime = 0 + try: + rel_mtime = os.path.getmtime(os.path.join(release_path, test_path)) + except os.error: + rel_mtime = 0 + return rel_mtime - debug_mtime >= 15 + + if is_release_15s_newer('build.ninja') or is_release_15s_newer('protoc'): + return release_path + return debug_path |