| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2009 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 """Enables directory-specific presubmit checks to run at upload and/or commit. | 6 """Enables directory-specific presubmit checks to run at upload and/or commit. |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 __version__ = '1.3.2' | 9 __version__ = '1.3.2' |
| 10 | 10 |
| 11 # TODO(joi) Add caching where appropriate/needed. The API is designed to allow | 11 # TODO(joi) Add caching where appropriate/needed. The API is designed to allow |
| 12 # caching (between all different invocations of presubmit scripts for a given | 12 # caching (between all different invocations of presubmit scripts for a given |
| 13 # change). We should add it as our presubmit scripts start feeling slow. | 13 # change). We should add it as our presubmit scripts start feeling slow. |
| 14 | 14 |
| 15 import cPickle # Exposed through the API. | 15 import cPickle # Exposed through the API. |
| 16 import cStringIO # Exposed through the API. | 16 import cStringIO # Exposed through the API. |
| 17 import exceptions | 17 import exceptions |
| 18 import fnmatch | 18 import fnmatch |
| 19 import glob | 19 import glob |
| 20 import logging |
| 20 import marshal # Exposed through the API. | 21 import marshal # Exposed through the API. |
| 21 import optparse | 22 import optparse |
| 22 import os # Somewhat exposed through the API. | 23 import os # Somewhat exposed through the API. |
| 23 import pickle # Exposed through the API. | 24 import pickle # Exposed through the API. |
| 24 import re # Exposed through the API. | 25 import re # Exposed through the API. |
| 25 import subprocess # Exposed through the API. | 26 import subprocess # Exposed through the API. |
| 26 import sys # Parts exposed through API. | 27 import sys # Parts exposed through API. |
| 27 import tempfile # Exposed through the API. | 28 import tempfile # Exposed through the API. |
| 28 import traceback # Exposed through the API. | 29 import traceback # Exposed through the API. |
| 29 import types | 30 import types |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 # files. Don't modify this list from a presubmit script! | 156 # files. Don't modify this list from a presubmit script! |
| 156 DEFAULT_BLACK_LIST = ( | 157 DEFAULT_BLACK_LIST = ( |
| 157 r".*\bexperimental[\\\/].*", | 158 r".*\bexperimental[\\\/].*", |
| 158 r".*\bthird_party[\\\/].*", | 159 r".*\bthird_party[\\\/].*", |
| 159 # Output directories (just in case) | 160 # Output directories (just in case) |
| 160 r".*\bDebug[\\\/].*", | 161 r".*\bDebug[\\\/].*", |
| 161 r".*\bRelease[\\\/].*", | 162 r".*\bRelease[\\\/].*", |
| 162 r".*\bxcodebuild[\\\/].*", | 163 r".*\bxcodebuild[\\\/].*", |
| 163 r".*\bsconsbuild[\\\/].*", | 164 r".*\bsconsbuild[\\\/].*", |
| 164 # All caps files like README and LICENCE. | 165 # All caps files like README and LICENCE. |
| 165 r".*\b[A-Z0-9_]+", | 166 r".*\b[A-Z0-9_]+$", |
| 166 # SCM (can happen in dual SCM configuration) | 167 # SCM (can happen in dual SCM configuration). (Slightly over aggressive) |
| 167 r".*\b\.git[\\\/].*", | 168 r".*\.git[\\\/].*", |
| 168 r".*\b\.svn[\\\/].*", | 169 r".*\.svn[\\\/].*", |
| 169 ) | 170 ) |
| 170 | 171 |
| 171 def __init__(self, change, presubmit_path, is_committing): | 172 def __init__(self, change, presubmit_path, is_committing): |
| 172 """Builds an InputApi object. | 173 """Builds an InputApi object. |
| 173 | 174 |
| 174 Args: | 175 Args: |
| 175 change: A presubmit.GclChange object. | 176 change: A presubmit.GclChange object. |
| 176 presubmit_path: The path to the presubmit script being processed. | 177 presubmit_path: The path to the presubmit script being processed. |
| 177 is_committing: True if the change is about to be committed. | 178 is_committing: True if the change is about to be committed. |
| 178 """ | 179 """ |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 If white_list or black_list is None, InputApi.DEFAULT_WHITE_LIST | 288 If white_list or black_list is None, InputApi.DEFAULT_WHITE_LIST |
| 288 and InputApi.DEFAULT_BLACK_LIST is used respectively. | 289 and InputApi.DEFAULT_BLACK_LIST is used respectively. |
| 289 | 290 |
| 290 The lists will be compiled as regular expression and | 291 The lists will be compiled as regular expression and |
| 291 AffectedFile.LocalPath() needs to pass both list. | 292 AffectedFile.LocalPath() needs to pass both list. |
| 292 | 293 |
| 293 Note: Copy-paste this function to suit your needs or use a lambda function. | 294 Note: Copy-paste this function to suit your needs or use a lambda function. |
| 294 """ | 295 """ |
| 295 def Find(affected_file, list): | 296 def Find(affected_file, list): |
| 296 for item in list: | 297 for item in list: |
| 297 if self.re.match(item, affected_file.LocalPath()): | 298 local_path = affected_file.LocalPath() |
| 299 if self.re.match(item, local_path): |
| 300 logging.debug("%s matched %s" % (item, local_path)) |
| 298 return True | 301 return True |
| 299 return False | 302 return False |
| 300 return (Find(affected_file, white_list or self.DEFAULT_WHITE_LIST) and | 303 return (Find(affected_file, white_list or self.DEFAULT_WHITE_LIST) and |
| 301 not Find(affected_file, black_list or self.DEFAULT_BLACK_LIST)) | 304 not Find(affected_file, black_list or self.DEFAULT_BLACK_LIST)) |
| 302 | 305 |
| 303 def AffectedSourceFiles(self, source_file): | 306 def AffectedSourceFiles(self, source_file): |
| 304 """Filter the list of AffectedTextFiles by the function source_file. | 307 """Filter the list of AffectedTextFiles by the function source_file. |
| 305 | 308 |
| 306 If source_file is None, InputApi.FilterSourceFile() is used. | 309 If source_file is None, InputApi.FilterSourceFile() is used. |
| 307 """ | 310 """ |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 options.commit, | 814 options.commit, |
| 812 options.verbose, | 815 options.verbose, |
| 813 sys.stdout, | 816 sys.stdout, |
| 814 sys.stdin, | 817 sys.stdin, |
| 815 None, | 818 None, |
| 816 False) | 819 False) |
| 817 | 820 |
| 818 | 821 |
| 819 if __name__ == '__main__': | 822 if __name__ == '__main__': |
| 820 sys.exit(Main(sys.argv)) | 823 sys.exit(Main(sys.argv)) |
| OLD | NEW |