OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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 Runs Coverity Prevent on a build of Chromium. | 7 Runs Coverity Prevent on a build of Chromium. |
8 | 8 |
9 This script should be run in a Visual Studio Command Prompt, so that the | 9 This script should be run in a Visual Studio Command Prompt, so that the |
10 INCLUDE, LIB, and PATH environment variables are set properly for Visual | 10 INCLUDE, LIB, and PATH environment variables are set properly for Visual |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 # Relative to CHROMIUM_SOURCE_DIR. Contains the pid of this script. | 77 # Relative to CHROMIUM_SOURCE_DIR. Contains the pid of this script. |
78 LOCK_FILE = 'coverity.lock' | 78 LOCK_FILE = 'coverity.lock' |
79 | 79 |
80 def _ReadPassword(pwfilename): | 80 def _ReadPassword(pwfilename): |
81 """Reads the coverity password in from a file where it was stashed""" | 81 """Reads the coverity password in from a file where it was stashed""" |
82 pwfile = open(pwfilename, 'r') | 82 pwfile = open(pwfilename, 'r') |
83 password = pwfile.readline() | 83 password = pwfile.readline() |
84 pwfile.close() | 84 pwfile.close() |
85 return password.rstrip() | 85 return password.rstrip() |
86 | 86 |
87 def _RunCommand(cmd, dry_run, shell=False): | 87 def _RunCommand(cmd, dry_run, shell=False, echo_cmd=True): |
88 """Runs the command if dry_run is false, otherwise just prints the command.""" | 88 """Runs the command if dry_run is false, otherwise just prints the command.""" |
89 print cmd | 89 if echo_cmd: |
90 print cmd | |
90 # TODO(wtc): Check the return value of subprocess.call, which is the return | 91 # TODO(wtc): Check the return value of subprocess.call, which is the return |
91 # value of the command. | 92 # value of the command. |
92 if not dry_run: | 93 if not dry_run: |
93 subprocess.call(cmd, shell=shell) | 94 subprocess.call(cmd, shell=shell) |
94 | 95 |
95 def _ReleaseLock(lock_file, lock_filename): | 96 def _ReleaseLock(lock_file, lock_filename): |
96 """Removes the lockfile. Function-ized so we can bail from anywhere""" | 97 """Removes the lockfile. Function-ized so we can bail from anywhere""" |
97 os.close(lock_file) | 98 os.close(lock_file) |
98 os.remove(lock_filename) | 99 os.remove(lock_filename) |
99 | 100 |
(...skipping 27 matching lines...) Expand all Loading... | |
127 cmd = 'gclient sync' | 128 cmd = 'gclient sync' |
128 _RunCommand(cmd, options.dry_run, shell=True) | 129 _RunCommand(cmd, options.dry_run, shell=True) |
129 print 'Elapsed time: %ds' % (time.time() - start_time) | 130 print 'Elapsed time: %ds' % (time.time() - start_time) |
130 | 131 |
131 # Do a clean build. Remove the build output directory first. | 132 # Do a clean build. Remove the build output directory first. |
132 if sys.platform == 'linux2': | 133 if sys.platform == 'linux2': |
133 rm_path = os.path.join(options.source_dir,'src','out',options.target) | 134 rm_path = os.path.join(options.source_dir,'src','out',options.target) |
134 elif sys.platform == 'win32': | 135 elif sys.platform == 'win32': |
135 rm_path = os.path.join(options.source_dir,options.solution_dir, | 136 rm_path = os.path.join(options.source_dir,options.solution_dir, |
136 options.target) | 137 options.target) |
138 elif sys.platform == 'darwin': | |
139 rm_path = os.path.join(options.source_dir,'src','xcodebuild') | |
137 else: | 140 else: |
138 print 'Platform "%s" unrecognized, don\'t know how to proceed' | 141 print 'Platform "%s" unrecognized, don\'t know how to proceed' |
139 _ReleaseLock(lock_file, lock_filename) | 142 _ReleaseLock(lock_file, lock_filename) |
140 sys.exit(1) | 143 sys.exit(1) |
141 | 144 |
142 if options.dry_run: | 145 if options.dry_run: |
143 print 'shutil.rmtree(%s)' % repr(rm_path) | 146 print 'shutil.rmtree(%s)' % repr(rm_path) |
144 else: | 147 else: |
145 shutil.rmtree(rm_path,True) | 148 shutil.rmtree(rm_path,True) |
146 | 149 |
147 print 'Elapsed time: %ds' % (time.time() - start_time) | 150 print 'Elapsed time: %ds' % (time.time() - start_time) |
148 | 151 |
149 use_shell_during_make = False | 152 use_shell_during_make = False |
150 if sys.platform == 'linux2': | 153 if sys.platform == 'linux2': |
151 use_shell_during_make = True | 154 use_shell_during_make = True |
152 os.chdir('src') | 155 os.chdir('src') |
153 _RunCommand('pwd', options.dry_run, shell=True) | 156 _RunCommand('pwd', options.dry_run, shell=True) |
154 cmd = '%s/cov-build --dir %s make BUILDTYPE=%s' % ( | 157 cmd = '%s/cov-build --dir %s make BUILDTYPE=%s' % ( |
155 options.coverity_bin_dir, options.coverity_intermediate_dir, | 158 options.coverity_bin_dir, options.coverity_intermediate_dir, |
156 options.target) | 159 options.target) |
157 elif sys.platform == 'win32': | 160 elif sys.platform == 'win32': |
158 cmd = '%s\\cov-build.exe --dir %s devenv.com %s\\%s /build %s' % ( | 161 cmd = '%s\\cov-build.exe --dir %s devenv.com %s\\%s /build %s' % ( |
159 options.coverity_bin_dir, options.coverity_intermediate_dir, | 162 options.coverity_bin_dir, options.coverity_intermediate_dir, |
160 options.source_dir, options.solution_file, options.target) | 163 options.source_dir, options.solution_file, options.target) |
164 elif sys.platform == 'darwin': | |
165 use_shell_during_make = True | |
166 os.chdir('src/build') | |
167 _RunCommand('pwd', options.dry_run, shell=True) | |
168 cmd = ('%s/cov-build --dir %s xcodebuild -project all.xcodeproj ' | |
169 '-configuration %s -target All') % ( | |
170 options.coverity_bin_dir, options.coverity_intermediate_dir, | |
171 options.target) | |
172 | |
161 | 173 |
162 _RunCommand(cmd, options.dry_run, shell=use_shell_during_make) | 174 _RunCommand(cmd, options.dry_run, shell=use_shell_during_make) |
163 print 'Elapsed time: %ds' % (time.time() - start_time) | 175 print 'Elapsed time: %ds' % (time.time() - start_time) |
164 | 176 |
165 cov_analyze_exe = os.path.join(options.coverity_bin_dir,'cov-analyze') | 177 cov_analyze_exe = os.path.join(options.coverity_bin_dir,'cov-analyze') |
166 cmd = '%s --dir %s %s' % (cov_analyze_exe, | 178 cmd = '%s --dir %s %s' % (cov_analyze_exe, |
167 options.coverity_intermediate_dir, | 179 options.coverity_intermediate_dir, |
168 options.coverity_analyze_options) | 180 options.coverity_analyze_options) |
169 _RunCommand(cmd, options.dry_run, shell=use_shell_during_make) | 181 _RunCommand(cmd, options.dry_run, shell=use_shell_during_make) |
170 print 'Elapsed time: %ds' % (time.time() - start_time) | 182 print 'Elapsed time: %ds' % (time.time() - start_time) |
(...skipping 14 matching lines...) Expand all Loading... | |
185 '--target %s ' | 197 '--target %s ' |
186 '--user %s ' | 198 '--user %s ' |
187 '--password %s') % (cov_commit_exe, | 199 '--password %s') % (cov_commit_exe, |
188 options.coverity_intermediate_dir, | 200 options.coverity_intermediate_dir, |
189 options.coverity_dbhost, | 201 options.coverity_dbhost, |
190 options.coverity_port, | 202 options.coverity_port, |
191 options.coverity_product, | 203 options.coverity_product, |
192 coverity_target, | 204 coverity_target, |
193 options.coverity_user, | 205 options.coverity_user, |
194 coverity_password) | 206 coverity_password) |
195 _RunCommand(cmd, options.dry_run, shell=use_shell_during_make) | 207 # Avoid echoing the Commit command because it has a password in it |
wtc
2010/06/15 22:04:07
Can we tell cov-commit-defects to read the passwor
| |
208 _RunCommand(cmd, options.dry_run, shell=use_shell_during_make, echo_cmd=False) | |
196 | 209 |
197 print 'Total time: %ds' % (time.time() - start_time) | 210 print 'Total time: %ds' % (time.time() - start_time) |
198 | 211 |
199 _ReleaseLock(lock_file, lock_filename) | 212 _ReleaseLock(lock_file, lock_filename) |
200 | 213 |
201 return 0 | 214 return 0 |
202 | 215 |
203 if '__main__' == __name__: | 216 if '__main__' == __name__: |
204 option_parser = optparse.OptionParser() | 217 option_parser = optparse.OptionParser() |
205 option_parser.add_option('', '--dry-run', action='store_true', default=False, | 218 option_parser.add_option('', '--dry-run', action='store_true', default=False, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 | 270 |
258 option_parser.add_option('', '--coverity-password-file', | 271 option_parser.add_option('', '--coverity-password-file', |
259 dest='coverity_password_file', | 272 dest='coverity_password_file', |
260 help='file containing the coverity password', | 273 help='file containing the coverity password', |
261 default='coverity-password') | 274 default='coverity-password') |
262 | 275 |
263 options, args = option_parser.parse_args() | 276 options, args = option_parser.parse_args() |
264 | 277 |
265 result = main(options, args) | 278 result = main(options, args) |
266 sys.exit(result) | 279 sys.exit(result) |
OLD | NEW |