| 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 a hook. If it detects that the build should |
| 8 the build should be clobbered, it will remove the build directory. | 8 be clobbered, it will touch the file <build_dir>/.landmine_triggered. The |
| 9 various build scripts will then check for the presence of this file and clobber |
| 10 accordingly. The script will also emit the reasons for the clobber to stdout. |
| 9 | 11 |
| 10 A landmine is tripped when a builder checks out a different revision, and the | 12 A landmine is tripped when a builder checks out a different revision, and the |
| 11 diff between the new landmines and the old ones is non-null. At this point, the | 13 diff between the new landmines and the old ones is non-null. At this point, the |
| 12 build is clobbered. | 14 build is clobbered. |
| 13 """ | 15 """ |
| 14 | 16 |
| 15 import difflib | 17 import difflib |
| 16 import errno | 18 import errno |
| 17 import gyp_environment | |
| 18 import logging | 19 import logging |
| 19 import optparse | 20 import optparse |
| 20 import os | 21 import os |
| 21 import shutil | |
| 22 import sys | 22 import sys |
| 23 import subprocess | 23 import subprocess |
| 24 import time | 24 import time |
| 25 | 25 |
| 26 import landmine_utils | 26 import landmine_utils |
| 27 | 27 |
| 28 | 28 |
| 29 SRC_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) | 29 SRC_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) |
| 30 | 30 |
| 31 | 31 |
| 32 def get_build_dir(build_tool, is_iphone=False): | 32 def get_target_build_dir(build_tool, target, is_iphone=False): |
| 33 """ | 33 """ |
| 34 Returns output directory absolute path dependent on build and targets. | 34 Returns output directory absolute path dependent on build and targets. |
| 35 Examples: | 35 Examples: |
| 36 r'c:\b\build\slave\win\build\src\out' | 36 r'c:\b\build\slave\win\build\src\out\Release' |
| 37 '/mnt/data/b/build/slave/linux/build/src/out' | 37 '/mnt/data/b/build/slave/linux/build/src/out/Debug' |
| 38 '/b/build/slave/ios_rel_device/build/src/xcodebuild' | 38 '/b/build/slave/ios_rel_device/build/src/xcodebuild/Release-iphoneos' |
| 39 | 39 |
| 40 Keep this function in sync with tools/build/scripts/slave/compile.py | 40 Keep this function in sync with tools/build/scripts/slave/compile.py |
| 41 """ | 41 """ |
| 42 ret = None | 42 ret = None |
| 43 if build_tool == 'xcode': | 43 if build_tool == 'xcode': |
| 44 ret = os.path.join(SRC_DIR, 'xcodebuild') | 44 ret = os.path.join(SRC_DIR, 'xcodebuild', |
| 45 target + ('-iphoneos' if is_iphone else '')) |
| 45 elif build_tool in ['make', 'ninja', 'ninja-ios']: # TODO: Remove ninja-ios. | 46 elif build_tool in ['make', 'ninja', 'ninja-ios']: # TODO: Remove ninja-ios. |
| 46 ret = os.path.join(SRC_DIR, 'out') | 47 ret = os.path.join(SRC_DIR, 'out', target) |
| 47 elif build_tool in ['msvs', 'vs', 'ib']: | 48 elif build_tool in ['msvs', 'vs', 'ib']: |
| 48 ret = os.path.join(SRC_DIR, 'build') | 49 ret = os.path.join(SRC_DIR, 'build', target) |
| 49 else: | 50 else: |
| 50 raise NotImplementedError('Unexpected GYP_GENERATORS (%s)' % build_tool) | 51 raise NotImplementedError('Unexpected GYP_GENERATORS (%s)' % build_tool) |
| 51 return os.path.abspath(ret) | 52 return os.path.abspath(ret) |
| 52 | 53 |
| 53 | 54 |
| 54 def clobber_if_necessary(new_landmines): | 55 def set_up_landmines(target, new_landmines): |
| 55 """Does the work of setting, planting, and triggering landmines.""" | 56 """Does the work of setting, planting, and triggering landmines.""" |
| 56 out_dir = get_build_dir(landmine_utils.builder()) | 57 out_dir = get_target_build_dir(landmine_utils.builder(), target, |
| 57 landmines_path = os.path.normpath(os.path.join(out_dir, '..', '.landmines')) | 58 landmine_utils.platform() == 'ios') |
| 59 |
| 60 landmines_path = os.path.join(out_dir, '.landmines') |
| 58 try: | 61 try: |
| 59 os.makedirs(out_dir) | 62 os.makedirs(out_dir) |
| 60 except OSError as e: | 63 except OSError as e: |
| 61 if e.errno == errno.EEXIST: | 64 if e.errno == errno.EEXIST: |
| 62 pass | 65 pass |
| 63 | 66 |
| 64 if os.path.exists(landmines_path): | 67 if os.path.exists(landmines_path): |
| 68 triggered = os.path.join(out_dir, '.landmines_triggered') |
| 65 with open(landmines_path, 'r') as f: | 69 with open(landmines_path, 'r') as f: |
| 66 old_landmines = f.readlines() | 70 old_landmines = f.readlines() |
| 67 if old_landmines != new_landmines: | 71 if old_landmines != new_landmines: |
| 68 old_date = time.ctime(os.stat(landmines_path).st_ctime) | 72 old_date = time.ctime(os.stat(landmines_path).st_ctime) |
| 69 diff = difflib.unified_diff(old_landmines, new_landmines, | 73 diff = difflib.unified_diff(old_landmines, new_landmines, |
| 70 fromfile='old_landmines', tofile='new_landmines', | 74 fromfile='old_landmines', tofile='new_landmines', |
| 71 fromfiledate=old_date, tofiledate=time.ctime(), n=0) | 75 fromfiledate=old_date, tofiledate=time.ctime(), n=0) |
| 72 sys.stdout.write('Clobbering due to:\n') | |
| 73 sys.stdout.writelines(diff) | |
| 74 | 76 |
| 75 # Clobber. | 77 with open(triggered, 'w') as f: |
| 76 shutil.rmtree(out_dir) | 78 f.writelines(diff) |
| 77 | 79 elif os.path.exists(triggered): |
| 78 # Save current set of landmines for next time. | 80 # Remove false triggered landmines. |
| 81 os.remove(triggered) |
| 79 with open(landmines_path, 'w') as f: | 82 with open(landmines_path, 'w') as f: |
| 80 f.writelines(new_landmines) | 83 f.writelines(new_landmines) |
| 81 | 84 |
| 82 | 85 |
| 83 def process_options(): | 86 def process_options(): |
| 84 """Returns a list of landmine emitting scripts.""" | 87 """Returns a list of landmine emitting scripts.""" |
| 85 parser = optparse.OptionParser() | 88 parser = optparse.OptionParser() |
| 86 parser.add_option( | 89 parser.add_option( |
| 87 '-s', '--landmine-scripts', action='append', | 90 '-s', '--landmine-scripts', action='append', |
| 88 default=[os.path.join(SRC_DIR, 'build', 'get_landmines.py')], | 91 default=[os.path.join(SRC_DIR, 'build', 'get_landmines.py')], |
| (...skipping 20 matching lines...) Expand all Loading... |
| 109 else: | 112 else: |
| 110 return options.landmine_scripts | 113 return options.landmine_scripts |
| 111 | 114 |
| 112 | 115 |
| 113 def main(): | 116 def main(): |
| 114 landmine_scripts = process_options() | 117 landmine_scripts = process_options() |
| 115 | 118 |
| 116 if landmine_utils.builder() in ('dump_dependency_json', 'eclipse'): | 119 if landmine_utils.builder() in ('dump_dependency_json', 'eclipse'): |
| 117 return 0 | 120 return 0 |
| 118 | 121 |
| 119 gyp_environment.SetEnvironment() | 122 for target in ('Debug', 'Release', 'Debug_x64', 'Release_x64'): |
| 120 | 123 landmines = [] |
| 121 landmines = [] | 124 for s in landmine_scripts: |
| 122 for s in landmine_scripts: | 125 proc = subprocess.Popen([sys.executable, s, '-t', target], |
| 123 proc = subprocess.Popen([sys.executable, s], stdout=subprocess.PIPE) | 126 stdout=subprocess.PIPE) |
| 124 output, _ = proc.communicate() | 127 output, _ = proc.communicate() |
| 125 landmines.extend([('%s\n' % l.strip()) for l in output.splitlines()]) | 128 landmines.extend([('%s\n' % l.strip()) for l in output.splitlines()]) |
| 126 clobber_if_necessary(landmines) | 129 set_up_landmines(target, landmines) |
| 127 | 130 |
| 128 return 0 | 131 return 0 |
| 129 | 132 |
| 130 | 133 |
| 131 if __name__ == '__main__': | 134 if __name__ == '__main__': |
| 132 sys.exit(main()) | 135 sys.exit(main()) |
| OLD | NEW |