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 |
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
969 cygwin_shell.append(f.LocalPath()) | 969 cygwin_shell.append(f.LocalPath()) |
970 break | 970 break |
971 | 971 |
972 if cygwin_shell: | 972 if cygwin_shell: |
973 return [output_api.PresubmitError( | 973 return [output_api.PresubmitError( |
974 'These files should not use msvs_cygwin_shell (the default is 0):', | 974 'These files should not use msvs_cygwin_shell (the default is 0):', |
975 items=cygwin_shell)] | 975 items=cygwin_shell)] |
976 return [] | 976 return [] |
977 | 977 |
978 | 978 |
979 def _CheckJavaStyle(input_api, output_api): | |
980 """Runs checkstyle on changed java files and returns errors if any exist.""" | |
981 style_file = './tools/android/checkstyle/chromium-style-5.0.xml' | |
982 import os | |
newt (away)
2013/12/10 00:04:28
move "import" to beginning of function
| |
983 if not os.path.exists(style_file): | |
984 file_error = (' Java checkstyle configuration file is missing') | |
newt (away)
2013/12/10 00:04:28
I'd include the path to the missing file to help p
aurimas (slooooooooow)
2013/12/10 02:31:47
Done.
| |
985 return [output_api.PresubmitError(file_error)] | |
986 | |
987 # Filter out non-Java files and files that were deleted. | |
988 java_files = [x.LocalPath() for x in input_api.AffectedFiles(False, False) | |
989 if os.path.splitext(x.LocalPath())[1].lower() == '.java'] | |
990 if not java_files: | |
991 return [] | |
992 | |
993 # Run checkstyle | |
994 checkstyle_env = os.environ.copy() | |
995 checkstyle_env['JAVA_CMD'] = 'java' | |
996 try: | |
997 check = subprocess.Popen(['checkstyle', '-c', style_file] + java_files, | |
998 stdout=subprocess.PIPE, env=checkstyle_env) | |
999 stdout, _ = check.communicate() | |
1000 if check.returncode == 0: | |
1001 return [] | |
1002 except OSError as e: | |
1003 import errno | |
1004 if e.errno == errno.ENOENT: | |
1005 install_error = (' checkstyle is not installed. Please run ' | |
1006 'build/install-build-deps-android.sh') | |
1007 return [output_api.PresubmitPromptWarning(install_error)] | |
1008 | |
1009 # Remove non-error values from stdout | |
1010 errors = stdout.splitlines() | |
1011 output_header = 'Starting audit...' | |
1012 output_footer = 'Audit done.' | |
1013 | |
1014 if errors and errors[0] == output_header: | |
1015 del errors[0] | |
1016 if errors and errors[-1] == output_footer: | |
1017 del errors[-1] | |
1018 | |
1019 # Filter out warnings | |
1020 errors = [x for x in errors if 'warning: ' not in x] | |
1021 if not errors: | |
1022 return [] | |
1023 else: | |
1024 local_path = input_api.PresubmitLocalPath() | |
1025 output = [] | |
1026 for error in errors: | |
1027 # Change the full file path to relative path in the output lines | |
1028 full_path, end = error.split(':', 1) | |
1029 rel_path = os.path.relpath(full_path, local_path) | |
1030 output.append(' %s:%s' % (rel_path, end)) | |
1031 return [output_api.PresubmitPromptWarning('\n'.join(output))] | |
1032 | |
1033 | |
979 def _CommonChecks(input_api, output_api): | 1034 def _CommonChecks(input_api, output_api): |
980 """Checks common to both upload and commit.""" | 1035 """Checks common to both upload and commit.""" |
981 results = [] | 1036 results = [] |
982 results.extend(input_api.canned_checks.PanProjectChecks( | 1037 results.extend(input_api.canned_checks.PanProjectChecks( |
983 input_api, output_api, excluded_paths=_EXCLUDED_PATHS)) | 1038 input_api, output_api, excluded_paths=_EXCLUDED_PATHS)) |
984 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) | 1039 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) |
985 results.extend( | 1040 results.extend( |
986 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) | 1041 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) |
987 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) | 1042 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) |
988 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api)) | 1043 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api)) |
989 results.extend(_CheckNoNewWStrings(input_api, output_api)) | 1044 results.extend(_CheckNoNewWStrings(input_api, output_api)) |
990 results.extend(_CheckNoDEPSGIT(input_api, output_api)) | 1045 results.extend(_CheckNoDEPSGIT(input_api, output_api)) |
991 results.extend(_CheckNoBannedFunctions(input_api, output_api)) | 1046 results.extend(_CheckNoBannedFunctions(input_api, output_api)) |
992 results.extend(_CheckNoPragmaOnce(input_api, output_api)) | 1047 results.extend(_CheckNoPragmaOnce(input_api, output_api)) |
993 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api)) | 1048 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api)) |
994 results.extend(_CheckUnwantedDependencies(input_api, output_api)) | 1049 results.extend(_CheckUnwantedDependencies(input_api, output_api)) |
995 results.extend(_CheckFilePermissions(input_api, output_api)) | 1050 results.extend(_CheckFilePermissions(input_api, output_api)) |
996 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api)) | 1051 results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api)) |
997 results.extend(_CheckIncludeOrder(input_api, output_api)) | 1052 results.extend(_CheckIncludeOrder(input_api, output_api)) |
998 results.extend(_CheckForVersionControlConflicts(input_api, output_api)) | 1053 results.extend(_CheckForVersionControlConflicts(input_api, output_api)) |
999 results.extend(_CheckPatchFiles(input_api, output_api)) | 1054 results.extend(_CheckPatchFiles(input_api, output_api)) |
1000 results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api)) | 1055 results.extend(_CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api)) |
1001 results.extend(_CheckNoAbbreviationInPngFileName(input_api, output_api)) | 1056 results.extend(_CheckNoAbbreviationInPngFileName(input_api, output_api)) |
1002 results.extend(_CheckForInvalidOSMacros(input_api, output_api)) | 1057 results.extend(_CheckForInvalidOSMacros(input_api, output_api)) |
1003 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api)) | 1058 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api)) |
1004 results.extend( | 1059 results.extend( |
1005 input_api.canned_checks.CheckChangeHasNoTabs( | 1060 input_api.canned_checks.CheckChangeHasNoTabs( |
1006 input_api, | 1061 input_api, |
1007 output_api, | 1062 output_api, |
1008 source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) | 1063 source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) |
1009 results.extend(_CheckSpamLogging(input_api, output_api)) | 1064 results.extend(_CheckSpamLogging(input_api, output_api)) |
1010 results.extend(_CheckForAnonymousVariables(input_api, output_api)) | 1065 results.extend(_CheckForAnonymousVariables(input_api, output_api)) |
1011 results.extend(_CheckCygwinShell(input_api, output_api)) | 1066 results.extend(_CheckCygwinShell(input_api, output_api)) |
1067 results.extend(_CheckJavaStyle(input_api, output_api)) | |
1012 | 1068 |
1013 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): | 1069 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): |
1014 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( | 1070 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( |
1015 input_api, output_api, | 1071 input_api, output_api, |
1016 input_api.PresubmitLocalPath(), | 1072 input_api.PresubmitLocalPath(), |
1017 whitelist=[r'^PRESUBMIT_test\.py$'])) | 1073 whitelist=[r'^PRESUBMIT_test\.py$'])) |
1018 return results | 1074 return results |
1019 | 1075 |
1020 | 1076 |
1021 def _CheckSubversionConfig(input_api, output_api): | 1077 def _CheckSubversionConfig(input_api, output_api): |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1229 trybots += ['cros_x86'] | 1285 trybots += ['cros_x86'] |
1230 | 1286 |
1231 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it | 1287 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it |
1232 # unless they're .gyp(i) files as changes to those files can break the gyp | 1288 # unless they're .gyp(i) files as changes to those files can break the gyp |
1233 # step on that bot. | 1289 # step on that bot. |
1234 if (not all(re.search('^chrome', f) for f in files) or | 1290 if (not all(re.search('^chrome', f) for f in files) or |
1235 any(re.search('\.gypi?$', f) for f in files)): | 1291 any(re.search('\.gypi?$', f) for f in files)): |
1236 trybots += ['android_aosp'] | 1292 trybots += ['android_aosp'] |
1237 | 1293 |
1238 return trybots | 1294 return trybots |
OLD | NEW |