andrew@webrtc.org | 2442de1 | 2012-01-23 17:45:41 +0000 | [diff] [blame] | 1 | # Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 2 | # |
| 3 | # Use of this source code is governed by a BSD-style license |
| 4 | # that can be found in the LICENSE file in the root of the source |
| 5 | # tree. An additional intellectual property rights grant can be found |
| 6 | # in the file PATENTS. All contributing project authors may |
| 7 | # be found in the AUTHORS file in the root of the source tree. |
niklase@google.com | da159d6 | 2011-05-30 11:51:34 +0000 | [diff] [blame] | 8 | |
kjellander@webrtc.org | 8575980 | 2013-10-22 16:47:40 +0000 | [diff] [blame] | 9 | import re |
| 10 | |
| 11 | |
kjellander@webrtc.org | 51198f1 | 2012-02-21 17:53:46 +0000 | [diff] [blame] | 12 | def _CheckNoIOStreamInHeaders(input_api, output_api): |
| 13 | """Checks to make sure no .h files include <iostream>.""" |
| 14 | files = [] |
| 15 | pattern = input_api.re.compile(r'^#include\s*<iostream>', |
| 16 | input_api.re.MULTILINE) |
| 17 | for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): |
| 18 | if not f.LocalPath().endswith('.h'): |
| 19 | continue |
| 20 | contents = input_api.ReadFile(f) |
| 21 | if pattern.search(contents): |
| 22 | files.append(f) |
| 23 | |
| 24 | if len(files): |
| 25 | return [ output_api.PresubmitError( |
| 26 | 'Do not #include <iostream> in header files, since it inserts static ' + |
| 27 | 'initialization into every file including the header. Instead, ' + |
| 28 | '#include <ostream>. See http://crbug.com/94794', |
| 29 | files) ] |
| 30 | return [] |
| 31 | |
| 32 | def _CheckNoFRIEND_TEST(input_api, output_api): |
| 33 | """Make sure that gtest's FRIEND_TEST() macro is not used, the |
| 34 | FRIEND_TEST_ALL_PREFIXES() macro from testsupport/gtest_prod_util.h should be |
| 35 | used instead since that allows for FLAKY_, FAILS_ and DISABLED_ prefixes.""" |
| 36 | problems = [] |
| 37 | |
| 38 | file_filter = lambda f: f.LocalPath().endswith(('.cc', '.h')) |
| 39 | for f in input_api.AffectedFiles(file_filter=file_filter): |
| 40 | for line_num, line in f.ChangedContents(): |
| 41 | if 'FRIEND_TEST(' in line: |
| 42 | problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
| 43 | |
| 44 | if not problems: |
| 45 | return [] |
| 46 | return [output_api.PresubmitPromptWarning('WebRTC\'s code should not use ' |
| 47 | 'gtest\'s FRIEND_TEST() macro. Include testsupport/gtest_prod_util.h and ' |
| 48 | 'use FRIEND_TEST_ALL_PREFIXES() instead.\n' + '\n'.join(problems))] |
| 49 | |
mflodman@webrtc.org | 2a45209 | 2012-07-01 05:55:23 +0000 | [diff] [blame] | 50 | def _CheckApprovedFilesLintClean(input_api, output_api, |
| 51 | source_file_filter=None): |
| 52 | """Checks that all new or whitelisted .cc and .h files pass cpplint.py. |
kjellander@webrtc.org | 51198f1 | 2012-02-21 17:53:46 +0000 | [diff] [blame] | 53 | This check is based on _CheckChangeLintsClean in |
| 54 | depot_tools/presubmit_canned_checks.py but has less filters and only checks |
| 55 | added files.""" |
| 56 | result = [] |
| 57 | |
| 58 | # Initialize cpplint. |
| 59 | import cpplint |
| 60 | # Access to a protected member _XX of a client class |
| 61 | # pylint: disable=W0212 |
| 62 | cpplint._cpplint_state.ResetErrorCounts() |
| 63 | |
| 64 | # Justifications for each filter: |
| 65 | # |
| 66 | # - build/header_guard : WebRTC coding style says they should be prefixed |
| 67 | # with WEBRTC_, which is not possible to configure in |
| 68 | # cpplint.py. |
| 69 | cpplint._SetFilters('-build/header_guard') |
| 70 | |
| 71 | # Use the strictest verbosity level for cpplint.py (level 1) which is the |
| 72 | # default when running cpplint.py from command line. |
| 73 | # To make it possible to work with not-yet-converted code, we're only applying |
mflodman@webrtc.org | 2a45209 | 2012-07-01 05:55:23 +0000 | [diff] [blame] | 74 | # it to new (or moved/renamed) files and files listed in LINT_FOLDERS. |
kjellander@webrtc.org | 51198f1 | 2012-02-21 17:53:46 +0000 | [diff] [blame] | 75 | verbosity_level = 1 |
| 76 | files = [] |
| 77 | for f in input_api.AffectedSourceFiles(source_file_filter): |
| 78 | # Note that moved/renamed files also count as added for svn. |
phoglund@webrtc.org | 5d371393 | 2013-03-07 09:59:43 +0000 | [diff] [blame] | 79 | if (f.Action() == 'A'): |
kjellander@webrtc.org | 51198f1 | 2012-02-21 17:53:46 +0000 | [diff] [blame] | 80 | files.append(f.AbsoluteLocalPath()) |
mflodman@webrtc.org | 2a45209 | 2012-07-01 05:55:23 +0000 | [diff] [blame] | 81 | |
kjellander@webrtc.org | 51198f1 | 2012-02-21 17:53:46 +0000 | [diff] [blame] | 82 | for file_name in files: |
| 83 | cpplint.ProcessFile(file_name, verbosity_level) |
| 84 | |
| 85 | if cpplint._cpplint_state.error_count > 0: |
| 86 | if input_api.is_committing: |
| 87 | # TODO(kjellander): Change back to PresubmitError below when we're |
| 88 | # confident with the lint settings. |
| 89 | res_type = output_api.PresubmitPromptWarning |
| 90 | else: |
| 91 | res_type = output_api.PresubmitPromptWarning |
| 92 | result = [res_type('Changelist failed cpplint.py check.')] |
| 93 | |
| 94 | return result |
| 95 | |
andrew@webrtc.org | 53df136 | 2012-01-26 21:24:23 +0000 | [diff] [blame] | 96 | def _CommonChecks(input_api, output_api): |
| 97 | """Checks common to both upload and commit.""" |
kjellander@webrtc.org | 51198f1 | 2012-02-21 17:53:46 +0000 | [diff] [blame] | 98 | # TODO(kjellander): Use presubmit_canned_checks.PanProjectChecks too. |
niklase@google.com | da159d6 | 2011-05-30 11:51:34 +0000 | [diff] [blame] | 99 | results = [] |
phoglund@webrtc.org | 5d371393 | 2013-03-07 09:59:43 +0000 | [diff] [blame] | 100 | results.extend(input_api.canned_checks.RunPylint(input_api, output_api, |
| 101 | black_list=(r'^.*gviz_api\.py$', |
| 102 | r'^.*gaeunit\.py$', |
fischman@webrtc.org | 33584f9 | 2013-07-25 16:43:30 +0000 | [diff] [blame] | 103 | # Embedded shell-script fakes out pylint. |
| 104 | r'^talk/site_scons/site_tools/talk_linux.py$', |
phoglund@webrtc.org | 5d371393 | 2013-03-07 09:59:43 +0000 | [diff] [blame] | 105 | r'^third_party/.*\.py$', |
| 106 | r'^testing/.*\.py$', |
kjellander@webrtc.org | c7b8b2f | 2014-04-03 20:19:36 +0000 | [diff] [blame] | 107 | r'^tools/clang/.*\.py$', |
phoglund@webrtc.org | 5d371393 | 2013-03-07 09:59:43 +0000 | [diff] [blame] | 108 | r'^tools/gyp/.*\.py$', |
| 109 | r'^tools/perf_expectations/.*\.py$', |
phoglund@webrtc.org | 6d07ad9 | 2013-05-14 09:42:39 +0000 | [diff] [blame] | 110 | r'^tools/protoc_wrapper/.*\.py$', |
phoglund@webrtc.org | 5d371393 | 2013-03-07 09:59:43 +0000 | [diff] [blame] | 111 | r'^tools/python/.*\.py$', |
| 112 | r'^tools/python_charts/data/.*\.py$', |
kjellander@webrtc.org | 3365422 | 2013-08-22 07:57:00 +0000 | [diff] [blame] | 113 | r'^tools/refactoring/.*\.py$', |
kjellander@webrtc.org | f9bdbe3 | 2013-12-11 13:37:12 +0000 | [diff] [blame] | 114 | r'^tools/swarming_client/.*\.py$', |
phoglund@webrtc.org | 5d371393 | 2013-03-07 09:59:43 +0000 | [diff] [blame] | 115 | # TODO(phoglund): should arguably be checked. |
| 116 | r'^tools/valgrind-webrtc/.*\.py$', |
| 117 | r'^tools/valgrind/.*\.py$', |
| 118 | # TODO(phoglund): should arguably be checked. |
| 119 | r'^webrtc/build/.*\.py$', |
| 120 | r'^build/.*\.py$', |
fischman@webrtc.org | 10adbef | 2014-03-01 02:09:36 +0000 | [diff] [blame] | 121 | r'^out.*/.*\.py$',), |
phoglund@webrtc.org | 5d371393 | 2013-03-07 09:59:43 +0000 | [diff] [blame] | 122 | disabled_warnings=['F0401', # Failed to import x |
| 123 | 'E0611', # No package y in x |
| 124 | 'W0232', # Class has no __init__ method |
| 125 | ])) |
andrew@webrtc.org | 2442de1 | 2012-01-23 17:45:41 +0000 | [diff] [blame] | 126 | results.extend(input_api.canned_checks.CheckLongLines( |
pbos@webrtc.org | f2e7bc6 | 2013-04-08 15:46:07 +0000 | [diff] [blame] | 127 | input_api, output_api, maxlen=80)) |
andrew@webrtc.org | 2442de1 | 2012-01-23 17:45:41 +0000 | [diff] [blame] | 128 | results.extend(input_api.canned_checks.CheckChangeHasNoTabs( |
| 129 | input_api, output_api)) |
andrew@webrtc.org | 53df136 | 2012-01-26 21:24:23 +0000 | [diff] [blame] | 130 | results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace( |
| 131 | input_api, output_api)) |
| 132 | results.extend(input_api.canned_checks.CheckChangeTodoHasOwner( |
| 133 | input_api, output_api)) |
mflodman@webrtc.org | 2a45209 | 2012-07-01 05:55:23 +0000 | [diff] [blame] | 134 | results.extend(_CheckApprovedFilesLintClean(input_api, output_api)) |
kjellander@webrtc.org | 51198f1 | 2012-02-21 17:53:46 +0000 | [diff] [blame] | 135 | results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) |
| 136 | results.extend(_CheckNoFRIEND_TEST(input_api, output_api)) |
andrew@webrtc.org | 53df136 | 2012-01-26 21:24:23 +0000 | [diff] [blame] | 137 | return results |
andrew@webrtc.org | 2442de1 | 2012-01-23 17:45:41 +0000 | [diff] [blame] | 138 | |
andrew@webrtc.org | 53df136 | 2012-01-26 21:24:23 +0000 | [diff] [blame] | 139 | def CheckChangeOnUpload(input_api, output_api): |
| 140 | results = [] |
| 141 | results.extend(_CommonChecks(input_api, output_api)) |
niklase@google.com | da159d6 | 2011-05-30 11:51:34 +0000 | [diff] [blame] | 142 | return results |
| 143 | |
andrew@webrtc.org | 2442de1 | 2012-01-23 17:45:41 +0000 | [diff] [blame] | 144 | def CheckChangeOnCommit(input_api, output_api): |
niklase@google.com | 1198db9 | 2011-06-09 07:07:24 +0000 | [diff] [blame] | 145 | results = [] |
andrew@webrtc.org | 53df136 | 2012-01-26 21:24:23 +0000 | [diff] [blame] | 146 | results.extend(_CommonChecks(input_api, output_api)) |
niklase@google.com | 1198db9 | 2011-06-09 07:07:24 +0000 | [diff] [blame] | 147 | results.extend(input_api.canned_checks.CheckOwners(input_api, output_api)) |
andrew@webrtc.org | 53df136 | 2012-01-26 21:24:23 +0000 | [diff] [blame] | 148 | results.extend(input_api.canned_checks.CheckChangeWasUploaded( |
| 149 | input_api, output_api)) |
| 150 | results.extend(input_api.canned_checks.CheckChangeHasDescription( |
| 151 | input_api, output_api)) |
kjellander@webrtc.org | 51198f1 | 2012-02-21 17:53:46 +0000 | [diff] [blame] | 152 | results.extend(input_api.canned_checks.CheckChangeHasBugField( |
| 153 | input_api, output_api)) |
| 154 | results.extend(input_api.canned_checks.CheckChangeHasTestField( |
| 155 | input_api, output_api)) |
kjellander@webrtc.org | 12cb88c | 2014-02-13 11:53:43 +0000 | [diff] [blame] | 156 | results.extend(input_api.canned_checks.CheckTreeIsOpen( |
| 157 | input_api, output_api, |
| 158 | json_url='http://webrtc-status.appspot.com/current?format=json')) |
niklase@google.com | 1198db9 | 2011-06-09 07:07:24 +0000 | [diff] [blame] | 159 | return results |
kjellander@webrtc.org | 8575980 | 2013-10-22 16:47:40 +0000 | [diff] [blame] | 160 | |
kjellander@webrtc.org | c7b8b2f | 2014-04-03 20:19:36 +0000 | [diff] [blame] | 161 | def GetDefaultTryConfigs(bots=None): |
| 162 | """Returns a list of ('bot', set(['tests']), optionally filtered by [bots]. |
| 163 | |
| 164 | For WebRTC purposes, we always return an empty list of tests, since we want |
| 165 | to run all tests by default on all our trybots. |
| 166 | """ |
| 167 | return { 'tryserver.webrtc': dict((bot, []) for bot in bots)} |
| 168 | |
kjellander@webrtc.org | 8575980 | 2013-10-22 16:47:40 +0000 | [diff] [blame] | 169 | # pylint: disable=W0613 |
kjellander@webrtc.org | c7b8b2f | 2014-04-03 20:19:36 +0000 | [diff] [blame] | 170 | def GetPreferredTryMasters(project, change): |
kjellander@webrtc.org | 8575980 | 2013-10-22 16:47:40 +0000 | [diff] [blame] | 171 | files = change.LocalPaths() |
| 172 | |
kjellander@webrtc.org | cf2b3ac | 2013-12-20 21:20:42 +0000 | [diff] [blame] | 173 | android_bots = [ |
| 174 | 'android', |
kjellander@webrtc.org | 9359eda | 2014-06-08 17:55:51 +0000 | [diff] [blame] | 175 | 'android_arm64', |
kjellander@webrtc.org | 2a260d9 | 2014-01-27 16:08:43 +0000 | [diff] [blame] | 176 | 'android_apk', |
| 177 | 'android_apk_rel', |
kjellander@webrtc.org | cf2b3ac | 2013-12-20 21:20:42 +0000 | [diff] [blame] | 178 | 'android_rel', |
| 179 | 'android_clang', |
| 180 | ] |
kjellander@webrtc.org | 8575980 | 2013-10-22 16:47:40 +0000 | [diff] [blame] | 181 | ios_bots = [ |
| 182 | 'ios', |
| 183 | 'ios_rel', |
| 184 | ] |
| 185 | linux_bots = [ |
| 186 | 'linux', |
| 187 | 'linux_asan', |
kjellander@webrtc.org | 570bc3d | 2014-01-22 19:00:01 +0000 | [diff] [blame] | 188 | 'linux_baremetal', |
kjellander@webrtc.org | 8575980 | 2013-10-22 16:47:40 +0000 | [diff] [blame] | 189 | 'linux_memcheck', |
| 190 | 'linux_rel', |
kjellander@webrtc.org | c7b8b2f | 2014-04-03 20:19:36 +0000 | [diff] [blame] | 191 | 'linux_tsan2', |
kjellander@webrtc.org | 8575980 | 2013-10-22 16:47:40 +0000 | [diff] [blame] | 192 | ] |
| 193 | mac_bots = [ |
| 194 | 'mac', |
| 195 | 'mac_asan', |
kjellander@webrtc.org | 570bc3d | 2014-01-22 19:00:01 +0000 | [diff] [blame] | 196 | 'mac_baremetal', |
kjellander@webrtc.org | 8575980 | 2013-10-22 16:47:40 +0000 | [diff] [blame] | 197 | 'mac_rel', |
| 198 | 'mac_x64_rel', |
| 199 | ] |
| 200 | win_bots = [ |
| 201 | 'win', |
kjellander@webrtc.org | c7b8b2f | 2014-04-03 20:19:36 +0000 | [diff] [blame] | 202 | 'win_asan', |
kjellander@webrtc.org | 570bc3d | 2014-01-22 19:00:01 +0000 | [diff] [blame] | 203 | 'win_baremetal', |
kjellander@webrtc.org | a956ec2 | 2014-04-14 08:38:27 +0000 | [diff] [blame] | 204 | 'win_drmemory_light', |
kjellander@webrtc.org | 8575980 | 2013-10-22 16:47:40 +0000 | [diff] [blame] | 205 | 'win_rel', |
| 206 | 'win_x64_rel', |
| 207 | ] |
kjellander@webrtc.org | 8575980 | 2013-10-22 16:47:40 +0000 | [diff] [blame] | 208 | if not files or all(re.search(r'[\\/]OWNERS$', f) for f in files): |
kjellander@webrtc.org | c7b8b2f | 2014-04-03 20:19:36 +0000 | [diff] [blame] | 209 | return {} |
kjellander@webrtc.org | 8575980 | 2013-10-22 16:47:40 +0000 | [diff] [blame] | 210 | |
kjellander@webrtc.org | 8575980 | 2013-10-22 16:47:40 +0000 | [diff] [blame] | 211 | if all(re.search('\.(m|mm)$|(^|[/_])mac[/_.]', f) for f in files): |
kjellander@webrtc.org | c7b8b2f | 2014-04-03 20:19:36 +0000 | [diff] [blame] | 212 | return GetDefaultTryConfigs(mac_bots) |
kjellander@webrtc.org | 8575980 | 2013-10-22 16:47:40 +0000 | [diff] [blame] | 213 | if all(re.search('(^|[/_])win[/_.]', f) for f in files): |
kjellander@webrtc.org | c7b8b2f | 2014-04-03 20:19:36 +0000 | [diff] [blame] | 214 | return GetDefaultTryConfigs(win_bots) |
| 215 | if all(re.search('(^|[/_])android[/_.]', f) for f in files): |
| 216 | return GetDefaultTryConfigs(android_bots) |
| 217 | if all(re.search('[/_]ios[/_.]', f) for f in files): |
| 218 | return GetDefaultTryConfigs(ios_bots) |
kjellander@webrtc.org | 8575980 | 2013-10-22 16:47:40 +0000 | [diff] [blame] | 219 | |
kjellander@webrtc.org | c7b8b2f | 2014-04-03 20:19:36 +0000 | [diff] [blame] | 220 | return GetDefaultTryConfigs(android_bots + ios_bots + linux_bots + mac_bots + |
| 221 | win_bots) |