Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2014 the V8 project authors. All rights reserved. | |
| 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 4 # Use of this source code is governed by a BSD-style license that can be | |
| 5 # found in the LICENSE file. | |
| 6 | |
| 7 """ | |
| 8 This script runs every build as a hook. If it detects that the build should | |
| 9 be clobbered, it will touch the file <build_dir>/.landmine_triggered. The | |
| 10 various build scripts will then check for the presence of this file and clobber | |
| 11 accordingly. The script will also emit the reasons for the clobber to stdout. | |
| 12 | |
| 13 A landmine is tripped when a builder checks out a different revision, and the | |
| 14 diff between the new landmines and the old ones is non-null. At this point, the | |
| 15 build is clobbered. | |
| 16 """ | |
| 17 | |
| 18 import difflib | |
| 19 import logging | |
| 20 import optparse | |
| 21 import os | |
| 22 import sys | |
| 23 import subprocess | |
| 24 import time | |
| 25 | |
| 26 import landmine_utils | |
| 27 | |
| 28 | |
| 29 SRC_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) | |
| 30 | |
| 31 | |
| 32 def get_target_build_dir(build_tool, target, is_iphone=False): | |
| 33 """ | |
| 34 Returns output directory absolute path dependent on build and targets. | |
| 35 Examples: | |
| 36 r'c:\b\build\slave\win\build\src\out\Release' | |
| 37 '/mnt/data/b/build/slave/linux/build/src/out/Debug' | |
| 38 '/b/build/slave/ios_rel_device/build/src/xcodebuild/Release-iphoneos' | |
| 39 | |
| 40 Keep this function in sync with tools/build/scripts/slave/compile.py | |
| 41 """ | |
| 42 ret = None | |
| 43 if build_tool == 'xcode': | |
| 44 ret = os.path.join(SRC_DIR, 'xcodebuild', | |
| 45 target + ('-iphoneos' if is_iphone else '')) | |
| 46 elif build_tool in ['make', 'ninja', 'ninja-ios']: # TODO: Remove ninja-ios. | |
| 47 ret = os.path.join(SRC_DIR, 'out', target) | |
| 48 elif build_tool in ['msvs', 'vs', 'ib']: | |
| 49 ret = os.path.join(SRC_DIR, 'build', target) | |
| 50 else: | |
| 51 raise NotImplementedError('Unexpected GYP_GENERATORS (%s)' % build_tool) | |
| 52 return os.path.abspath(ret) | |
| 53 | |
| 54 | |
| 55 def set_up_landmines(target, new_landmines): | |
| 56 """Does the work of setting, planting, and triggering landmines.""" | |
| 57 out_dir = get_target_build_dir(landmine_utils.builder(), target, | |
| 58 landmine_utils.platform() == 'ios') | |
| 59 | |
| 60 landmines_path = os.path.join(out_dir, '.landmines') | |
| 61 if not os.path.exists(out_dir): | |
|
Michael Achenbach
2014/07/22 14:04:45
The original script creates the dir here. I wonder
| |
| 62 return | |
| 63 | |
| 64 if os.path.exists(landmines_path): | |
| 65 triggered = os.path.join(out_dir, '.landmines_triggered') | |
| 66 with open(landmines_path, 'r') as f: | |
| 67 old_landmines = f.readlines() | |
| 68 if old_landmines != new_landmines: | |
| 69 old_date = time.ctime(os.stat(landmines_path).st_ctime) | |
| 70 diff = difflib.unified_diff(old_landmines, new_landmines, | |
| 71 fromfile='old_landmines', tofile='new_landmines', | |
| 72 fromfiledate=old_date, tofiledate=time.ctime(), n=0) | |
| 73 | |
| 74 with open(triggered, 'w') as f: | |
| 75 f.writelines(diff) | |
| 76 elif os.path.exists(triggered): | |
| 77 # Remove false triggered landmines. | |
| 78 os.remove(triggered) | |
| 79 with open(landmines_path, 'w') as f: | |
| 80 f.writelines(new_landmines) | |
| 81 | |
| 82 | |
| 83 def process_options(): | |
| 84 """Returns a list of landmine emitting scripts.""" | |
| 85 parser = optparse.OptionParser() | |
| 86 parser.add_option( | |
| 87 '-s', '--landmine-scripts', action='append', | |
| 88 default=[os.path.join(SRC_DIR, 'build', 'get_landmines.py')], | |
| 89 help='Path to the script which emits landmines to stdout. The target ' | |
| 90 'is passed to this script via option -t. Note that an extra ' | |
| 91 'script can be specified via an env var EXTRA_LANDMINES_SCRIPT.') | |
| 92 parser.add_option('-v', '--verbose', action='store_true', | |
| 93 default=('LANDMINES_VERBOSE' in os.environ), | |
| 94 help=('Emit some extra debugging information (default off). This option ' | |
| 95 'is also enabled by the presence of a LANDMINES_VERBOSE environment ' | |
| 96 'variable.')) | |
| 97 | |
| 98 options, args = parser.parse_args() | |
| 99 | |
| 100 if args: | |
| 101 parser.error('Unknown arguments %s' % args) | |
| 102 | |
| 103 logging.basicConfig( | |
| 104 level=logging.DEBUG if options.verbose else logging.ERROR) | |
| 105 | |
| 106 extra_script = os.environ.get('EXTRA_LANDMINES_SCRIPT') | |
| 107 if extra_script: | |
| 108 return options.landmine_scripts + [extra_script] | |
| 109 else: | |
| 110 return options.landmine_scripts | |
| 111 | |
| 112 | |
| 113 def main(): | |
| 114 landmine_scripts = process_options() | |
| 115 | |
| 116 if landmine_utils.builder() in ('dump_dependency_json', 'eclipse'): | |
| 117 return 0 | |
| 118 | |
| 119 landmines = [] | |
| 120 for s in landmine_scripts: | |
|
Michael Achenbach
2014/07/22 14:04:45
I simplified this compared to the original script
| |
| 121 proc = subprocess.Popen([sys.executable, s], stdout=subprocess.PIPE) | |
| 122 output, _ = proc.communicate() | |
| 123 landmines.extend([('%s\n' % l.strip()) for l in output.splitlines()]) | |
| 124 | |
| 125 for target in ('Debug', 'Release'): | |
| 126 set_up_landmines(target, landmines) | |
| 127 | |
| 128 return 0 | |
| 129 | |
| 130 | |
| 131 if __name__ == '__main__': | |
| 132 sys.exit(main()) | |
| OLD | NEW |