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.4' | 9 __version__ = '1.3.4' |
10 | 10 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 | 143 |
144 class InputApi(object): | 144 class InputApi(object): |
145 """An instance of this object is passed to presubmit scripts so they can | 145 """An instance of this object is passed to presubmit scripts so they can |
146 know stuff about the change they're looking at. | 146 know stuff about the change they're looking at. |
147 """ | 147 """ |
148 | 148 |
149 # File extensions that are considered source files from a style guide | 149 # File extensions that are considered source files from a style guide |
150 # perspective. Don't modify this list from a presubmit script! | 150 # perspective. Don't modify this list from a presubmit script! |
151 DEFAULT_WHITE_LIST = ( | 151 DEFAULT_WHITE_LIST = ( |
152 # C++ and friends | 152 # C++ and friends |
153 r".*\.c", r".*\.cc", r".*\.cpp", r".*\.h", r".*\.m", r".*\.mm", | 153 r".*\.c$", r".*\.cc$", r".*\.cpp$", r".*\.h$", r".*\.m$", r".*\.mm$", |
154 r".*\.inl", r".*\.asm", r".*\.hxx", r".*\.hpp", | 154 r".*\.inl$", r".*\.asm$", r".*\.hxx$", r".*\.hpp$", |
155 # Scripts | 155 # Scripts |
156 r".*\.js", r".*\.py", r".*\.sh", r".*\.rb", r".*\.pl", r".*\.pm", | 156 r".*\.js$", r".*\.py$", r".*\.sh$", r".*\.rb$", r".*\.pl$", r".*\.pm$", |
157 # No extension at all, note that ALL CAPS files are black listed in | 157 # No extension at all, note that ALL CAPS files are black listed in |
158 # DEFAULT_BLACK_LIST below. | 158 # DEFAULT_BLACK_LIST below. |
159 r"(^|.*[\\\/])[^.]+$", | 159 r"(^|.*?[\\\/])[^.]+$", |
Evan Martin
2010/01/28 23:41:47
Surprised this is needed, since .* matches the emp
| |
160 # Other | 160 # Other |
161 r".*\.java", r".*\.mk", r".*\.am", | 161 r".*\.java$", r".*\.mk$", r".*\.am$", |
162 ) | 162 ) |
163 | 163 |
164 # Path regexp that should be excluded from being considered containing source | 164 # Path regexp that should be excluded from being considered containing source |
165 # files. Don't modify this list from a presubmit script! | 165 # files. Don't modify this list from a presubmit script! |
166 DEFAULT_BLACK_LIST = ( | 166 DEFAULT_BLACK_LIST = ( |
167 r".*\bexperimental[\\\/].*", | 167 r".*\bexperimental[\\\/].*", |
168 r".*\bthird_party[\\\/].*", | 168 r".*\bthird_party[\\\/].*", |
169 # Output directories (just in case) | 169 # Output directories (just in case) |
170 r".*\bDebug[\\\/].*", | 170 r".*\bDebug[\\\/].*", |
171 r".*\bRelease[\\\/].*", | 171 r".*\bRelease[\\\/].*", |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 and InputApi.DEFAULT_BLACK_LIST is used respectively. | 302 and InputApi.DEFAULT_BLACK_LIST is used respectively. |
303 | 303 |
304 The lists will be compiled as regular expression and | 304 The lists will be compiled as regular expression and |
305 AffectedFile.LocalPath() needs to pass both list. | 305 AffectedFile.LocalPath() needs to pass both list. |
306 | 306 |
307 Note: Copy-paste this function to suit your needs or use a lambda function. | 307 Note: Copy-paste this function to suit your needs or use a lambda function. |
308 """ | 308 """ |
309 def Find(affected_file, list): | 309 def Find(affected_file, list): |
310 for item in list: | 310 for item in list: |
311 local_path = affected_file.LocalPath() | 311 local_path = affected_file.LocalPath() |
312 if self.re.match(item, local_path): | 312 if self.re.match(item, local_path): |
Evan Martin
2010/01/28 23:41:47
Could also just add a "$" here to make match() mea
| |
313 logging.debug("%s matched %s" % (item, local_path)) | 313 logging.debug("%s matched %s" % (item, local_path)) |
314 return True | 314 return True |
315 return False | 315 return False |
316 return (Find(affected_file, white_list or self.DEFAULT_WHITE_LIST) and | 316 return (Find(affected_file, white_list or self.DEFAULT_WHITE_LIST) and |
317 not Find(affected_file, black_list or self.DEFAULT_BLACK_LIST)) | 317 not Find(affected_file, black_list or self.DEFAULT_BLACK_LIST)) |
318 | 318 |
319 def AffectedSourceFiles(self, source_file): | 319 def AffectedSourceFiles(self, source_file): |
320 """Filter the list of AffectedTextFiles by the function source_file. | 320 """Filter the list of AffectedTextFiles by the function source_file. |
321 | 321 |
322 If source_file is None, InputApi.FilterSourceFile() is used. | 322 If source_file is None, InputApi.FilterSourceFile() is used. |
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1049 options.commit, | 1049 options.commit, |
1050 options.verbose, | 1050 options.verbose, |
1051 sys.stdout, | 1051 sys.stdout, |
1052 sys.stdin, | 1052 sys.stdin, |
1053 options.default_presubmit, | 1053 options.default_presubmit, |
1054 options.may_prompt) | 1054 options.may_prompt) |
1055 | 1055 |
1056 | 1056 |
1057 if __name__ == '__main__': | 1057 if __name__ == '__main__': |
1058 sys.exit(Main(sys.argv)) | 1058 sys.exit(Main(sys.argv)) |
OLD | NEW |