OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """ | 6 """ |
7 This script runs every build as the first hook (See DEPS). If it detects that | 7 This script runs every build as the first hook (See DEPS). If it detects that |
8 the build should be clobbered, it will delete the contents of the build | 8 the build should be clobbered, it will delete the contents of the build |
9 directory. | 9 directory. |
10 | 10 |
11 A landmine is tripped when a builder checks out a different revision, and the | 11 A landmine is tripped when a builder checks out a different revision, and the |
12 diff between the new landmines and the old ones is non-null. At this point, the | 12 diff between the new landmines and the old ones is non-null. At this point, the |
13 build is clobbered. | 13 build is clobbered. |
14 """ | 14 """ |
15 | 15 |
16 import difflib | 16 import difflib |
17 import errno | 17 import errno |
18 import gyp_environment | 18 import gyp_environment |
19 import logging | 19 import logging |
20 import optparse | 20 import optparse |
21 import os | 21 import os |
22 import sys | 22 import sys |
23 import subprocess | 23 import subprocess |
24 import time | 24 import time |
25 | 25 |
26 import clobber | 26 import clobber |
27 import landmine_utils | 27 import landmine_utils |
28 | 28 |
29 | 29 |
30 def get_build_dir(src_dir): | 30 def get_build_dir(build_tool, src_dir, is_iphone=False): |
31 """ | 31 """ |
32 Returns output directory absolute path dependent on build and targets. | 32 Returns output directory absolute path dependent on build and targets. |
33 Examples: | 33 Examples: |
34 r'c:\b\build\slave\win\build\src\out' | 34 r'c:\b\build\slave\win\build\src\out' |
35 '/mnt/data/b/build/slave/linux/build/src/out' | 35 '/mnt/data/b/build/slave/linux/build/src/out' |
36 '/b/build/slave/ios_rel_device/build/src/out' | 36 '/b/build/slave/ios_rel_device/build/src/xcodebuild' |
37 | 37 |
38 Keep this function in sync with tools/build/scripts/slave/compile.py | 38 Keep this function in sync with tools/build/scripts/slave/compile.py |
39 """ | 39 """ |
40 if 'CHROMIUM_OUT_DIR' in os.environ: | 40 ret = None |
41 output_dir = os.environ.get('CHROMIUM_OUT_DIR').strip() | 41 if build_tool == 'xcode': |
42 if not output_dir: | 42 ret = os.path.join(src_dir, 'xcodebuild') |
43 raise Error('CHROMIUM_OUT_DIR environment variable is set but blank!') | 43 elif build_tool in ['make', 'ninja', 'ninja-ios']: # TODO: Remove ninja-ios. |
| 44 if 'CHROMIUM_OUT_DIR' in os.environ: |
| 45 output_dir = os.environ.get('CHROMIUM_OUT_DIR').strip() |
| 46 if not output_dir: |
| 47 raise Error('CHROMIUM_OUT_DIR environment variable is set but blank!') |
| 48 else: |
| 49 output_dir = landmine_utils.gyp_generator_flags().get('output_dir', 'out') |
| 50 ret = os.path.join(src_dir, output_dir) |
44 else: | 51 else: |
45 output_dir = landmine_utils.gyp_generator_flags().get('output_dir', 'out') | 52 raise NotImplementedError('Unexpected GYP_GENERATORS (%s)' % build_tool) |
46 return os.path.abspath(os.path.join(src_dir, output_dir)) | 53 return os.path.abspath(ret) |
47 | 54 |
48 | 55 |
49 def clobber_if_necessary(new_landmines, src_dir): | 56 def clobber_if_necessary(new_landmines, src_dir): |
50 """Does the work of setting, planting, and triggering landmines.""" | 57 """Does the work of setting, planting, and triggering landmines.""" |
51 out_dir = get_build_dir(src_dir) | 58 out_dir = get_build_dir(landmine_utils.builder(), src_dir) |
52 landmines_path = os.path.normpath(os.path.join(src_dir, '.landmines')) | 59 landmines_path = os.path.normpath(os.path.join(src_dir, '.landmines')) |
53 try: | 60 try: |
54 os.makedirs(out_dir) | 61 os.makedirs(out_dir) |
55 except OSError as e: | 62 except OSError as e: |
56 if e.errno == errno.EEXIST: | 63 if e.errno == errno.EEXIST: |
57 pass | 64 pass |
58 | 65 |
59 if os.path.exists(landmines_path): | 66 if os.path.exists(landmines_path): |
60 with open(landmines_path, 'r') as f: | 67 with open(landmines_path, 'r') as f: |
61 old_landmines = f.readlines() | 68 old_landmines = f.readlines() |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 extra_script = os.environ.get('EXTRA_LANDMINES_SCRIPT') | 122 extra_script = os.environ.get('EXTRA_LANDMINES_SCRIPT') |
116 if extra_script: | 123 if extra_script: |
117 options.landmine_scripts += [extra_script] | 124 options.landmine_scripts += [extra_script] |
118 | 125 |
119 return options | 126 return options |
120 | 127 |
121 | 128 |
122 def main(): | 129 def main(): |
123 options = process_options() | 130 options = process_options() |
124 | 131 |
| 132 if landmine_utils.builder() in ('dump_dependency_json', 'eclipse'): |
| 133 return 0 |
| 134 |
125 gyp_environment.SetEnvironment() | 135 gyp_environment.SetEnvironment() |
126 | 136 |
127 landmines = [] | 137 landmines = [] |
128 for s in options.landmine_scripts: | 138 for s in options.landmine_scripts: |
129 proc = subprocess.Popen([sys.executable, s], stdout=subprocess.PIPE) | 139 proc = subprocess.Popen([sys.executable, s], stdout=subprocess.PIPE) |
130 output, _ = proc.communicate() | 140 output, _ = proc.communicate() |
131 landmines.extend([('%s\n' % l.strip()) for l in output.splitlines()]) | 141 landmines.extend([('%s\n' % l.strip()) for l in output.splitlines()]) |
132 clobber_if_necessary(landmines, options.src_dir) | 142 clobber_if_necessary(landmines, options.src_dir) |
133 | 143 |
134 return 0 | 144 return 0 |
135 | 145 |
136 | 146 |
137 if __name__ == '__main__': | 147 if __name__ == '__main__': |
138 sys.exit(main()) | 148 sys.exit(main()) |
OLD | NEW |