Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(324)

Side by Side Diff: build/landmines.py

Issue 457003004: Make landmines work on local builds too (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reland: handle clean pull and ios Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « build/gyp_environment.py ('k') | build/vs_toolchain.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 a hook. If it detects that the build should 7 This script runs every build as the first hook (See DEPS). If it detects that
8 be clobbered, it will touch the file <build_dir>/.landmine_triggered. The 8 the build should be clobbered, it will remove the build directory.
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 9
12 A landmine is tripped when a builder checks out a different revision, and the 10 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 11 diff between the new landmines and the old ones is non-null. At this point, the
14 build is clobbered. 12 build is clobbered.
15 """ 13 """
16 14
17 import difflib 15 import difflib
18 import errno 16 import errno
17 import gyp_environment
19 import logging 18 import logging
20 import optparse 19 import optparse
21 import os 20 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_target_build_dir(build_tool, target, is_iphone=False): 32 def get_build_dir(build_tool, 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\Release' 36 r'c:\b\build\slave\win\build\src\out'
37 '/mnt/data/b/build/slave/linux/build/src/out/Debug' 37 '/mnt/data/b/build/slave/linux/build/src/out'
38 '/b/build/slave/ios_rel_device/build/src/xcodebuild/Release-iphoneos' 38 '/b/build/slave/ios_rel_device/build/src/xcodebuild'
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 ''))
46 elif build_tool in ['make', 'ninja', 'ninja-ios']: # TODO: Remove ninja-ios. 45 elif build_tool in ['make', 'ninja', 'ninja-ios']: # TODO: Remove ninja-ios.
47 ret = os.path.join(SRC_DIR, 'out', target) 46 ret = os.path.join(SRC_DIR, 'out')
48 elif build_tool in ['msvs', 'vs', 'ib']: 47 elif build_tool in ['msvs', 'vs', 'ib']:
49 ret = os.path.join(SRC_DIR, 'build', target) 48 ret = os.path.join(SRC_DIR, 'build')
50 else: 49 else:
51 raise NotImplementedError('Unexpected GYP_GENERATORS (%s)' % build_tool) 50 raise NotImplementedError('Unexpected GYP_GENERATORS (%s)' % build_tool)
52 return os.path.abspath(ret) 51 return os.path.abspath(ret)
53 52
54 53
55 def set_up_landmines(target, new_landmines): 54 def clobber_if_necessary(new_landmines):
56 """Does the work of setting, planting, and triggering landmines.""" 55 """Does the work of setting, planting, and triggering landmines."""
57 out_dir = get_target_build_dir(landmine_utils.builder(), target, 56 out_dir = get_build_dir(landmine_utils.builder())
58 landmine_utils.platform() == 'ios') 57 landmines_path = os.path.normpath(os.path.join(out_dir, '..', '.landmines'))
59
60 landmines_path = os.path.join(out_dir, '.landmines')
61 try: 58 try:
62 os.makedirs(out_dir) 59 os.makedirs(out_dir)
63 except OSError as e: 60 except OSError as e:
64 if e.errno == errno.EEXIST: 61 if e.errno == errno.EEXIST:
65 pass 62 pass
66 63
67 if os.path.exists(landmines_path): 64 if os.path.exists(landmines_path):
68 triggered = os.path.join(out_dir, '.landmines_triggered')
69 with open(landmines_path, 'r') as f: 65 with open(landmines_path, 'r') as f:
70 old_landmines = f.readlines() 66 old_landmines = f.readlines()
71 if old_landmines != new_landmines: 67 if old_landmines != new_landmines:
72 old_date = time.ctime(os.stat(landmines_path).st_ctime) 68 old_date = time.ctime(os.stat(landmines_path).st_ctime)
73 diff = difflib.unified_diff(old_landmines, new_landmines, 69 diff = difflib.unified_diff(old_landmines, new_landmines,
74 fromfile='old_landmines', tofile='new_landmines', 70 fromfile='old_landmines', tofile='new_landmines',
75 fromfiledate=old_date, tofiledate=time.ctime(), n=0) 71 fromfiledate=old_date, tofiledate=time.ctime(), n=0)
72 sys.stdout.write('Clobbering due to:\n')
73 sys.stdout.writelines(diff)
76 74
77 with open(triggered, 'w') as f: 75 # Clobber.
78 f.writelines(diff) 76 shutil.rmtree(out_dir)
79 elif os.path.exists(triggered): 77
80 # Remove false triggered landmines. 78 # Save current set of landmines for next time.
81 os.remove(triggered)
82 with open(landmines_path, 'w') as f: 79 with open(landmines_path, 'w') as f:
83 f.writelines(new_landmines) 80 f.writelines(new_landmines)
84 81
85 82
86 def process_options(): 83 def process_options():
87 """Returns a list of landmine emitting scripts.""" 84 """Returns a list of landmine emitting scripts."""
88 parser = optparse.OptionParser() 85 parser = optparse.OptionParser()
89 parser.add_option( 86 parser.add_option(
90 '-s', '--landmine-scripts', action='append', 87 '-s', '--landmine-scripts', action='append',
91 default=[os.path.join(SRC_DIR, 'build', 'get_landmines.py')], 88 default=[os.path.join(SRC_DIR, 'build', 'get_landmines.py')],
(...skipping 20 matching lines...) Expand all
112 else: 109 else:
113 return options.landmine_scripts 110 return options.landmine_scripts
114 111
115 112
116 def main(): 113 def main():
117 landmine_scripts = process_options() 114 landmine_scripts = process_options()
118 115
119 if landmine_utils.builder() in ('dump_dependency_json', 'eclipse'): 116 if landmine_utils.builder() in ('dump_dependency_json', 'eclipse'):
120 return 0 117 return 0
121 118
122 for target in ('Debug', 'Release', 'Debug_x64', 'Release_x64'): 119 gyp_environment.SetEnvironment()
123 landmines = [] 120
124 for s in landmine_scripts: 121 landmines = []
125 proc = subprocess.Popen([sys.executable, s, '-t', target], 122 for s in landmine_scripts:
126 stdout=subprocess.PIPE) 123 proc = subprocess.Popen([sys.executable, s], stdout=subprocess.PIPE)
127 output, _ = proc.communicate() 124 output, _ = proc.communicate()
128 landmines.extend([('%s\n' % l.strip()) for l in output.splitlines()]) 125 landmines.extend([('%s\n' % l.strip()) for l in output.splitlines()])
129 set_up_landmines(target, landmines) 126 clobber_if_necessary(landmines)
130 127
131 return 0 128 return 0
132 129
133 130
134 if __name__ == '__main__': 131 if __name__ == '__main__':
135 sys.exit(main()) 132 sys.exit(main())
OLDNEW
« no previous file with comments | « build/gyp_environment.py ('k') | build/vs_toolchain.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698