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

Side by Side Diff: tools/vim/ninja_output.py

Issue 1940753002: Enable YouCompleteMe and :CrCompile to find GN build directory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change from 'out/Debug' to 'out/gn' directory in tests. Created 4 years, 7 months 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/ninja-build.vim ('k') | tools/vim/tests/chromium.ycm_extra_conf_unittest.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 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 5
6 import sys 6 import sys
7 import os 7 import os
8 import exceptions 8 import exceptions
9 import itertools 9 import itertools
10 import re 10 import re
11 11
12 12
13 def GetNinjaOutputDirectory(chrome_root, configuration=None): 13 def GetNinjaOutputDirectory(chrome_root):
14 """Returns <chrome_root>/<output_dir>/(Release|Debug). 14 """Returns <chrome_root>/<output_dir>/(Release|Debug|<other>).
15 15
16 If either of the following environment variables are set, their 16 If either of the following environment variables are set, their
17 value is used to determine the output directory: 17 value is used to determine the output directory:
18 1. CHROMIUM_OUT_DIR environment variable. 18 1. CHROMIUM_OUT_DIR environment variable.
19 2. GYP_GENERATOR_FLAGS environment variable output_dir property. 19 2. GYP_GENERATOR_FLAGS environment variable output_dir property.
20 20
21 Otherwise, all directories starting with the word out are examined. 21 Otherwise, all directories starting with the word out are examined.
22 22
23 The output directory must contain {configuration}/build.ninja (if 23 The configuration chosen is the one most recently generated/built.
24 configuration is None, both Debug and Release will be checked).
25
26 The configuration chosen is the one most recently generated/built,
27 but can be overriden via the <configuration> parameter.
28 """ 24 """
29 25
30 output_dirs = [] 26 output_dirs = []
31 if ('CHROMIUM_OUT_DIR' in os.environ and 27 if ('CHROMIUM_OUT_DIR' in os.environ and
32 os.path.isdir(os.path.join(chrome_root, os.environ['CHROMIUM_OUT_DIR']))): 28 os.path.isdir(os.path.join(chrome_root, os.environ['CHROMIUM_OUT_DIR']))):
33 output_dirs = [os.environ['CHROMIUM_OUT_DIR']] 29 output_dirs = [os.environ['CHROMIUM_OUT_DIR']]
34 if not output_dirs: 30 if not output_dirs:
35 generator_flags = os.getenv('GYP_GENERATOR_FLAGS', '').split(' ') 31 generator_flags = os.getenv('GYP_GENERATOR_FLAGS', '').split(' ')
36 for flag in generator_flags: 32 for flag in generator_flags:
37 name_value = flag.split('=', 1) 33 name_value = flag.split('=', 1)
38 if (len(name_value) == 2 and name_value[0] == 'output_dir' and 34 if (len(name_value) == 2 and name_value[0] == 'output_dir' and
39 os.path.isdir(os.path.join(chrome_root, name_value[1]))): 35 os.path.isdir(os.path.join(chrome_root, name_value[1]))):
40 output_dirs = [name_value[1]] 36 output_dirs = [name_value[1]]
41 if not output_dirs: 37 if not output_dirs:
42 for f in os.listdir(chrome_root): 38 for f in os.listdir(chrome_root):
43 if re.match(r'out(\b|_)', f): 39 if re.match(r'out(\b|_)', f):
44 out = os.path.realpath(os.path.join(chrome_root, f)) 40 out = os.path.realpath(os.path.join(chrome_root, f))
45 if os.path.isdir(out): 41 if os.path.isdir(out):
46 output_dirs.append(os.path.relpath(out, start = chrome_root)) 42 output_dirs.append(os.path.relpath(out, start = chrome_root))
47 43
48 configs = ['Debug', 'Release', 'Default']
49 if configuration:
50 configs = [configuration]
51
52 def generate_paths(): 44 def generate_paths():
53 for out_dir, config in itertools.product(output_dirs, configs): 45 for out_dir in output_dirs:
54 path = os.path.join(chrome_root, out_dir, config) 46 out_path = os.path.join(chrome_root, out_dir)
55 if os.path.exists(os.path.join(path, 'build.ninja')): 47 for config in os.listdir(out_path):
56 yield path 48 path = os.path.join(out_path, config)
49 if os.path.exists(os.path.join(path, 'build.ninja')):
50 yield path
57 51
58 def approx_directory_mtime(path): 52 def approx_directory_mtime(path):
59 # This is a heuristic; don't recurse into subdirectories. 53 # This is a heuristic; don't recurse into subdirectories.
60 paths = [path] + [os.path.join(path, f) for f in os.listdir(path)] 54 paths = [path] + [os.path.join(path, f) for f in os.listdir(path)]
61 return max(os.path.getmtime(p) for p in paths) 55 return max(os.path.getmtime(p) for p in paths)
62 56
63 try: 57 try:
64 return max(generate_paths(), key=approx_directory_mtime) 58 return max(generate_paths(), key=approx_directory_mtime)
65 except ValueError: 59 except ValueError:
66 raise exceptions.RuntimeError( 60 raise exceptions.RuntimeError(
67 'Unable to find a valid ninja output directory.') 61 'Unable to find a valid ninja output directory.')
68 62
69 if __name__ == '__main__': 63 if __name__ == '__main__':
70 if len(sys.argv) != 2: 64 if len(sys.argv) != 2:
71 raise exceptions.RuntimeError('Expected a single path argument.') 65 raise exceptions.RuntimeError('Expected a single path argument.')
72 print GetNinjaOutputDirectory(sys.argv[1]) 66 print GetNinjaOutputDirectory(sys.argv[1])
OLDNEW
« no previous file with comments | « tools/vim/ninja-build.vim ('k') | tools/vim/tests/chromium.ycm_extra_conf_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698