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