| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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.6.1' | 9 __version__ = '1.6.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 cpplint |
| 15 import cPickle # Exposed through the API. | 16 import cPickle # Exposed through the API. |
| 16 import cStringIO # Exposed through the API. | 17 import cStringIO # Exposed through the API. |
| 17 import contextlib | 18 import contextlib |
| 18 import fnmatch | 19 import fnmatch |
| 19 import glob | 20 import glob |
| 20 import inspect | 21 import inspect |
| 21 import json # Exposed through the API. | 22 import json # Exposed through the API. |
| 22 import logging | 23 import logging |
| 23 import marshal # Exposed through the API. | 24 import marshal # Exposed through the API. |
| 24 import optparse | 25 import optparse |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 self.rietveld = rietveld_obj | 241 self.rietveld = rietveld_obj |
| 241 # TBD | 242 # TBD |
| 242 self.host_url = 'http://codereview.chromium.org' | 243 self.host_url = 'http://codereview.chromium.org' |
| 243 if self.rietveld: | 244 if self.rietveld: |
| 244 self.host_url = self.rietveld.url | 245 self.host_url = self.rietveld.url |
| 245 | 246 |
| 246 # We expose various modules and functions as attributes of the input_api | 247 # We expose various modules and functions as attributes of the input_api |
| 247 # so that presubmit scripts don't have to import them. | 248 # so that presubmit scripts don't have to import them. |
| 248 self.basename = os.path.basename | 249 self.basename = os.path.basename |
| 249 self.cPickle = cPickle | 250 self.cPickle = cPickle |
| 251 self.cpplint = cpplint |
| 250 self.cStringIO = cStringIO | 252 self.cStringIO = cStringIO |
| 251 self.glob = glob.glob | 253 self.glob = glob.glob |
| 252 self.json = json | 254 self.json = json |
| 253 self.logging = logging.getLogger('PRESUBMIT') | 255 self.logging = logging.getLogger('PRESUBMIT') |
| 254 self.os_listdir = os.listdir | 256 self.os_listdir = os.listdir |
| 255 self.os_walk = os.walk | 257 self.os_walk = os.walk |
| 256 self.os_path = os.path | 258 self.os_path = os.path |
| 257 self.pickle = pickle | 259 self.pickle = pickle |
| 258 self.marshal = marshal | 260 self.marshal = marshal |
| 259 self.re = re | 261 self.re = re |
| (...skipping 16 matching lines...) Expand all Loading... |
| 276 | 278 |
| 277 # We carry the canned checks so presubmit scripts can easily use them. | 279 # We carry the canned checks so presubmit scripts can easily use them. |
| 278 self.canned_checks = presubmit_canned_checks | 280 self.canned_checks = presubmit_canned_checks |
| 279 | 281 |
| 280 # TODO(dpranke): figure out a list of all approved owners for a repo | 282 # TODO(dpranke): figure out a list of all approved owners for a repo |
| 281 # in order to be able to handle wildcard OWNERS files? | 283 # in order to be able to handle wildcard OWNERS files? |
| 282 self.owners_db = owners.Database(change.RepositoryRoot(), | 284 self.owners_db = owners.Database(change.RepositoryRoot(), |
| 283 fopen=file, os_path=self.os_path, glob=self.glob) | 285 fopen=file, os_path=self.os_path, glob=self.glob) |
| 284 self.verbose = verbose | 286 self.verbose = verbose |
| 285 | 287 |
| 288 # Replace <hash_map> and <hash_set> as headers that need to be included |
| 289 # with "base/hash_tables.h" instead. |
| 290 # Access to a protected member _XX of a client class |
| 291 # pylint: disable=W0212 |
| 292 self.cpplint._re_pattern_templates = [ |
| 293 (a, b, 'base/hash_tables.h') |
| 294 if header in ('<hash_map>', '<hash_set>') else (a, b, header) |
| 295 for (a, b, header) in cpplint._re_pattern_templates |
| 296 ] |
| 297 |
| 286 def PresubmitLocalPath(self): | 298 def PresubmitLocalPath(self): |
| 287 """Returns the local path of the presubmit script currently being run. | 299 """Returns the local path of the presubmit script currently being run. |
| 288 | 300 |
| 289 This is useful if you don't want to hard-code absolute paths in the | 301 This is useful if you don't want to hard-code absolute paths in the |
| 290 presubmit script. For example, It can be used to find another file | 302 presubmit script. For example, It can be used to find another file |
| 291 relative to the PRESUBMIT.py script, so the whole tree can be branched and | 303 relative to the PRESUBMIT.py script, so the whole tree can be branched and |
| 292 the presubmit script still works, without editing its content. | 304 the presubmit script still works, without editing its content. |
| 293 """ | 305 """ |
| 294 return self._current_presubmit_path | 306 return self._current_presubmit_path |
| 295 | 307 |
| (...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1299 except PresubmitFailure, e: | 1311 except PresubmitFailure, e: |
| 1300 print >> sys.stderr, e | 1312 print >> sys.stderr, e |
| 1301 print >> sys.stderr, 'Maybe your depot_tools is out of date?' | 1313 print >> sys.stderr, 'Maybe your depot_tools is out of date?' |
| 1302 print >> sys.stderr, 'If all fails, contact maruel@' | 1314 print >> sys.stderr, 'If all fails, contact maruel@' |
| 1303 return 2 | 1315 return 2 |
| 1304 | 1316 |
| 1305 | 1317 |
| 1306 if __name__ == '__main__': | 1318 if __name__ == '__main__': |
| 1307 fix_encoding.fix_encoding() | 1319 fix_encoding.fix_encoding() |
| 1308 sys.exit(Main(None)) | 1320 sys.exit(Main(None)) |
| OLD | NEW |