diff options
author | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-11 00:33:40 +0000 |
---|---|---|
committer | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-11 00:33:40 +0000 |
commit | 430641764227eed23957b1045bd31437599824e4 (patch) | |
tree | c7d48e58caa85d99c252be9bfe50325e6e38048a | |
parent | dc9e4f79d3086c188faba279b004585909944984 (diff) | |
download | chromium_src-430641764227eed23957b1045bd31437599824e4.zip chromium_src-430641764227eed23957b1045bd31437599824e4.tar.gz chromium_src-430641764227eed23957b1045bd31437599824e4.tar.bz2 |
Use new canned checks in PRESUBMIT.py
Also fix gcl presubmit tree status check when the change hasn't been uploaded nor gcl try'ed.
Remove PRESUBMIT_unittest.py since it's not useful anymore.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/119432
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18124 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-x | PRESUBMIT.py | 148 | ||||
-rwxr-xr-x | PRESUBMIT_unittest.py | 106 |
2 files changed, 39 insertions, 215 deletions
diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 0a20edfd..f769350 100755 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -9,44 +9,55 @@ See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for details on the presubmit API built into gcl. """ -# Files with these extensions are considered source files. -SOURCE_FILE_EXTENSIONS = [ - '.c', '.cc', '.cpp', '.h', '.m', '.mm', '.py', '.mk', '.am', '.json', -] -EXCLUDED_PATHS = [ +EXCLUDED_PATHS = ( r"breakpad[\\\/].*", - r"chrome[\\\/]Debug[\\\/].*", - r"chrome[\\\/]Release[\\\/].*", - r"sconsbuild[\\\/].*", - r"xcodebuild[\\\/].*", r"skia[\\\/].*", - r".*third_party[\\\/].*", r"v8[\\\/].*", -] +) def CheckChangeOnUpload(input_api, output_api): - # TODO(maruel): max_cols is temporarily disabled. Reenable once the source - # tree is in better shape. results = [] - results.extend(LocalChecks(input_api, output_api, max_cols=0)) - results.extend(input_api.canned_checks.CheckChangeHasBugField(input_api, - output_api)) - results.extend(input_api.canned_checks.CheckChangeHasTestField(input_api, - output_api)) + # What does this code do? + # It loads the default black list (e.g. third_party, experimental, etc) and + # add our black list (breakpad, skia and v8 are still not following + # google style and are not really living this repository). + # See presubmit_support.py InputApi.FilterSourceFile for the (simple) usage. + black_list = input_api.DEFAULT_BLACK_LIST + EXCLUDED_PATHS + sources = lambda x: input_api.FilterSourceFile(x, black_list=black_list) + results.extend(input_api.canned_checks.CheckLongLines( + input_api, output_api, sources)) + results.extend(input_api.canned_checks.CheckChangeHasNoTabs( + input_api, output_api, sources)) + results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace( + input_api, output_api, sources)) + results.extend(input_api.canned_checks.CheckChangeHasBugField( + input_api, output_api)) + results.extend(input_api.canned_checks.CheckChangeHasTestField( + input_api, output_api)) + results.extend(input_api.canned_checks.CheckChangeSvnEolStyle( + input_api, output_api, sources)) return results def CheckChangeOnCommit(input_api, output_api): results = [] - # TODO(maruel): max_cols is temporarily disabled. Reenable once the source - # tree is in better shape. - results.extend(LocalChecks(input_api, output_api, max_cols=0)) - results.extend(input_api.canned_checks.CheckChangeHasBugField(input_api, - output_api)) - results.extend(input_api.canned_checks.CheckChangeHasTestField(input_api, - output_api)) + black_list = input_api.DEFAULT_BLACK_LIST + EXCLUDED_PATHS + sources = lambda x: input_api.FilterSourceFile(x, black_list=black_list) + results.extend(input_api.canned_checks.CheckLongLines( + input_api, output_api, sources)) + results.extend(input_api.canned_checks.CheckChangeHasNoTabs( + input_api, output_api, sources)) + results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace( + input_api, output_api, sources)) + results.extend(input_api.canned_checks.CheckChangeHasBugField( + input_api, output_api)) + results.extend(input_api.canned_checks.CheckChangeHasTestField( + input_api, output_api)) + results.extend(input_api.canned_checks.CheckChangeSvnEolStyle( + input_api, output_api, sources)) # Make sure the tree is 'open'. + # TODO(maruel): Run it in a separate thread to parallelize checks? results.extend(input_api.canned_checks.CheckTreeIsOpen( input_api, output_api, 'http://chromium-status.appspot.com/status', '0' @@ -55,93 +66,12 @@ def CheckChangeOnCommit(input_api, output_api): return results -def LocalChecks(input_api, output_api, max_cols=80): - """Reports an error if for any source file in SOURCE_FILE_EXTENSIONS: - - uses CR (or CRLF) - - contains a TAB - - has a line that ends with whitespace - - contains a line >|max_cols| cols unless |max_cols| is 0. - - File does not end in a newline, or ends in more than one. - - Note that the whole file is checked, not only the changes. - """ - C_SOURCE_FILE_EXTENSIONS = ('.c', '.cc', '.cpp', '.h', '.inl') - cr_files = [] - eof_files = [] - results = [] - excluded_paths = [input_api.re.compile(x) for x in EXCLUDED_PATHS] - files = input_api.AffectedFiles(include_deletes=False) - for f in files: - path = f.LocalPath() - root, ext = input_api.os_path.splitext(path) - # Look for unsupported extensions. - if not ext in SOURCE_FILE_EXTENSIONS: - continue - # Look for excluded paths. - found = False - for item in excluded_paths: - if item.match(path): - found = True - break - if found: - continue - - # Need to read the file ourselves since AffectedFile.NewContents() - # will normalize line endings. - contents = input_api.ReadFile(f) - if '\r' in contents: - cr_files.append(path) - - # Check that the file ends in one and only one newline character. - if len(contents) > 0 and (contents[-1:] != "\n" or contents[-2:-1] == "\n"): - eof_files.append(path) - - local_errors = [] - # Remove end of line character. - lines = contents.splitlines() - line_num = 1 - for line in lines: - if line.endswith(' '): - local_errors.append(output_api.PresubmitError( - '%s, line %s ends with whitespaces.' % - (path, line_num))) - # Accept lines with http://, https:// and C #define/#pragma/#include to - # exceed the max_cols rule. - if (max_cols and - len(line) > max_cols and - not 'http://' in line and - not 'https://' in line and - not (line[0] == '#' and ext in C_SOURCE_FILE_EXTENSIONS)): - local_errors.append(output_api.PresubmitError( - '%s, line %s has %s chars, please reduce to %d chars.' % - (path, line_num, len(line), max_cols))) - if '\t' in line: - local_errors.append(output_api.PresubmitError( - "%s, line %s contains a tab character." % - (path, line_num))) - line_num += 1 - # Just show the first 5 errors. - if len(local_errors) == 6: - local_errors.pop() - local_errors.append(output_api.PresubmitError("... and more.")) - break - results.extend(local_errors) - - if cr_files: - results.append(output_api.PresubmitError( - 'Found CR (or CRLF) line ending in these files, please use only LF:', - items=cr_files)) - if eof_files: - results.append(output_api.PresubmitError( - 'These files should end in one (and only one) newline character:', - items=eof_files)) - return results - - def CheckTryJobExecution(input_api, output_api): + outputs = [] + if not input_api.change.issue or not input_api.change.patchset: + return outputs url = "http://codereview.chromium.org/%d/get_build_results/%d" % ( input_api.change.issue, input_api.change.patchset) - outputs = [] try: connection = input_api.urllib2.urlopen(url) # platform|status|url diff --git a/PRESUBMIT_unittest.py b/PRESUBMIT_unittest.py deleted file mode 100755 index fef41ed..0000000 --- a/PRESUBMIT_unittest.py +++ /dev/null @@ -1,106 +0,0 @@ -#!/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. - -"""Unit tests for top-level Chromium presubmit script. -""" - - -import os -import PRESUBMIT -import re -import unittest - - -class MockInputApi(object): - def __init__(self, test): - self.affected_files = [] - self.re = re - self.os_path = os.path - self._test = test - - def AffectedFiles(self, include_deletes=True): - if include_deletes: - return self.affected_files - else: - return filter(lambda x: x.Action() != 'D', self.affected_files) - - def AffectedTextFiles(self, include_deletes=True): - return self.affected_files - - def ReadFile(self, file): - self._test.failIf(file.LocalPath().endswith('notsource')) - return file.file_contents - - -class MockAffectedFile(object): - def __init__(self, path, action='A'): - self.path = path - self.action = action - - def Action(self): - return self.action - - def LocalPath(self): - return self.path - - def AbsoluteLocalPath(self): - return self.path - - -class MockOutputApi(object): - class PresubmitError(object): - def __init__(self, msg, items=[], long_text=''): - self.msg = msg - self.items = items - - -class PresubmitUnittest(unittest.TestCase): - def testLocalChecks(self): - api = MockInputApi(self) - api.affected_files = [ - MockAffectedFile('foo/blat/yoo.notsource'), - MockAffectedFile('third_party/blat/source.cc'), - MockAffectedFile('foo/blat/source.h'), - MockAffectedFile('foo/blat/source.mm'), - MockAffectedFile('foo/blat/source.py'), - ] - for item in api.affected_files: - item.file_contents = 'file with \n\terror\nhere\r\nyes there' - # 3 source files, 2 errors by file + 1 global CR + 1 global EOF error. - self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 8) - - for item in api.affected_files: - item.file_contents = 'file\twith\ttabs\n' - # 3 source files, 1 error by file. - self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 3) - - for item in api.affected_files: - item.file_contents = 'file\rusing\rCRs\n' - # One global CR error. - self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 1) - self.failUnless( - len(PRESUBMIT.LocalChecks(api, MockOutputApi)[0].items) == 3) - - for item in api.affected_files: - item.file_contents = 'both\ttabs and\r\nCRLF\n' - # 3 source files, 1 error by file + 1 global CR error. - self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 4) - - for item in api.affected_files: - item.file_contents = 'file with\nzero \\t errors \\r\\n\n' - self.failIf(PRESUBMIT.LocalChecks(api, MockOutputApi)) - - def testLocalChecksDeletedFile(self): - api = MockInputApi(self) - api.affected_files = [ - MockAffectedFile('foo/blat/source.py', 'D'), - ] - api.affected_files[0].file_contents = ( - 'file with \n\terror\nhere\r\nyes there') - self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 0) - - -if __name__ == '__main__': - unittest.main() |