Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 """Top-level presubmit script for Chromium. | 5 """Top-level presubmit script for Chromium. |
| 6 | 6 |
| 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 8 for more details about the presubmit API built into gcl. | 8 for more details about the presubmit API built into gcl. |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 | 11 |
| 12 import re | 12 import re |
| 13 import sys | 13 import sys |
| 14 from xml.dom import minidom | |
| 14 | 15 |
| 15 | 16 |
| 16 _EXCLUDED_PATHS = ( | 17 _EXCLUDED_PATHS = ( |
| 17 r"^breakpad[\\\/].*", | 18 r"^breakpad[\\\/].*", |
| 18 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_rules.py", | 19 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_rules.py", |
| 19 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_simple.py", | 20 r"^native_client_sdk[\\\/]src[\\\/]build_tools[\\\/]make_simple.py", |
| 20 r"^native_client_sdk[\\\/]src[\\\/]tools[\\\/].*.mk", | 21 r"^native_client_sdk[\\\/]src[\\\/]tools[\\\/].*.mk", |
| 21 r"^net[\\\/]tools[\\\/]spdyshark[\\\/].*", | 22 r"^net[\\\/]tools[\\\/]spdyshark[\\\/].*", |
| 22 r"^skia[\\\/].*", | 23 r"^skia[\\\/].*", |
| 23 r"^v8[\\\/].*", | 24 r"^v8[\\\/].*", |
| (...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1007 | 1008 |
| 1008 if cygwin_shell: | 1009 if cygwin_shell: |
| 1009 return [output_api.PresubmitError( | 1010 return [output_api.PresubmitError( |
| 1010 'These files should not use msvs_cygwin_shell (the default is 0):', | 1011 'These files should not use msvs_cygwin_shell (the default is 0):', |
| 1011 items=cygwin_shell)] | 1012 items=cygwin_shell)] |
| 1012 return [] | 1013 return [] |
| 1013 | 1014 |
| 1014 | 1015 |
| 1015 def _CheckUserActionUpdate(input_api, output_api): | 1016 def _CheckUserActionUpdate(input_api, output_api): |
| 1016 """Checks if any new user action has been added.""" | 1017 """Checks if any new user action has been added.""" |
| 1017 if any('chromeactions.txt' == input_api.os_path.basename(f) for f in | 1018 if any('actions.xml' == input_api.os_path.basename(f) for f in |
| 1018 input_api.LocalPaths()): | 1019 input_api.LocalPaths()): |
| 1019 # If chromeactions.txt is already included in the changelist, the PRESUBMIT | 1020 # If actions.xml is already included in the changelist, the PRESUBMIT |
| 1020 # for chromeactions.txt will do a more complete presubmit check. | 1021 # for actions.xml will do a more complete presubmit check. |
| 1021 return [] | 1022 return [] |
| 1022 | 1023 |
| 1023 with open('tools/metrics/actions/chromeactions.txt') as f: | 1024 current_actions = [] |
| 1024 current_actions = f.read() | |
| 1025 | |
| 1026 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm')) | 1025 file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm')) |
| 1027 action_re = r'[^a-zA-Z]UserMetricsAction\("([^"]*)' | 1026 action_re = r'[^a-zA-Z]UserMetricsAction\("([^"]*)' |
| 1028 for f in input_api.AffectedFiles(file_filter=file_filter): | 1027 for f in input_api.AffectedFiles(file_filter=file_filter): |
| 1029 for line_num, line in f.ChangedContents(): | 1028 for line_num, line in f.ChangedContents(): |
| 1030 match = input_api.re.search(action_re, line) | 1029 match = input_api.re.search(action_re, line) |
| 1031 if match: | 1030 if match: |
| 1031 # Get all current user actions. | |
| 1032 if not current_actions: | |
| 1033 try: | |
| 1034 current_actions = [a.getAttribute('name') for a in | |
| 1035 minidom.parse('tools/metrics/actions/actions.xml'). | |
|
Jói
2014/03/05 09:09:35
I am concerned about the performance of parsing an
yiyaoliu
2014/03/05 15:07:07
With 1 or 5 user actions code added, the presubmit
| |
| 1036 getElementsByTagName('action')] | |
| 1037 except: | |
| 1038 return [output_api.PresubmitPromptWarning( | |
| 1039 'Error parsing tools/metrics/actions/actions.xml.')] | |
| 1032 for action_name in match.groups(): | 1040 for action_name in match.groups(): |
| 1033 name_pattern = r'\t%s\n' % action_name | 1041 if action_name not in current_actions: |
| 1034 if name_pattern not in current_actions: | |
| 1035 return [output_api.PresubmitPromptWarning( | 1042 return [output_api.PresubmitPromptWarning( |
| 1036 'File %s line %d: %s is missing in ' | 1043 'File %s line %d: %s is missing in ' |
| 1037 'tools/metrics/actions/chromeactions.txt. Please run ' | 1044 'tools/metrics/actions/actions.xml. Please run ' |
| 1038 'tools/metrics/actions/extract_actions.py --hash to update.' | 1045 'tools/metrics/actions/extract_actions.py to update.' |
| 1039 % (f.LocalPath(), line_num, action_name))] | 1046 % (f.LocalPath(), line_num, action_name))] |
| 1040 return [] | 1047 return [] |
| 1041 | 1048 |
| 1042 | 1049 |
| 1043 def _CheckJavaStyle(input_api, output_api): | 1050 def _CheckJavaStyle(input_api, output_api): |
| 1044 """Runs checkstyle on changed java files and returns errors if any exist.""" | 1051 """Runs checkstyle on changed java files and returns errors if any exist.""" |
| 1045 original_sys_path = sys.path | 1052 original_sys_path = sys.path |
| 1046 try: | 1053 try: |
| 1047 sys.path = sys.path + [input_api.os_path.join( | 1054 sys.path = sys.path + [input_api.os_path.join( |
| 1048 input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')] | 1055 input_api.PresubmitLocalPath(), 'tools', 'android', 'checkstyle')] |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1451 trybots.extend(GetDefaultTryConfigs(['cros_x86'])) | 1458 trybots.extend(GetDefaultTryConfigs(['cros_x86'])) |
| 1452 | 1459 |
| 1453 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it | 1460 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it |
| 1454 # unless they're .gyp(i) files as changes to those files can break the gyp | 1461 # unless they're .gyp(i) files as changes to those files can break the gyp |
| 1455 # step on that bot. | 1462 # step on that bot. |
| 1456 if (not all(re.search('^chrome', f) for f in files) or | 1463 if (not all(re.search('^chrome', f) for f in files) or |
| 1457 any(re.search('\.gypi?$', f) for f in files)): | 1464 any(re.search('\.gypi?$', f) for f in files)): |
| 1458 trybots.extend(GetDefaultTryConfigs(['android_aosp'])) | 1465 trybots.extend(GetDefaultTryConfigs(['android_aosp'])) |
| 1459 | 1466 |
| 1460 return trybots | 1467 return trybots |
| OLD | NEW |