diff options
author | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-19 16:33:12 +0000 |
---|---|---|
committer | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-19 16:33:12 +0000 |
commit | ca8d1984ce76d0048e630dccdbf19492e9a87fd2 (patch) | |
tree | cdb01edbf3d7b420aaf32efd7f36883e06044fd8 /PRESUBMIT.py | |
parent | 1402c866adcaa4cc07d1da980141e3b0db5a3e01 (diff) | |
download | chromium_src-ca8d1984ce76d0048e630dccdbf19492e9a87fd2.zip chromium_src-ca8d1984ce76d0048e630dccdbf19492e9a87fd2.tar.gz chromium_src-ca8d1984ce76d0048e630dccdbf19492e9a87fd2.tar.bz2 |
Very basic starter presubmit script for Chromium, as requested by maruel.
At present this checks the following:
- No tabs in source files
- The words "DO-NOT-SUBMIT" (without the dashes) do not appear in the CL
description or in files in the change
- No CRLF in source files (.cc, .h, .mm, .py)
Limitations:
- The general limitations of the current presubmit API implementation
apply. One of these is that gcl only walks up to the checkout root
searching for presubmit files, so if you've mapped stuff into your
client using DEPS, it will only walk up to where the root of that
mapping.
Patch contributed by Jói.
Review: http://codereview.chromium.org/20474
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10015 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'PRESUBMIT.py')
-rwxr-xr-x | PRESUBMIT.py | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/PRESUBMIT.py b/PRESUBMIT.py new file mode 100755 index 0000000..1340216 --- /dev/null +++ b/PRESUBMIT.py @@ -0,0 +1,73 @@ +#!/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 Chromium. + +See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for +details on the presubmit API built into gcl. +""" + + +import os + + +# Files with these extensions will be considered source files +SOURCE_FILE_EXTENSIONS = ['.c', '.cc', '.cpp', '.h', '.m', '.mm', '.py'] + + +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 + + +# Seam for unit testing +_ReadFile = ReadFile + + +def CheckChangeOnUpload(input_api, output_api): + return (CheckNoCrOrTabs(input_api, output_api) + + input_api.canned_checks.CheckDoNotSubmit(input_api, output_api)) + + +def CheckChangeOnCommit(input_api, output_api): + # No extra checks on commit for now + return CheckChangeOnUpload(input_api, output_api) + + +def CheckNoCrOrTabs(input_api, output_api): + """Reports an error if source files use CR (or CRLF) or TAB. + """ + cr_files = [] + tab_files = [] + results = [] + + for f in input_api.AffectedTextFiles(include_deletes=False): + path = f.LocalPath() + root, ext = os.path.splitext(path) + if ext in SOURCE_FILE_EXTENSIONS: + # Need to read the file ourselves since AffectedFile.NewContents() + # will normalize line endings. + contents = _ReadFile(path) + if '\r' in contents: + cr_files.append(path) + if '\t' in contents: + tab_files.append(path) + 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 tab_files: + results.append(output_api.PresubmitError( + 'Found tabs in the following files, please use spaces', + items=tab_files)) + return results |