OLD | NEW |
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 |
(...skipping 22 matching lines...) Expand all Loading... |
33 output_dirs = [os.environ['CHROMIUM_OUT_DIR']] | 33 output_dirs = [os.environ['CHROMIUM_OUT_DIR']] |
34 if not output_dirs: | 34 if not output_dirs: |
35 generator_flags = os.getenv('GYP_GENERATOR_FLAGS', '').split(' ') | 35 generator_flags = os.getenv('GYP_GENERATOR_FLAGS', '').split(' ') |
36 for flag in generator_flags: | 36 for flag in generator_flags: |
37 name_value = flag.split('=', 1) | 37 name_value = flag.split('=', 1) |
38 if (len(name_value) == 2 and name_value[0] == 'output_dir' and | 38 if (len(name_value) == 2 and name_value[0] == 'output_dir' and |
39 os.path.isdir(os.path.join(chrome_root, name_value[1]))): | 39 os.path.isdir(os.path.join(chrome_root, name_value[1]))): |
40 output_dirs = [name_value[1]] | 40 output_dirs = [name_value[1]] |
41 if not output_dirs: | 41 if not output_dirs: |
42 for f in os.listdir(chrome_root): | 42 for f in os.listdir(chrome_root): |
43 if re.match(r'out\b', f): | 43 if re.match(r'out(\b|_)', f): |
44 out = os.path.realpath(os.path.join(chrome_root, f)) | 44 out = os.path.realpath(os.path.join(chrome_root, f)) |
45 if os.path.isdir(out): | 45 if os.path.isdir(out): |
46 output_dirs.append(os.path.relpath(out, start = chrome_root)) | 46 output_dirs.append(os.path.relpath(out, start = chrome_root)) |
47 | 47 |
48 configs = ['Debug', 'Release', 'Default'] | 48 configs = ['Debug', 'Release', 'Default'] |
49 if configuration: | 49 if configuration: |
50 configs = [configuration] | 50 configs = [configuration] |
51 | 51 |
52 def generate_paths(): | 52 def generate_paths(): |
53 for out_dir, config in itertools.product(output_dirs, configs): | 53 for out_dir, config in itertools.product(output_dirs, configs): |
54 path = os.path.join(chrome_root, out_dir, config) | 54 path = os.path.join(chrome_root, out_dir, config) |
55 if os.path.exists(os.path.join(path, 'build.ninja')): | 55 if os.path.exists(os.path.join(path, 'build.ninja')): |
56 yield path | 56 yield path |
57 | 57 |
58 def approx_directory_mtime(path): | 58 def approx_directory_mtime(path): |
59 # This is a heuristic; don't recurse into subdirectories. | 59 # This is a heuristic; don't recurse into subdirectories. |
60 paths = [path] + [os.path.join(path, f) for f in os.listdir(path)] | 60 paths = [path] + [os.path.join(path, f) for f in os.listdir(path)] |
61 return max(os.path.getmtime(p) for p in paths) | 61 return max(os.path.getmtime(p) for p in paths) |
62 | 62 |
63 try: | 63 try: |
64 return max(generate_paths(), key=approx_directory_mtime) | 64 return max(generate_paths(), key=approx_directory_mtime) |
65 except ValueError: | 65 except ValueError: |
66 raise exceptions.RuntimeError( | 66 raise exceptions.RuntimeError( |
67 'Unable to find a valid ninja output directory.') | 67 'Unable to find a valid ninja output directory.') |
68 | 68 |
69 if __name__ == '__main__': | 69 if __name__ == '__main__': |
70 if len(sys.argv) != 2: | 70 if len(sys.argv) != 2: |
71 raise exceptions.RuntimeError('Expected a single path argument.') | 71 raise exceptions.RuntimeError('Expected a single path argument.') |
72 print GetNinjaOutputDirectory(sys.argv[1]) | 72 print GetNinjaOutputDirectory(sys.argv[1]) |
OLD | NEW |