summaryrefslogtreecommitdiffstats
path: root/googleurl/PRESUBMIT.py
diff options
context:
space:
mode:
authorPatrick Scott <phanna@android.com>2010-02-04 10:37:17 -0500
committerPatrick Scott <phanna@android.com>2010-02-04 10:39:42 -0500
commitc7f5f8508d98d5952d42ed7648c2a8f30a4da156 (patch)
treedd51dbfbf6670daa61279b3a19e7b1835b301dbf /googleurl/PRESUBMIT.py
parent139d8152182f9093f03d9089822b688e49fa7667 (diff)
downloadexternal_chromium-c7f5f8508d98d5952d42ed7648c2a8f30a4da156.zip
external_chromium-c7f5f8508d98d5952d42ed7648c2a8f30a4da156.tar.gz
external_chromium-c7f5f8508d98d5952d42ed7648c2a8f30a4da156.tar.bz2
Initial source checkin.
The source files were determined by building net_unittests in chromium's source tree. Some of the obvious libraries were left out (v8, gmock, gtest). The Android.mk file has all the sources (minus unittests and tools) that were used during net_unittests compilation. Nothing builds yet because of STL but that is the next task. The .cpp files will most likely not compile anyways because of the LOCAL_CPP_EXTENSION mod. I will have to break this into multiple projects to get around that limitation.
Diffstat (limited to 'googleurl/PRESUBMIT.py')
-rw-r--r--googleurl/PRESUBMIT.py108
1 files changed, 108 insertions, 0 deletions
diff --git a/googleurl/PRESUBMIT.py b/googleurl/PRESUBMIT.py
new file mode 100644
index 0000000..6cfbe74
--- /dev/null
+++ b/googleurl/PRESUBMIT.py
@@ -0,0 +1,108 @@
+#!/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.
+
+"""Top-level presubmit script for googleurl.
+
+See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for
+details on the presubmit API built into gcl.
+"""
+
+# Files with these extensions will be considered source files
+SOURCE_FILE_EXTENSIONS = [
+ '.c', '.cc', '.cpp', '.h', '.m', '.mm', '.py', '.mk', '.am', '.json',
+]
+EXCLUDED_PATHS = [
+ r".*third_party[\\\/].*",
+]
+
+def ReadFile(path):
+ """Given a path, returns the full contents of the file.
+
+ Reads files in binary format.
+ """
+ fo = open(path, 'rb')
+ try:
+ contents = fo.read()
+ finally:
+ fo.close()
+ return contents
+
+
+def CheckChangeOnUpload(input_api, output_api):
+ # TODO(brettw) Enforce 80 cols.
+ return LocalChecks(input_api, output_api, max_cols=0)
+
+
+def CheckChangeOnCommit(input_api, output_api):
+ # TODO(brettw) Enforce 80 cols.
+ return (LocalChecks(input_api, output_api, max_cols=0) +
+ input_api.canned_checks.CheckDoNotSubmit(input_api, output_api))
+
+
+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.
+
+ Note that the whole file is checked, not only the changes.
+ """
+ cr_files = []
+ results = []
+ excluded_paths = [input_api.re.compile(x) for x in EXCLUDED_PATHS]
+ files = input_api.AffectedFiles()
+ 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 = ReadFile(path)
+ if '\r' in contents:
+ cr_files.append(path)
+
+ local_errors = []
+ # Remove EOL 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:// to exceed the max_cols rule.
+ if max_cols and len(line) > max_cols and not 'http://' in line:
+ 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))
+ return results