Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1827)

Side by Side Diff: presubmit_support.py

Issue 6004006: Fix path filtering to be on the relative path and no on the absolute path. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: added comment Created 9 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « presubmit_canned_checks.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2010 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.5' 9 __version__ = '1.3.5'
10 10
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 r".*\bexperimental[\\\/].*", 204 r".*\bexperimental[\\\/].*",
205 r".*\bthird_party[\\\/].*", 205 r".*\bthird_party[\\\/].*",
206 # Output directories (just in case) 206 # Output directories (just in case)
207 r".*\bDebug[\\\/].*", 207 r".*\bDebug[\\\/].*",
208 r".*\bRelease[\\\/].*", 208 r".*\bRelease[\\\/].*",
209 r".*\bxcodebuild[\\\/].*", 209 r".*\bxcodebuild[\\\/].*",
210 r".*\bsconsbuild[\\\/].*", 210 r".*\bsconsbuild[\\\/].*",
211 # All caps files like README and LICENCE. 211 # All caps files like README and LICENCE.
212 r".*\b[A-Z0-9_]+$", 212 r".*\b[A-Z0-9_]+$",
213 # SCM (can happen in dual SCM configuration). (Slightly over aggressive) 213 # SCM (can happen in dual SCM configuration). (Slightly over aggressive)
214 r".*\.git[\\\/].*", 214 r"(|.*[\\\/])\.git[\\\/].*",
215 r".*\.svn[\\\/].*", 215 r"(|.*[\\\/])\.svn[\\\/].*",
216 ) 216 )
217 217
218 def __init__(self, change, presubmit_path, is_committing): 218 def __init__(self, change, presubmit_path, is_committing):
219 """Builds an InputApi object. 219 """Builds an InputApi object.
220 220
221 Args: 221 Args:
222 change: A presubmit.Change object. 222 change: A presubmit.Change object.
223 presubmit_path: The path to the presubmit script being processed. 223 presubmit_path: The path to the presubmit script being processed.
224 is_committing: True if the change is about to be committed. 224 is_committing: True if the change is about to be committed.
225 """ 225 """
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 class AffectedFile(object): 398 class AffectedFile(object):
399 """Representation of a file in a change.""" 399 """Representation of a file in a change."""
400 # Method could be a function 400 # Method could be a function
401 # pylint: disable=R0201 401 # pylint: disable=R0201
402 def __init__(self, path, action, repository_root=''): 402 def __init__(self, path, action, repository_root=''):
403 self._path = path 403 self._path = path
404 self._action = action 404 self._action = action
405 self._local_root = repository_root 405 self._local_root = repository_root
406 self._is_directory = None 406 self._is_directory = None
407 self._properties = {} 407 self._properties = {}
408 logging.debug('%s(%s)' % (self.__class__.__name__, self._path))
408 409
409 def ServerPath(self): 410 def ServerPath(self):
410 """Returns a path string that identifies the file in the SCM system. 411 """Returns a path string that identifies the file in the SCM system.
411 412
412 Returns the empty string if the file does not exist in SCM. 413 Returns the empty string if the file does not exist in SCM.
413 """ 414 """
414 return "" 415 return ""
415 416
416 def LocalPath(self): 417 def LocalPath(self):
417 """Returns the path of this file on the local disk relative to client root. 418 """Returns the path of this file on the local disk relative to client root.
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 break 796 break
796 directory = parent_dir 797 directory = parent_dir
797 798
798 # Look for PRESUBMIT.py in all candidate directories. 799 # Look for PRESUBMIT.py in all candidate directories.
799 results = [] 800 results = []
800 for directory in sorted(list(candidates)): 801 for directory in sorted(list(candidates)):
801 p = os.path.join(directory, 'PRESUBMIT.py') 802 p = os.path.join(directory, 'PRESUBMIT.py')
802 if os.path.isfile(p): 803 if os.path.isfile(p):
803 results.append(p) 804 results.append(p)
804 805
806 logging.debug('Presubmit files: %s' % ','.join(results))
805 return results 807 return results
806 808
807 809
808 class GetTrySlavesExecuter(object): 810 class GetTrySlavesExecuter(object):
809 @staticmethod 811 @staticmethod
810 def ExecPresubmitScript(script_text): 812 def ExecPresubmitScript(script_text):
811 """Executes GetPreferredTrySlaves() from a single presubmit script. 813 """Executes GetPreferredTrySlaves() from a single presubmit script.
812 814
813 Args: 815 Args:
814 script_text: The text of the presubmit script. 816 script_text: The text of the presubmit script.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 exec script_text in context 912 exec script_text in context
911 913
912 # These function names must change if we make substantial changes to 914 # These function names must change if we make substantial changes to
913 # the presubmit API that are not backwards compatible. 915 # the presubmit API that are not backwards compatible.
914 if self.committing: 916 if self.committing:
915 function_name = 'CheckChangeOnCommit' 917 function_name = 'CheckChangeOnCommit'
916 else: 918 else:
917 function_name = 'CheckChangeOnUpload' 919 function_name = 'CheckChangeOnUpload'
918 if function_name in context: 920 if function_name in context:
919 context['__args'] = (input_api, OutputApi()) 921 context['__args'] = (input_api, OutputApi())
922 logging.debug('Running %s in %s' % (function_name, presubmit_path))
920 result = eval(function_name + '(*__args)', context) 923 result = eval(function_name + '(*__args)', context)
924 logging.debug('Running %s done.' % function_name)
921 if not (isinstance(result, types.TupleType) or 925 if not (isinstance(result, types.TupleType) or
922 isinstance(result, types.ListType)): 926 isinstance(result, types.ListType)):
923 raise exceptions.RuntimeError( 927 raise exceptions.RuntimeError(
924 'Presubmit functions must return a tuple or list') 928 'Presubmit functions must return a tuple or list')
925 for item in result: 929 for item in result:
926 if not isinstance(item, OutputApi.PresubmitResult): 930 if not isinstance(item, OutputApi.PresubmitResult):
927 raise exceptions.RuntimeError( 931 raise exceptions.RuntimeError(
928 'All presubmit results must be of types derived from ' 932 'All presubmit results must be of types derived from '
929 'output_api.PresubmitResult') 933 'output_api.PresubmitResult')
930 else: 934 else:
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 options.commit, 1116 options.commit,
1113 options.verbose, 1117 options.verbose,
1114 sys.stdout, 1118 sys.stdout,
1115 sys.stdin, 1119 sys.stdin,
1116 options.default_presubmit, 1120 options.default_presubmit,
1117 options.may_prompt) 1121 options.may_prompt)
1118 1122
1119 1123
1120 if __name__ == '__main__': 1124 if __name__ == '__main__':
1121 sys.exit(Main(sys.argv)) 1125 sys.exit(Main(sys.argv))
OLDNEW
« no previous file with comments | « presubmit_canned_checks.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698