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

Side by Side Diff: tools/coverity/coverity.py

Issue 8678023: Fix python scripts in src/tools/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes Created 9 years 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 | « tools/code_coverage/process_coverage.py ('k') | tools/crx_id/PRESUBMIT.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/python 1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 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
11 Studio. 11 Studio.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 COVERITY_PRODUCT = 'Chromium' 70 COVERITY_PRODUCT = 'Chromium'
71 71
72 COVERITY_TARGET = 'Windows' 72 COVERITY_TARGET = 'Windows'
73 73
74 COVERITY_USER = 'admin' 74 COVERITY_USER = 'admin'
75 # looking for a PASSWORD constant? Look at --coverity-password-file instead. 75 # looking for a PASSWORD constant? Look at --coverity-password-file instead.
76 76
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
80 def _ReadPassword(pwfilename): 81 def _ReadPassword(pwfilename):
81 """Reads the coverity password in from a file where it was stashed""" 82 """Reads the coverity password in from a file where it was stashed"""
82 pwfile = open(pwfilename, 'r') 83 pwfile = open(pwfilename, 'r')
83 password = pwfile.readline() 84 password = pwfile.readline()
84 pwfile.close() 85 pwfile.close()
85 return password.rstrip() 86 return password.rstrip()
86 87
88
87 def _RunCommand(cmd, dry_run, shell=False, echo_cmd=True): 89 def _RunCommand(cmd, dry_run, shell=False, echo_cmd=True):
88 """Runs the command if dry_run is false, otherwise just prints the command.""" 90 """Runs the command if dry_run is false, otherwise just prints the command."""
89 if echo_cmd: 91 if echo_cmd:
90 print cmd 92 print cmd
91 if not dry_run: 93 if not dry_run:
92 return subprocess.call(cmd, shell=shell) 94 return subprocess.call(cmd, shell=shell)
93 else: 95 else:
94 return 0 96 return 0
95 97
98
96 def _ReleaseLock(lock_file, lock_filename): 99 def _ReleaseLock(lock_file, lock_filename):
97 """Removes the lockfile. Function-ized so we can bail from anywhere""" 100 """Removes the lockfile. Function-ized so we can bail from anywhere"""
98 os.close(lock_file) 101 os.close(lock_file)
99 os.remove(lock_filename) 102 os.remove(lock_filename)
100 103
101 def main(options, args): 104
105 def run_coverity(options, args):
102 """Runs all the selected tests for the given build type and target.""" 106 """Runs all the selected tests for the given build type and target."""
103 # Create the lock file to prevent another instance of this script from 107 # Create the lock file to prevent another instance of this script from
104 # running. 108 # running.
105 lock_filename = os.path.join(options.source_dir, LOCK_FILE) 109 lock_filename = os.path.join(options.source_dir, LOCK_FILE)
106 try: 110 try:
107 lock_file = os.open(lock_filename, 111 lock_file = os.open(lock_filename,
108 os.O_CREAT | os.O_EXCL | os.O_TRUNC | os.O_RDWR) 112 os.O_CREAT | os.O_EXCL | os.O_TRUNC | os.O_RDWR)
109 except OSError, err: 113 except OSError, err:
110 print 'Failed to open lock file:\n ' + str(err) 114 print 'Failed to open lock file:\n ' + str(err)
111 return 1 115 return 1
(...skipping 11 matching lines...) Expand all
123 # The coverity-password filename may have been a relative path. 127 # The coverity-password filename may have been a relative path.
124 # If so, assume it's relative to the source directory, which means 128 # If so, assume it's relative to the source directory, which means
125 # the time to read the password is after we do the chdir(). 129 # the time to read the password is after we do the chdir().
126 coverity_password = _ReadPassword(options.coverity_password_file) 130 coverity_password = _ReadPassword(options.coverity_password_file)
127 131
128 cmd = 'gclient sync' 132 cmd = 'gclient sync'
129 gclient_exit = _RunCommand(cmd, options.dry_run, shell=True) 133 gclient_exit = _RunCommand(cmd, options.dry_run, shell=True)
130 if gclient_exit != 0: 134 if gclient_exit != 0:
131 print 'gclient aborted with status %s' % gclient_exit 135 print 'gclient aborted with status %s' % gclient_exit
132 _ReleaseLock(lock_file, lock_filename) 136 _ReleaseLock(lock_file, lock_filename)
133 sys.exit(1) 137 return 1
134 138
135 print 'Elapsed time: %ds' % (time.time() - start_time) 139 print 'Elapsed time: %ds' % (time.time() - start_time)
136 140
137 # Do a clean build. Remove the build output directory first. 141 # Do a clean build. Remove the build output directory first.
138 if sys.platform.startswith('linux'): 142 if sys.platform.startswith('linux'):
139 rm_path = os.path.join(options.source_dir,'src','out',options.target) 143 rm_path = os.path.join(options.source_dir,'src','out',options.target)
140 elif sys.platform == 'win32': 144 elif sys.platform == 'win32':
141 rm_path = os.path.join(options.source_dir,options.solution_dir, 145 rm_path = os.path.join(options.source_dir,options.solution_dir,
142 options.target) 146 options.target)
143 elif sys.platform == 'darwin': 147 elif sys.platform == 'darwin':
144 rm_path = os.path.join(options.source_dir,'src','xcodebuild') 148 rm_path = os.path.join(options.source_dir,'src','xcodebuild')
145 else: 149 else:
146 print 'Platform "%s" unrecognized, aborting' % sys.platform 150 print 'Platform "%s" unrecognized, aborting' % sys.platform
147 _ReleaseLock(lock_file, lock_filename) 151 _ReleaseLock(lock_file, lock_filename)
148 sys.exit(1) 152 return 1
149 153
150 if options.dry_run: 154 if options.dry_run:
151 print 'shutil.rmtree(%s)' % repr(rm_path) 155 print 'shutil.rmtree(%s)' % repr(rm_path)
152 else: 156 else:
153 shutil.rmtree(rm_path,True) 157 shutil.rmtree(rm_path,True)
154 158
155 if options.preserve_intermediate_dir: 159 if options.preserve_intermediate_dir:
156 print 'Preserving intermediate directory.' 160 print 'Preserving intermediate directory.'
157 else: 161 else:
158 if options.dry_run: 162 if options.dry_run:
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 coverity_password) 226 coverity_password)
223 # Avoid echoing the Commit command because it has a password in it 227 # Avoid echoing the Commit command because it has a password in it
224 _RunCommand(cmd, options.dry_run, shell=use_shell_during_make, echo_cmd=False) 228 _RunCommand(cmd, options.dry_run, shell=use_shell_during_make, echo_cmd=False)
225 229
226 print 'Total time: %ds' % (time.time() - start_time) 230 print 'Total time: %ds' % (time.time() - start_time)
227 231
228 _ReleaseLock(lock_file, lock_filename) 232 _ReleaseLock(lock_file, lock_filename)
229 233
230 return 0 234 return 0
231 235
232 if '__main__' == __name__: 236
237 def main():
233 option_parser = optparse.OptionParser() 238 option_parser = optparse.OptionParser()
234 option_parser.add_option('', '--dry-run', action='store_true', default=False, 239 option_parser.add_option('', '--dry-run', action='store_true', default=False,
235 help='print but don\'t run the commands') 240 help='print but don\'t run the commands')
236 241
237 option_parser.add_option('', '--target', default='Release', 242 option_parser.add_option('', '--target', default='Release',
238 help='build target (Debug or Release)') 243 help='build target (Debug or Release)')
239 244
240 option_parser.add_option('', '--source-dir', dest='source_dir', 245 option_parser.add_option('', '--source-dir', dest='source_dir',
241 help='full path to directory ABOVE "src"', 246 help='full path to directory ABOVE "src"',
242 default=CHROMIUM_SOURCE_DIR) 247 default=CHROMIUM_SOURCE_DIR)
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 help='file containing the coverity password', 294 help='file containing the coverity password',
290 default='coverity-password') 295 default='coverity-password')
291 296
292 helpmsg = ('By default, the intermediate dir is emptied before analysis. ' 297 helpmsg = ('By default, the intermediate dir is emptied before analysis. '
293 'This switch disables that behavior.') 298 'This switch disables that behavior.')
294 option_parser.add_option('', '--preserve-intermediate-dir', 299 option_parser.add_option('', '--preserve-intermediate-dir',
295 action='store_true', help=helpmsg, 300 action='store_true', help=helpmsg,
296 default=False) 301 default=False)
297 302
298 options, args = option_parser.parse_args() 303 options, args = option_parser.parse_args()
304 return run_coverity(options, args)
299 305
300 result = main(options, args) 306
301 sys.exit(result) 307 if '__main__' == __name__:
308 sys.exit(main())
OLDNEW
« no previous file with comments | « tools/code_coverage/process_coverage.py ('k') | tools/crx_id/PRESUBMIT.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698