| Index: tools/vim/ninja_output.py
 | 
| diff --git a/tools/vim/ninja_output.py b/tools/vim/ninja_output.py
 | 
| index f6d41d592dc92bbdd2a1b1deca73366e6ddfa1d7..e343c5b7f2db8918348f6ea0d0416a5cf34ae56e 100644
 | 
| --- a/tools/vim/ninja_output.py
 | 
| +++ b/tools/vim/ninja_output.py
 | 
| @@ -5,40 +5,53 @@
 | 
|  
 | 
|  import os
 | 
|  import os.path
 | 
| +import re
 | 
|  
 | 
|  
 | 
|  def GetNinjaOutputDirectory(chrome_root, configuration=None):
 | 
|    """Returns <chrome_root>/<output_dir>/(Release|Debug).
 | 
|  
 | 
| +  The output_dir is detected in the following ways, in order of precedence:
 | 
| +  1. CHROMIUM_OUT_DIR environment variable.
 | 
| +  2. GYP_GENERATOR_FLAGS environment variable output_dir property.
 | 
| +  3. Symlink target, if src/out is a symlink.
 | 
| +  4. Most recently modified (e.g. built) directory called out or out_*.
 | 
| +
 | 
|    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
 | 
| +  overriden via the <configuration> parameter."""
 | 
| +
 | 
| +  output_dirs = []
 | 
| +  if ('CHROMIUM_OUT_DIR' in os.environ and
 | 
| +      os.path.isdir(os.path.join(chrome_root, os.environ['CHROMIUM_OUT_DIR']))):
 | 
| +    output_dirs = [os.environ['CHROMIUM_OUT_DIR']]
 | 
| +  if not output_dirs:
 | 
| +    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' and
 | 
| +          os.path.isdir(os.path.join(chrome_root, name_value[1]))):
 | 
| +        output_dirs = [name_value[1]]
 | 
| +  if not output_dirs:
 | 
| +    out = os.path.join(chrome_root, 'out')
 | 
| +    if os.path.islink(out):
 | 
| +      out_target = os.path.join(os.path.dirname(out), os.readlink(out))
 | 
| +      if os.path.exists(out_target):
 | 
| +        output_dirs = [out_target]
 | 
| +  if not output_dirs:
 | 
| +    for f in os.listdir(chrome_root):
 | 
| +      if (re.match('out(?:$|_)', f) and
 | 
| +          os.path.isdir(os.path.join(chrome_root, f))):
 | 
| +        output_dirs.append(f)
 | 
| +
 | 
| +  configs = [configuration] if configuration else ['Debug', 'Release']
 | 
| +  output_paths = [os.path.join(chrome_root, out_dir, config)
 | 
| +                  for out_dir in output_dirs for config in configs]
 | 
| +
 | 
| +  def approx_directory_mtime(path):
 | 
| +    if not os.path.exists(path):
 | 
| +      return -1
 | 
| +    # This is a heuristic; don't recurse into subdirectories.
 | 
| +    paths = [path] + [os.path.join(path, f) for f in os.listdir(path)]
 | 
| +    return max(os.path.getmtime(p) for p in paths)
 | 
| +
 | 
| +  return max(output_paths, key=approx_directory_mtime)
 | 
| 
 |