OLD | NEW |
1 # Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 1 # Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
2 # | 2 # |
3 # Use of this source code is governed by a BSD-style license | 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 | 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 | 5 # tree. An additional intellectual property rights grant can be found |
6 # in the file PATENTS. All contributing project authors may | 6 # in the file PATENTS. All contributing project authors may |
7 # be found in the AUTHORS file in the root of the source tree. | 7 # be found in the AUTHORS file in the root of the source tree. |
8 | 8 |
9 import json | 9 import json |
10 import os | 10 import os |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 if input_api.is_committing: | 221 if input_api.is_committing: |
222 # TODO(kjellander): Change back to PresubmitError below when we're | 222 # TODO(kjellander): Change back to PresubmitError below when we're |
223 # confident with the lint settings. | 223 # confident with the lint settings. |
224 res_type = output_api.PresubmitPromptWarning | 224 res_type = output_api.PresubmitPromptWarning |
225 else: | 225 else: |
226 res_type = output_api.PresubmitPromptWarning | 226 res_type = output_api.PresubmitPromptWarning |
227 result = [res_type('Changelist failed cpplint.py check.')] | 227 result = [res_type('Changelist failed cpplint.py check.')] |
228 | 228 |
229 return result | 229 return result |
230 | 230 |
231 def _CheckNoRtcBaseDeps(input_api, gn_files, output_api): | |
232 pattern = input_api.re.compile(r'base:rtc_base\s*"') | |
233 violating_files = [] | |
234 for f in gn_files: | |
235 gn_exceptions = ( | |
236 os.path.join('audio_device', 'BUILD.gn'), | |
237 os.path.join('base_tests', 'BUILD.gn'), | |
238 os.path.join('desktop_capture', 'BUILD.gn'), | |
239 os.path.join('p2p', 'BUILD.gn'), | |
240 os.path.join('sdk', 'BUILD.gn'), | |
241 os.path.join('webrtc_test_common', 'BUILD.gn'), | |
242 os.path.join('webrtc_tests', 'BUILD.gn'), | |
243 | |
244 # TODO(ehmaldonado): Clean up references to rtc_base in these files. | |
245 # See https://bugs.chromium.org/p/webrtc/issues/detail?id=3806 | |
246 os.path.join('webrtc', 'BUILD.gn'), | |
247 os.path.join('xmllite', 'BUILD.gn'), | |
248 os.path.join('xmpp', 'BUILD.gn'), | |
249 os.path.join('modules', 'BUILD.gn'), | |
250 os.path.join('audio_device', 'BUILD.gn'), | |
251 os.path.join('pc', 'BUILD.gn'), | |
252 ) | |
253 if f.LocalPath().endswith(gn_exceptions): | |
254 continue | |
255 contents = input_api.ReadFile(f) | |
256 if pattern.search(contents): | |
257 violating_files.append(f) | |
258 if violating_files: | |
259 return [output_api.PresubmitError( | |
260 'Depending on rtc_base is not allowed. Change your dependency to ' | |
261 'rtc_base_approved and possibly sanitize and move the desired source ' | |
262 'file(s) to rtc_base_approved.\nChanged GN files:', | |
263 items=violating_files)] | |
264 return [] | |
265 | |
266 | |
267 def _CheckNoSourcesAbove(input_api, gn_files, output_api): | 231 def _CheckNoSourcesAbove(input_api, gn_files, output_api): |
268 # Disallow referencing source files with paths above the GN file location. | 232 # Disallow referencing source files with paths above the GN file location. |
269 source_pattern = input_api.re.compile(r' +sources \+?= \[(.*?)\]', | 233 source_pattern = input_api.re.compile(r' +sources \+?= \[(.*?)\]', |
270 re.MULTILINE | re.DOTALL) | 234 re.MULTILINE | re.DOTALL) |
271 file_pattern = input_api.re.compile(r'"((\.\./.*?)|(//.*?))"') | 235 file_pattern = input_api.re.compile(r'"((\.\./.*?)|(//.*?))"') |
272 violating_gn_files = set() | 236 violating_gn_files = set() |
273 violating_source_entries = [] | 237 violating_source_entries = [] |
274 for gn_file in gn_files: | 238 for gn_file in gn_files: |
275 contents = input_api.ReadFile(gn_file) | 239 contents = input_api.ReadFile(gn_file) |
276 for source_block_match in source_pattern.finditer(contents): | 240 for source_block_match in source_pattern.finditer(contents): |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 source_file_filter = lambda x: input_api.FilterSourceFile( | 289 source_file_filter = lambda x: input_api.FilterSourceFile( |
326 x, white_list=(r'.+\.(gn|gni)$',)) | 290 x, white_list=(r'.+\.(gn|gni)$',)) |
327 | 291 |
328 gn_files = [] | 292 gn_files = [] |
329 for f in input_api.AffectedSourceFiles(source_file_filter): | 293 for f in input_api.AffectedSourceFiles(source_file_filter): |
330 if f.LocalPath().startswith('webrtc'): | 294 if f.LocalPath().startswith('webrtc'): |
331 gn_files.append(f) | 295 gn_files.append(f) |
332 | 296 |
333 result = [] | 297 result = [] |
334 if gn_files: | 298 if gn_files: |
335 result.extend(_CheckNoRtcBaseDeps(input_api, gn_files, output_api)) | |
336 result.extend(_CheckNoSourcesAbove(input_api, gn_files, output_api)) | 299 result.extend(_CheckNoSourcesAbove(input_api, gn_files, output_api)) |
337 result.extend(_CheckNoMixingCAndCCSources(input_api, gn_files, output_api)) | 300 result.extend(_CheckNoMixingCAndCCSources(input_api, gn_files, output_api)) |
338 return result | 301 return result |
339 | 302 |
340 def _CheckUnwantedDependencies(input_api, output_api): | 303 def _CheckUnwantedDependencies(input_api, output_api): |
341 """Runs checkdeps on #include statements added in this | 304 """Runs checkdeps on #include statements added in this |
342 change. Breaking - rules is an error, breaking ! rules is a | 305 change. Breaking - rules is an error, breaking ! rules is a |
343 warning. | 306 warning. |
344 """ | 307 """ |
345 # Copied from Chromium's src/PRESUBMIT.py. | 308 # Copied from Chromium's src/PRESUBMIT.py. |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 input_api, output_api)) | 520 input_api, output_api)) |
558 results.extend(input_api.canned_checks.CheckChangeHasDescription( | 521 results.extend(input_api.canned_checks.CheckChangeHasDescription( |
559 input_api, output_api)) | 522 input_api, output_api)) |
560 results.extend(_CheckChangeHasBugField(input_api, output_api)) | 523 results.extend(_CheckChangeHasBugField(input_api, output_api)) |
561 results.extend(input_api.canned_checks.CheckChangeHasTestField( | 524 results.extend(input_api.canned_checks.CheckChangeHasTestField( |
562 input_api, output_api)) | 525 input_api, output_api)) |
563 results.extend(input_api.canned_checks.CheckTreeIsOpen( | 526 results.extend(input_api.canned_checks.CheckTreeIsOpen( |
564 input_api, output_api, | 527 input_api, output_api, |
565 json_url='http://webrtc-status.appspot.com/current?format=json')) | 528 json_url='http://webrtc-status.appspot.com/current?format=json')) |
566 return results | 529 return results |
OLD | NEW |