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

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

Issue 2282006: Adds support for running coverity on Linux. Removes embedded password... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 10 years, 7 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 | « no previous file | no next file » | 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/python
2 # Copyright (c) 2009 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
11 Studio. 11 Studio.
12 12
13 Usage examples: 13 Usage examples:
14 coverity.py 14 coverity.py
15 coverity.py --dry-run 15 coverity.py --dry-run
16 coverity.py --target=debug 16 coverity.py --target=debug
17 %comspec% /c ""C:\Program Files\Microsoft Visual Studio 8\VC\vcvarsall.bat" 17 %comspec% /c ""C:\Program Files\Microsoft Visual Studio 8\VC\vcvarsall.bat"
18 x86 && C:\Python24\python.exe C:\coverity.py" 18 x86 && C:\Python24\python.exe C:\coverity.py"
19 19
20 For a full list of options, pass the '--help' switch. 20 For a full list of options, pass the '--help' switch.
21 21
22 See http://support.microsoft.com/kb/308569 for running this script as a 22 See http://support.microsoft.com/kb/308569 for running this script as a
23 Scheduled Task on Windows XP. 23 Scheduled Task on Windows XP.
24 24
25 """ 25 """
26 26
27 import optparse 27 import optparse
28 import os 28 import os
29 import os.path
30 import shutil
29 import subprocess 31 import subprocess
30 import sys 32 import sys
31 import time 33 import time
32 34
33 # TODO(wtc): Change these constants to command-line flags, particularly the 35 # These constants provide default values, but are exposed as command-line
34 # ones that are paths. Set default values for the flags. 36 # flags. See the --help for more info. Note that for historical reasons
37 # (the script started out as Windows-only and has legacy usages which pre-date
38 # these switches), the constants are all tuned for Windows.
39 # Usage of this script on Linux pretty much requires explicit
40 # --source-dir, --coverity-bin-dir, --coverity-intermediate-dir, and
41 # --coverity-target command line flags.
35 42
36 CHROMIUM_SOURCE_DIR = 'C:\\chromium.latest' 43 CHROMIUM_SOURCE_DIR = 'C:\\chromium.latest'
37 44
38 # Relative to CHROMIUM_SOURCE_DIR. 45 # Relative to CHROMIUM_SOURCE_DIR.
39 CHROMIUM_SOLUTION_FILE = 'src\\chrome\\chrome.sln' 46 CHROMIUM_SOLUTION_FILE = 'src\\chrome\\chrome.sln'
40 47
41 # Relative to CHROMIUM_SOURCE_DIR. 48 # Relative to CHROMIUM_SOURCE_DIR.
42 CHROMIUM_SOLUTION_DIR = 'src\\chrome' 49 CHROMIUM_SOLUTION_DIR = 'src\\chrome'
43 50
44 COVERITY_BIN_DIR = 'C:\\coverity\\prevent-win32-4.5.1\\bin' 51 COVERITY_BIN_DIR = 'C:\\coverity\\prevent-win32-4.5.1\\bin'
(...skipping 13 matching lines...) Expand all
58 # Might need to be changed to FQDN 65 # Might need to be changed to FQDN
59 COVERITY_REMOTE = 'chromecoverity-linux1' 66 COVERITY_REMOTE = 'chromecoverity-linux1'
60 67
61 COVERITY_PORT = '5467' 68 COVERITY_PORT = '5467'
62 69
63 COVERITY_PRODUCT = 'Chromium' 70 COVERITY_PRODUCT = 'Chromium'
64 71
65 COVERITY_TARGET = 'Windows' 72 COVERITY_TARGET = 'Windows'
66 73
67 COVERITY_USER = 'admin' 74 COVERITY_USER = 'admin'
68 75 # looking for a PASSWORD constant? Look at --coverity-password-file instead.
69 CHROMIUM_PASSWORD = 'xxxxxxxx'
70 76
71 # Relative to CHROMIUM_SOURCE_DIR. Contains the pid of this script. 77 # Relative to CHROMIUM_SOURCE_DIR. Contains the pid of this script.
72 LOCK_FILE = 'coverity.lock' 78 LOCK_FILE = 'coverity.lock'
73 79
80 def _ReadPassword(pwfilename):
81 """Reads the coverity password in from a file where it was stashed"""
82 pwfile = open(pwfilename, 'r')
83 password = pwfile.readline()
84 pwfile.close()
85 return password.rstrip()
86
74 def _RunCommand(cmd, dry_run, shell=False): 87 def _RunCommand(cmd, dry_run, shell=False):
75 """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."""
76 print cmd 89 print cmd
77 # TODO(wtc): Check the return value of subprocess.call, which is the return 90 # TODO(wtc): Check the return value of subprocess.call, which is the return
78 # value of the command. 91 # value of the command.
79 if not dry_run: 92 if not dry_run:
80 subprocess.call(cmd, shell=shell) 93 subprocess.call(cmd, shell=shell)
81 94
95 def _ReleaseLock(lock_file, lock_filename):
96 """Removes the lockfile. Function-ized so we can bail from anywhere"""
97 os.close(lock_file)
98 os.remove(lock_filename)
99
82 def main(options, args): 100 def main(options, args):
83 """Runs all the selected tests for the given build type and target.""" 101 """Runs all the selected tests for the given build type and target."""
84 # Create the lock file to prevent another instance of this script from 102 # Create the lock file to prevent another instance of this script from
85 # running. 103 # running.
86 lock_filename = '%s\\%s' % (CHROMIUM_SOURCE_DIR, LOCK_FILE) 104 lock_filename = os.path.join(options.source_dir, LOCK_FILE)
87 try: 105 try:
88 lock_file = os.open(lock_filename, 106 lock_file = os.open(lock_filename,
89 os.O_CREAT | os.O_EXCL | os.O_TRUNC | os.O_RDWR) 107 os.O_CREAT | os.O_EXCL | os.O_TRUNC | os.O_RDWR)
90 except OSError, err: 108 except OSError, err:
91 print 'Failed to open lock file:\n ' + str(err) 109 print 'Failed to open lock file:\n ' + str(err)
92 return 1 110 return 1
93 111
94 # Write the pid of this script (the python.exe process) to the lock file. 112 # Write the pid of this script (the python.exe process) to the lock file.
95 os.write(lock_file, str(os.getpid())) 113 os.write(lock_file, str(os.getpid()))
96 114
97 options.target = options.target.title() 115 options.target = options.target.title()
98 116
99 start_time = time.time() 117 start_time = time.time()
100 118
101 print 'Change directory to ' + CHROMIUM_SOURCE_DIR 119 print 'Change directory to ' + options.source_dir
102 os.chdir(CHROMIUM_SOURCE_DIR) 120 os.chdir(options.source_dir)
121
122 # The coverity-password filename may have been a relative path.
123 # If so, assume it's relative to the source directory, which means
124 # the time to read the password is after we do the chdir().
125 coverity_password = _ReadPassword(options.coverity_password_file)
103 126
104 cmd = 'gclient sync' 127 cmd = 'gclient sync'
105 _RunCommand(cmd, options.dry_run, shell=True) 128 _RunCommand(cmd, options.dry_run, shell=True)
106 print 'Elapsed time: %ds' % (time.time() - start_time) 129 print 'Elapsed time: %ds' % (time.time() - start_time)
107 130
108 # Do a clean build. Remove the build output directory first. 131 # Do a clean build. Remove the build output directory first.
109 # TODO(wtc): Consider using Python's rmtree function in the shutil module, 132 if sys.platform == 'linux2':
110 # or the RemoveDirectory function in 133 rm_path = os.path.join(options.source_dir,'src','out',options.target)
111 # trunk/tools/buildbot/scripts/common/chromium_utils.py. 134 elif sys.platform == 'win32':
112 cmd = 'rmdir /s /q %s\\%s\\%s' % (CHROMIUM_SOURCE_DIR, 135 rm_path = os.path.join(options.source_dir,options.solution_dir,
113 CHROMIUM_SOLUTION_DIR, options.target) 136 options.target)
114 _RunCommand(cmd, options.dry_run, shell=True) 137 else:
138 print 'Platform "%s" unrecognized, don\'t know how to proceed'
139 _ReleaseLock(lock_file, lock_filename)
140 sys.exit(1)
141
142 if options.dry_run:
143 print 'shutil.rmtree(%s)' % repr(rm_path)
144 else:
145 shutil.rmtree(rm_path,True)
146
115 print 'Elapsed time: %ds' % (time.time() - start_time) 147 print 'Elapsed time: %ds' % (time.time() - start_time)
116 148
117 cmd = '%s\\cov-build.exe --dir %s devenv.com %s\\%s /build %s' % ( 149 use_shell_during_make = False
118 COVERITY_BIN_DIR, COVERITY_INTERMEDIATE_DIR, CHROMIUM_SOURCE_DIR, 150 if sys.platform == 'linux2':
119 CHROMIUM_SOLUTION_FILE, options.target) 151 use_shell_during_make = True
120 _RunCommand(cmd, options.dry_run) 152 os.chdir('src')
153 _RunCommand('pwd', options.dry_run, shell=True)
154 cmd = '%s/cov-build --dir %s make BUILDTYPE=%s' % (
155 options.coverity_bin_dir, options.coverity_intermediate_dir,
156 options.target)
157 elif sys.platform == 'win32':
158 cmd = '%s\\cov-build.exe --dir %s devenv.com %s\\%s /build %s' % (
159 options.coverity_bin_dir, options.coverity_intermediate_dir,
160 options.source_dir, options.solution_file, options.target)
161
162 _RunCommand(cmd, options.dry_run, shell=use_shell_during_make)
121 print 'Elapsed time: %ds' % (time.time() - start_time) 163 print 'Elapsed time: %ds' % (time.time() - start_time)
122 164
123 cmd = '%s\\cov-analyze.exe --dir %s %s' % (COVERITY_BIN_DIR, 165 cov_analyze_exe = os.path.join(options.coverity_bin_dir,'cov-analyze')
124 COVERITY_INTERMEDIATE_DIR, 166 cmd = '%s --dir %s %s' % (cov_analyze_exe,
125 COVERITY_ANALYZE_OPTIONS) 167 options.coverity_intermediate_dir,
126 _RunCommand(cmd, options.dry_run) 168 options.coverity_analyze_options)
169 _RunCommand(cmd, options.dry_run, shell=use_shell_during_make)
127 print 'Elapsed time: %ds' % (time.time() - start_time) 170 print 'Elapsed time: %ds' % (time.time() - start_time)
128 171
129 cmd = ('%s\\cov-commit-defects.exe --dir %s --remote %s --port %s' 172 cov_commit_exe = os.path.join(options.coverity_bin_dir,'cov-commit-defects')
173
174 # On Linux we have started using a Target with a space in it, so we want
175 # to quote it. On the other hand, Windows quoting doesn't work quite the
176 # same way. To be conservative, I'd like to avoid quoting an argument
177 # that doesn't need quoting and which we haven't historically been quoting
178 # on that platform. So, only quote the target if we have to.
179 coverity_target = options.coverity_target
180 if sys.platform != 'win32':
181 coverity_target = '"%s"' % coverity_target
182
183 cmd = ('%s --dir %s --remote %s --port %s '
130 '--product %s ' 184 '--product %s '
131 '--target %s ' 185 '--target %s '
132 '--user %s ' 186 '--user %s '
133 '--password %s') % (COVERITY_BIN_DIR, 187 '--password %s') % (cov_commit_exe,
134 COVERITY_INTERMEDIATE_DIR, 188 options.coverity_intermediate_dir,
135 COVERITY_REMOTE, COVERITY_PORT, 189 options.coverity_dbhost,
136 COVERITY_PRODUCT, 190 options.coverity_port,
137 COVERITY_TARGET, COVERITY_USER, 191 options.coverity_product,
138 CHROMIUM_PASSWORD) 192 coverity_target,
139 _RunCommand(cmd, options.dry_run) 193 options.coverity_user,
194 coverity_password)
195 _RunCommand(cmd, options.dry_run, shell=use_shell_during_make)
140 196
141 print 'Total time: %ds' % (time.time() - start_time) 197 print 'Total time: %ds' % (time.time() - start_time)
142 198
143 os.close(lock_file) 199 _ReleaseLock(lock_file, lock_filename)
144 os.remove(lock_filename)
145 200
146 return 0 201 return 0
147 202
148 if '__main__' == __name__: 203 if '__main__' == __name__:
149 option_parser = optparse.OptionParser() 204 option_parser = optparse.OptionParser()
150 option_parser.add_option('', '--dry-run', action='store_true', default=False, 205 option_parser.add_option('', '--dry-run', action='store_true', default=False,
151 help='print but don\'t run the commands') 206 help='print but don\'t run the commands')
207
152 option_parser.add_option('', '--target', default='Release', 208 option_parser.add_option('', '--target', default='Release',
153 help='build target (Debug or Release)') 209 help='build target (Debug or Release)')
210
211 option_parser.add_option('', '--source-dir', dest='source_dir',
212 help='full path to directory ABOVE "src"',
213 default=CHROMIUM_SOURCE_DIR)
214
215 option_parser.add_option('', '--solution-file', dest='solution_file',
216 default=CHROMIUM_SOLUTION_FILE)
217
218 option_parser.add_option('', '--solution-dir', dest='solution_dir',
219 default=CHROMIUM_SOLUTION_DIR)
220
221 option_parser.add_option('', '--coverity-bin-dir', dest='coverity_bin_dir',
222 default=COVERITY_BIN_DIR)
223
224 option_parser.add_option('', '--coverity-intermediate-dir',
225 dest='coverity_intermediate_dir',
226 default=COVERITY_INTERMEDIATE_DIR)
227
228 option_parser.add_option('', '--coverity-analyze-options',
229 dest='coverity_analyze_options',
230 help=('all cov-analyze options, e.g. "%s"'
231 % COVERITY_ANALYZE_OPTIONS),
232 default=COVERITY_ANALYZE_OPTIONS)
233
234 option_parser.add_option('', '--coverity-db-host',
235 dest='coverity_dbhost',
236 help=('coverity defect db server hostname, e.g. %s'
237 % COVERITY_REMOTE),
238 default=COVERITY_REMOTE)
239
240 option_parser.add_option('', '--coverity-db-port', dest='coverity_port',
241 help=('port # of coverity web/db server, e.g. %s'
242 % COVERITY_PORT),
243 default=COVERITY_PORT)
244
245 option_parser.add_option('', '--coverity-product', dest='coverity_product',
246 help=('Product name reported to coverity, e.g. %s'
247 % COVERITY_PRODUCT),
248 default=COVERITY_PRODUCT)
249
250 option_parser.add_option('', '--coverity-target', dest='coverity_target',
251 help='Platform Target reported to coverity',
252 default=COVERITY_TARGET)
253
254 option_parser.add_option('', '--coverity-user', dest='coverity_user',
255 help='Username used to log into coverity',
256 default=COVERITY_USER)
257
258 option_parser.add_option('', '--coverity-password-file',
259 dest='coverity_password_file',
260 help='file containing the coverity password',
261 default='coverity-password')
262
154 options, args = option_parser.parse_args() 263 options, args = option_parser.parse_args()
155 264
156 result = main(options, args) 265 result = main(options, args)
157 sys.exit(result) 266 sys.exit(result)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698