Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 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 | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 ''' | |
| 7 This file holds a list of reasons why a particular build needs to be clobbered | |
| 8 (or a list of 'landmines'). | |
| 9 | |
| 10 This script runs every build as a hook. If it detects that the build should | |
| 11 be clobbered, it will touch the file <build_dir>/.landmine_triggered. The | |
| 12 various build scripts will then check for the presence of this file and clobber | |
| 13 accordingly. The script will also emit the reasons for the clobber to stdout. | |
| 14 | |
| 15 A landmine is tripped when a builder checks out a different revision, and the | |
| 16 diff between the new landmines and the old ones is non-null. At this point, the | |
| 17 build is clobbered. | |
| 18 ''' | |
| 19 | |
| 20 import difflib | |
| 21 import functools | |
| 22 import gyp_helper | |
| 23 import os | |
| 24 import shlex | |
| 25 import sys | |
| 26 import time | |
| 27 | |
| 28 | |
| 29 def memoize(default=''): | |
|
M-A Ruel
2012/10/24 00:40:58
Please a one-liner docstring. It's a nice trick th
iannucci
2012/10/24 04:12:25
I have '' as the default because get_landmines exp
| |
| 30 def memoizer(func): | |
| 31 val = [] | |
| 32 @functools.wraps(func) | |
| 33 def inner(*args, **kwargs): | |
| 34 if not val: | |
| 35 ret = func(*args, **kwargs) | |
| 36 val.append(ret if ret is not None else default) | |
| 37 print '%s -> %r' % (func.__name__, val[0]) | |
|
M-A Ruel
2012/10/24 00:40:58
Was this for debugging purpose? At best you'd use
iannucci
2012/10/24 04:12:25
I'd like this to show up in the buildbot logs (ver
M-A Ruel
2012/10/24 12:16:10
I just fear spew for devs. You can leave it in and
| |
| 38 return val[0] | |
| 39 return inner | |
| 40 return memoizer | |
| 41 | |
| 42 | |
| 43 @memoize() | |
| 44 def IsWindows(): | |
| 45 return sys.platform.startswith('win') or sys.platform == 'cygwin' | |
| 46 | |
| 47 | |
| 48 @memoize() | |
| 49 def IsLinux(): | |
| 50 return sys.platform.startswith('linux') | |
| 51 | |
| 52 | |
| 53 @memoize() | |
| 54 def IsMac(): | |
| 55 return sys.platform.startswith('darwin') | |
| 56 | |
| 57 | |
| 58 @memoize() | |
| 59 def gyp_defines(): | |
| 60 return dict(arg.split('=', 1) | |
| 61 for arg in shlex.split(os.environ.get('GYP_DEFINES', ''))) | |
| 62 | |
| 63 | |
| 64 @memoize() | |
| 65 def distributor(): | |
| 66 if 'goma' in gyp_defines(): | |
| 67 return 'goma' | |
| 68 elif IsWindows(): | |
| 69 if 'CHROME_HEADLESS' in os.environ: | |
| 70 return 'ib' # use (!goma and headless) as approximation of ib | |
| 71 | |
| 72 | |
| 73 @memoize() | |
| 74 def platform(): | |
| 75 if 'OS' in gyp_defines(): | |
| 76 if 'android' in gyp_defines()['OS']: | |
| 77 return 'android' | |
| 78 else: | |
| 79 return gyp_defines()['OS'] | |
| 80 elif IsWindows(): | |
| 81 return 'win' | |
| 82 elif IsLinux(): | |
| 83 return 'linux' | |
| 84 else: | |
| 85 return 'mac' | |
| 86 | |
| 87 | |
| 88 @memoize() | |
| 89 def builder(): | |
| 90 if 'GYP_GENERATORS' in os.environ: | |
| 91 # for simplicity, only support the first explicit generator | |
| 92 return os.environ['GYP_GENERATORS'].split(',')[0] | |
| 93 else: | |
| 94 if platform() == 'android': | |
| 95 # Good enough for now? Do any android bots use make? | |
| 96 return 'ninja' | |
| 97 elif platform() == 'ios': | |
| 98 return 'xcode' | |
| 99 elif IsWindows(): | |
| 100 return 'msvs' | |
| 101 elif IsLinux(): | |
| 102 return 'make' | |
| 103 elif IsMac(): | |
| 104 return 'xcode' | |
| 105 else: | |
| 106 assert False, 'Don\'t know what builder we\'re using!' | |
| 107 | |
| 108 | |
| 109 def get_landmines(target): | |
| 110 ''' | |
|
M-A Ruel
2012/10/24 00:40:58
Consistent docstring style, we setled for """
iannucci
2012/10/24 04:12:25
And just when I was getting good at using single q
| |
| 111 ALL LANDMINES ARE DEFINED HERE. | |
| 112 target is Release or Debug | |
| 113 ''' | |
| 114 landmines = [] | |
| 115 add = lambda item: landmines.append(item + '\n') | |
| 116 | |
| 117 if (distributor() == 'goma' and platform() == 'win32' and | |
| 118 builder() == 'ninja'): | |
| 119 add('Need to clobber winja goma due to backend cwd cache fix.') | |
| 120 | |
| 121 return landmines | |
| 122 | |
| 123 | |
| 124 def get_target_build_dir(build_tool, src_dir, target, is_iphone=False): | |
| 125 ret = None | |
| 126 if build_tool == 'xcode': | |
| 127 ret = os.path.join(src_dir, 'xcodebuild', 'content.build', | |
| 128 target + ('-iphoneos' if is_iphone else '')) | |
| 129 elif build_tool == 'make': | |
| 130 ret = os.path.join(src_dir, 'out', target) | |
| 131 elif build_tool == 'ninja': | |
| 132 ret = os.path.join(src_dir, 'out', target) | |
| 133 elif build_tool == 'msvs': | |
| 134 ret = os.path.join(src_dir, 'build', target) | |
| 135 elif build_tool == 'scons': | |
| 136 ret = os.path.join(src_dir, 'sconsbuild', target) | |
| 137 return os.path.abspath(ret) | |
| 138 | |
| 139 | |
| 140 def main(): | |
| 141 gyp_helper.apply_chromium_gyp_env() | |
| 142 src_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) | |
| 143 | |
| 144 for target in ('Debug', 'Release'): | |
| 145 out_dir = get_target_build_dir(builder(), src_dir, target, | |
| 146 platform() == 'ios') | |
| 147 | |
| 148 landmines_path = os.path.join(out_dir, '.landmines') | |
| 149 if not os.path.exists(out_dir): | |
| 150 os.makedirs(out_dir) | |
| 151 | |
| 152 new_landmines = get_landmines(target) | |
| 153 | |
| 154 if not os.path.exists(landmines_path): | |
| 155 with open(landmines_path, 'w') as f: | |
| 156 f.writelines(new_landmines) | |
| 157 else: | |
| 158 triggered = os.path.join(out_dir, '.landmines_triggered') | |
| 159 with open(landmines_path, 'r') as f: | |
| 160 old_landmines = f.readlines() | |
| 161 if old_landmines != new_landmines: | |
| 162 old_date = time.ctime(os.stat(landmines_path).st_ctime) | |
| 163 diff = difflib.unified_diff(old_landmines, new_landmines, | |
| 164 fromfile='old_landmines', tofile='new_landmines', | |
| 165 fromfiledate=old_date, tofiledate=time.ctime(), n=0) | |
| 166 | |
| 167 with open(triggered, 'w') as f: | |
| 168 f.writelines(diff) | |
| 169 elif os.path.exists(triggered): | |
| 170 # Remove false triggered landmines. | |
| 171 os.unlink(triggered) | |
| 172 | |
| 173 return 0 | |
| 174 | |
|
M-A Ruel
2012/10/24 00:40:58
2 lines
| |
| 175 if __name__ == '__main__': | |
| 176 sys.exit(main()) | |
| OLD | NEW |