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 a hook. If it detects that the build should | 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 | 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 | 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. | 10 accordingly. The script will also emit the reasons for the clobber to stdout. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 fromfile='old_landmines', tofile='new_landmines', | 76 fromfile='old_landmines', tofile='new_landmines', |
77 fromfiledate=old_date, tofiledate=time.ctime(), n=0) | 77 fromfiledate=old_date, tofiledate=time.ctime(), n=0) |
78 | 78 |
79 with open(triggered, 'w') as f: | 79 with open(triggered, 'w') as f: |
80 f.writelines(diff) | 80 f.writelines(diff) |
81 elif os.path.exists(triggered): | 81 elif os.path.exists(triggered): |
82 # Remove false triggered landmines. | 82 # Remove false triggered landmines. |
83 os.remove(triggered) | 83 os.remove(triggered) |
84 | 84 |
85 | 85 |
86 def process_options(): | 86 def main(): |
87 """Returns a list of landmine emitting scripts.""" | |
88 parser = optparse.OptionParser() | 87 parser = optparse.OptionParser() |
89 parser.add_option( | 88 parser.add_option( |
90 '-s', '--landmine-scripts', action='append', | 89 '-s', '--landmine-scripts', action='append', |
91 default=[os.path.join(SRC_DIR, 'build', 'get_landmines.py')], | 90 default=[os.path.join(SRC_DIR, 'build', 'get_landmines.py')], |
92 help='Path to the script which emits landmines to stdout. The target ' | 91 help='Path to the script which emits landmines to stdout. The target ' |
93 'is passed to this script via option -t. Note that an extra ' | 92 'is passed to this script via option -t.') |
94 'script can be specified via an env var EXTRA_LANDMINES_SCRIPT.') | |
95 parser.add_option('-v', '--verbose', action='store_true', | 93 parser.add_option('-v', '--verbose', action='store_true', |
96 default=('LANDMINES_VERBOSE' in os.environ), | 94 default=('LANDMINES_VERBOSE' in os.environ), |
97 help=('Emit some extra debugging information (default off). This option ' | 95 help=('Emit some extra debugging information (default off). This option ' |
98 'is also enabled by the presence of a LANDMINES_VERBOSE environment ' | 96 'is also enabled by the presence of a LANDMINES_VERBOSE environment ' |
99 'variable.')) | 97 'variable.')) |
100 | 98 |
101 options, args = parser.parse_args() | 99 options, args = parser.parse_args() |
102 | 100 |
103 if args: | 101 if args: |
104 parser.error('Unknown arguments %s' % args) | 102 parser.error('Unknown arguments %s' % args) |
105 | 103 |
106 logging.basicConfig( | 104 logging.basicConfig( |
107 level=logging.DEBUG if options.verbose else logging.ERROR) | 105 level=logging.DEBUG if options.verbose else logging.ERROR) |
108 | 106 |
109 extra_script = os.environ.get('EXTRA_LANDMINES_SCRIPT') | |
110 if extra_script: | |
111 return options.landmine_scripts + [extra_script] | |
112 else: | |
113 return options.landmine_scripts | |
114 | |
115 | |
116 def main(): | |
117 landmine_scripts = process_options() | |
118 gyp_helper.apply_chromium_gyp_env() | 107 gyp_helper.apply_chromium_gyp_env() |
119 | 108 |
120 for target in ('Debug', 'Release', 'Debug_x64', 'Release_x64'): | 109 for target in ('Debug', 'Release', 'Debug_x64', 'Release_x64'): |
121 landmines = [] | 110 landmines = [] |
122 for s in landmine_scripts: | 111 for s in options.landmine_scripts: |
123 proc = subprocess.Popen([sys.executable, s, '-t', target], | 112 proc = subprocess.Popen([sys.executable, s, '-t', target], |
124 stdout=subprocess.PIPE) | 113 stdout=subprocess.PIPE) |
125 output, _ = proc.communicate() | 114 output, _ = proc.communicate() |
126 landmines.extend([('%s\n' % l.strip()) for l in output.splitlines()]) | 115 landmines.extend([('%s\n' % l.strip()) for l in output.splitlines()]) |
127 set_up_landmines(target, landmines) | 116 set_up_landmines(target, landmines) |
128 | 117 |
129 return 0 | 118 return 0 |
130 | 119 |
131 | 120 |
132 if __name__ == '__main__': | 121 if __name__ == '__main__': |
133 sys.exit(main()) | 122 sys.exit(main()) |
OLD | NEW |