diff options
author | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-12 01:31:48 +0000 |
---|---|---|
committer | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-12 01:31:48 +0000 |
commit | 5d15ca3b908891e9a9d514448510651484c1c207 (patch) | |
tree | 5cd5fc0e2b4d219e1b5b7484cce41d99f3011537 /tools/coverity | |
parent | 57223f4095ade243522eff302090b011cab224f2 (diff) | |
download | chromium_src-5d15ca3b908891e9a9d514448510651484c1c207.zip chromium_src-5d15ca3b908891e9a9d514448510651484c1c207.tar.gz chromium_src-5d15ca3b908891e9a9d514448510651484c1c207.tar.bz2 |
Add a script that runs cov-build, cov-analyze, and
cov-commit-defects on a Chromium tree.
R=patrick
BUG=N/A
TEST=N/A
Review URL: http://codereview.chromium.org/99264
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15831 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/coverity')
-rw-r--r-- | tools/coverity/coverity.py | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/tools/coverity/coverity.py b/tools/coverity/coverity.py new file mode 100644 index 0000000..bcf592b --- /dev/null +++ b/tools/coverity/coverity.py @@ -0,0 +1,136 @@ +#!/usr/bin/python +# Copyright (c) 2009 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +""" +Runs Coverity Prevent on a build of Chromium. + +This script should be run in a Visual Studio Command Prompt, so that the +INCLUDE, LIB, and PATH environment variables are set properly for Visual +Studio. + +Usage examples: + coverity.py + coverity.py --dry-run + coverity.py --target=debug + %comspec% /c ""C:\Program Files\Microsoft Visual Studio 8\VC\vcvarsall.bat" + x86 && C:\Python24\python.exe C:\coverity.py" + +For a full list of options, pass the '--help' switch. + +""" + +import optparse +import os +import subprocess +import sys +import time + +# TODO(wtc): Change these constants to command-line flags, particularly the +# ones that are paths. Set default values for the flags. + +CHROMIUM_SOURCE_DIR = 'E:\\chromium.latest' + +# Relative to CHROMIUM_SOURCE_DIR. +CHROMIUM_SOLUTION_FILE = 'src\\chrome\\chrome.sln' + +# Relative to CHROMIUM_SOURCE_DIR. +CHROMIUM_SOLUTION_DIR = 'src\\chrome' + +COVERITY_BIN_DIR = 'C:\\coverity\\prevent-mingw-4.4.0\\bin' + +COVERITY_INTERMEDIATE_DIR = 'C:\\coverity\\cvbuild\\cr_int' + +COVERITY_DATABASE_DIR = 'C:\\coverity\\cvbuild\\db' + +COVERITY_ANALYZE_OPTIONS = ('--all --enable-single-virtual ' + '--enable-constraint-fpp ' + '--enable-callgraph-metrics ' + '--checker-option PASS_BY_VALUE:size_threshold:16') + +COVERITY_PRODUCT = 'Chromium' + +COVERITY_USER = 'admin' + +# Relative to CHROMIUM_SOURCE_DIR. Contains the pid of this script. +LOCK_FILE = 'coverity.lock' + +def _RunCommand(cmd, dry_run, shell=False): + """Runs the command if dry_run is false, otherwise just prints the command.""" + print cmd + # TODO(wtc): Check the return value of subprocess.call, which is the return + # value of the command. + if not dry_run: + subprocess.call(cmd, shell=shell) + +def main(options, args): + """Runs all the selected tests for the given build type and target.""" + # Create the lock file to prevent another instance of this script from + # running. + lock_filename = '%s\\%s' % (CHROMIUM_SOURCE_DIR, LOCK_FILE) + try: + lock_file = os.open(lock_filename, + os.O_CREAT | os.O_EXCL | os.O_TRUNC | os.O_RDWR) + except OSError, err: + print 'Failed to open lock file:\n ' + str(err) + return 1 + + # Write the pid of this script (the python.exe process) to the lock file. + os.write(lock_file, str(os.getpid())) + + options.target = options.target.title() + + start_time = time.time() + + print 'Change directory to ' + CHROMIUM_SOURCE_DIR + os.chdir(CHROMIUM_SOURCE_DIR) + + cmd = 'gclient sync' + _RunCommand(cmd, options.dry_run, shell=True) + print 'Elapsed time: %ds' % (time.time() - start_time) + + # Do a clean build. Remove the build output directory first. + # TODO(wtc): Consider using Python's rmtree function in the shutil module, + # or the RemoveDirectory function in + # trunk/tools/buildbot/scripts/common/chromium_utils.py. + cmd = 'rmdir /s /q %s\\%s\\%s' % (CHROMIUM_SOURCE_DIR, + CHROMIUM_SOLUTION_DIR, options.target) + _RunCommand(cmd, options.dry_run, shell=True) + print 'Elapsed time: %ds' % (time.time() - start_time) + + cmd = '%s\\cov-build.exe --dir %s devenv.com %s\\%s /build %s' % ( + COVERITY_BIN_DIR, COVERITY_INTERMEDIATE_DIR, CHROMIUM_SOURCE_DIR, + CHROMIUM_SOLUTION_FILE, options.target) + _RunCommand(cmd, options.dry_run) + print 'Elapsed time: %ds' % (time.time() - start_time) + + cmd = '%s\\cov-analyze.exe --dir %s %s' % (COVERITY_BIN_DIR, + COVERITY_INTERMEDIATE_DIR, + COVERITY_ANALYZE_OPTIONS) + _RunCommand(cmd, options.dry_run) + print 'Elapsed time: %ds' % (time.time() - start_time) + + cmd = ('%s\\cov-commit-defects.exe --dir %s --datadir %s --product %s ' + '--user %s') % (COVERITY_BIN_DIR, COVERITY_INTERMEDIATE_DIR, + COVERITY_DATABASE_DIR, COVERITY_PRODUCT, + COVERITY_USER) + _RunCommand(cmd, options.dry_run) + + print 'Total time: %ds' % (time.time() - start_time) + + os.close(lock_file) + os.remove(lock_filename) + + return 0 + +if '__main__' == __name__: + option_parser = optparse.OptionParser() + option_parser.add_option('', '--dry-run', action='store_true', default=False, + help='print but don\'t run the commands') + option_parser.add_option('', '--target', default='Release', + help='build target (Debug or Release)') + options, args = option_parser.parse_args() + + result = main(options, args) + sys.exit(result) |