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