| OLD | NEW |
| 1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Generic presubmit checks that can be reused by other presubmit checks.""" | 5 """Generic presubmit checks that can be reused by other presubmit checks.""" |
| 6 | 6 |
| 7 | 7 |
| 8 ### Description checks | 8 ### Description checks |
| 9 | 9 |
| 10 def CheckChangeHasTestField(input_api, output_api): | 10 def CheckChangeHasTestField(input_api, output_api): |
| (...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 output_api: Bag of output related interfaces. | 879 output_api: Bag of output related interfaces. |
| 880 excluded_paths: Don't include these paths in common checks. | 880 excluded_paths: Don't include these paths in common checks. |
| 881 text_files: Which file are to be treated as documentation text files. | 881 text_files: Which file are to be treated as documentation text files. |
| 882 license_header: What license header should be on files. | 882 license_header: What license header should be on files. |
| 883 project_name: What is the name of the project as it appears in the license. | 883 project_name: What is the name of the project as it appears in the license. |
| 884 Returns: | 884 Returns: |
| 885 A list of warning or error objects. | 885 A list of warning or error objects. |
| 886 """ | 886 """ |
| 887 excluded_paths = excluded_paths or tuple() | 887 excluded_paths = excluded_paths or tuple() |
| 888 text_files = text_files or ( | 888 text_files = text_files or ( |
| 889 r'.*\.txt', | 889 r'.+\.txt$', |
| 890 r'.*\.json', | 890 r'.+\.json$', |
| 891 ) | 891 ) |
| 892 project_name = project_name or 'Chromium' | 892 project_name = project_name or 'Chromium' |
| 893 license_header = license_header or ( | 893 license_header = license_header or ( |
| 894 r'.*? Copyright \(c\) %(year)s The %(project)s Authors\. ' | 894 r'.*? Copyright \(c\) %(year)s The %(project)s Authors\. ' |
| 895 r'All rights reserved\.\n' | 895 r'All rights reserved\.\n' |
| 896 r'.*? Use of this source code is governed by a BSD-style license that ' | 896 r'.*? Use of this source code is governed by a BSD-style license that ' |
| 897 r'can be\n' | 897 r'can be\n' |
| 898 r'.*? found in the LICENSE file\.\n' | 898 r'.*? found in the LICENSE file\.\n' |
| 899 ) % { | 899 ) % { |
| 900 'year': input_api.time.strftime('%Y'), | 900 'year': input_api.time.strftime('%Y'), |
| 901 'project': project_name, | 901 'project': project_name, |
| 902 } | 902 } |
| 903 | 903 |
| 904 results = [] | 904 results = [] |
| 905 # This code loads the default black list (e.g. third_party, experimental, etc) | 905 # This code loads the default black list (e.g. third_party, experimental, etc) |
| 906 # and add our black list (breakpad, skia and v8 are still not following | 906 # and add our black list (breakpad, skia and v8 are still not following |
| 907 # google style and are not really living this repository). | 907 # google style and are not really living this repository). |
| 908 # See presubmit_support.py InputApi.FilterSourceFile for the (simple) usage. | 908 # See presubmit_support.py InputApi.FilterSourceFile for the (simple) usage. |
| 909 black_list = input_api.DEFAULT_BLACK_LIST + excluded_paths | 909 black_list = input_api.DEFAULT_BLACK_LIST + excluded_paths |
| 910 white_list = input_api.DEFAULT_WHITE_LIST + text_files | 910 white_list = input_api.DEFAULT_WHITE_LIST + text_files |
| 911 sources = lambda x: input_api.FilterSourceFile(x, black_list=black_list) | 911 sources = lambda x: input_api.FilterSourceFile(x, black_list=black_list) |
| 912 text_files = lambda x: input_api.FilterSourceFile(x, black_list=black_list, | 912 text_files = lambda x: input_api.FilterSourceFile( |
| 913 white_list=white_list) | 913 x, black_list=black_list, white_list=white_list) |
| 914 | |
| 915 | 914 |
| 916 snapshot_memory = [] | 915 snapshot_memory = [] |
| 917 def snapshot(msg): | 916 def snapshot(msg): |
| 918 """Measures & prints performance warning if a rule is running slow.""" | 917 """Measures & prints performance warning if a rule is running slow.""" |
| 919 dt2 = input_api.time.clock() | 918 dt2 = input_api.time.clock() |
| 920 if snapshot_memory: | 919 if snapshot_memory: |
| 921 delta_ms = int(1000*(dt2 - snapshot_memory[0])) | 920 delta_ms = int(1000*(dt2 - snapshot_memory[0])) |
| 922 if delta_ms > 500: | 921 if delta_ms > 500: |
| 923 print " %s took a long time: %dms" % (snapshot_memory[1], delta_ms) | 922 print " %s took a long time: %dms" % (snapshot_memory[1], delta_ms) |
| 924 snapshot_memory[:] = (dt2, msg) | 923 snapshot_memory[:] = (dt2, msg) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 951 results.extend(input_api.canned_checks.CheckChangeSvnEolStyle( | 950 results.extend(input_api.canned_checks.CheckChangeSvnEolStyle( |
| 952 input_api, output_api, source_file_filter=text_files)) | 951 input_api, output_api, source_file_filter=text_files)) |
| 953 snapshot("checking svn mime types") | 952 snapshot("checking svn mime types") |
| 954 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( | 953 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( |
| 955 input_api, output_api)) | 954 input_api, output_api)) |
| 956 snapshot("checking license") | 955 snapshot("checking license") |
| 957 results.extend(input_api.canned_checks.CheckLicense( | 956 results.extend(input_api.canned_checks.CheckLicense( |
| 958 input_api, output_api, license_header, source_file_filter=sources)) | 957 input_api, output_api, license_header, source_file_filter=sources)) |
| 959 snapshot("done") | 958 snapshot("done") |
| 960 return results | 959 return results |
| OLD | NEW |