diff options
author | tobiasjs <tobiasjs@chromium.org> | 2015-09-10 00:37:51 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-10 07:38:43 +0000 |
commit | dd4006af5cf5e6711512278e89da7bb1794d84c3 (patch) | |
tree | c26370a3bb9b6c4853b0959371c8544cd999ce8d | |
parent | bf767fa84b99bc601a632839a999ccaa1572519a (diff) | |
download | chromium_src-dd4006af5cf5e6711512278e89da7bb1794d84c3.zip chromium_src-dd4006af5cf5e6711512278e89da7bb1794d84c3.tar.gz chromium_src-dd4006af5cf5e6711512278e89da7bb1794d84c3.tar.bz2 |
Change fallback ninja output_dir detection to test dirs matching out*/.
BUG=
Review URL: https://codereview.chromium.org/1326333002
Cr-Commit-Position: refs/heads/master@{#348115}
-rw-r--r-- | tools/vim/ninja_output.py | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/tools/vim/ninja_output.py b/tools/vim/ninja_output.py index e343c5b..a2d1268 100644 --- a/tools/vim/ninja_output.py +++ b/tools/vim/ninja_output.py @@ -3,22 +3,29 @@ # found in the LICENSE file. +import sys import os -import os.path +import exceptions +import itertools 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_*. + If either of the following environment variables are set, their + value is used to determine the output directory: + 1. CHROMIUM_OUT_DIR environment variable. + 2. GYP_GENERATOR_FLAGS environment variable output_dir property. - The configuration chosen is the one most recently generated/built, but can be - overriden via the <configuration> parameter.""" + Otherwise, all directories starting with the word out are examined. + + The output directory must contain {configuration}/build.ninja (if + configuration is None, both Debug and Release will be checked). + + The configuration chosen is the one most recently generated/built, + but can be overriden via the <configuration> parameter. + """ output_dirs = [] if ('CHROMIUM_OUT_DIR' in os.environ and @@ -32,26 +39,32 @@ def GetNinjaOutputDirectory(chrome_root, configuration=None): 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) + if re.match(r'out\b', f): + out = os.path.realpath(os.path.join(chrome_root, f)) + if os.path.isdir(out): + output_dirs.append(os.path.relpath(out, start = chrome_root)) 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 generate_paths(): + for out_dir, config in itertools.product(output_dirs, configs): + path = os.path.join(chrome_root, out_dir, config) + if os.path.exists(os.path.join(path, 'build.ninja')): + yield path 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) + try: + return max(generate_paths(), key=approx_directory_mtime) + except ValueError: + raise exceptions.RuntimeError( + 'Unable to find a valid ninja output directory.') + +if __name__ == '__main__': + if len(sys.argv) != 2: + raise exceptions.RuntimeError('Expected a single path argument.') + print GetNinjaOutputDirectory(sys.argv[1]) |