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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 if pattern.search(contents): | 249 if pattern.search(contents): |
250 violating_files.append(f) | 250 violating_files.append(f) |
251 if violating_files: | 251 if violating_files: |
252 return [output_api.PresubmitError( | 252 return [output_api.PresubmitError( |
253 'Depending on rtc_base is not allowed. Change your dependency to ' | 253 'Depending on rtc_base is not allowed. Change your dependency to ' |
254 'rtc_base_approved and possibly sanitize and move the desired source ' | 254 'rtc_base_approved and possibly sanitize and move the desired source ' |
255 'file(s) to rtc_base_approved.\nChanged GYP files:', | 255 'file(s) to rtc_base_approved.\nChanged GYP files:', |
256 items=violating_files)] | 256 items=violating_files)] |
257 return [] | 257 return [] |
258 | 258 |
259 def _CheckNoRtcBaseDepsGn(input_api, gn_files, output_api): | |
260 pattern = input_api.re.compile(r'base:rtc_base\s*"') | |
261 violating_files = [] | |
262 for f in gn_files: | |
263 gn_exceptions = ( | |
264 os.path.join('base_tests', 'BUILD.gn'), | |
265 os.path.join('desktop_capture', 'BUILD.gn'), | |
266 os.path.join('p2p', 'BUILD.gn'), | |
267 os.path.join('sdk', 'BUILD.gn'), | |
268 os.path.join('webrtc_test_common', 'BUILD.gn'), | |
269 os.path.join('webrtc_tests', 'BUILD.gn'), | |
270 | |
271 # This are not in GYP, but were in GN at the time of writing this | |
ehmaldonado_webrtc
2016/09/02 09:32:18
What should we do with these files?
kjellander_webrtc
2016/09/02 12:13:22
Leave them as is and add a reference to https://bu
| |
272 os.path.join('webrtc', 'BUILD.gn'), | |
273 os.path.join('xmllite', 'BUILD.gn'), | |
274 os.path.join('xmpp', 'BUILD.gn'), | |
275 os.path.join('modules', 'BUILD.gn'), | |
276 os.path.join('audio_device', 'BUILD.gn'), | |
277 os.path.join('pc', 'BUILD.gn'), | |
278 ) | |
279 if f.LocalPath().endswith(gn_exceptions): | |
280 continue | |
281 contents = input_api.ReadFile(f) | |
282 if pattern.search(contents): | |
283 violating_files.append(f) | |
284 if violating_files: | |
285 return [output_api.PresubmitError( | |
286 'Depending on rtc_base is not allowed. Change your dependency to ' | |
287 'rtc_base_approved and possibly sanitize and move the desired source ' | |
288 'file(s) to rtc_base_approved.\nChanged GN files:', | |
289 items=violating_files)] | |
290 return [] | |
291 | |
259 def _CheckNoSourcesAboveGyp(input_api, gyp_files, output_api): | 292 def _CheckNoSourcesAboveGyp(input_api, gyp_files, output_api): |
260 # Disallow referencing source files with paths above the GYP file location. | 293 # Disallow referencing source files with paths above the GYP file location. |
261 source_pattern = input_api.re.compile(r'\'sources\'.*?\[(.*?)\]', | 294 source_pattern = input_api.re.compile(r'\'sources\'.*?\[(.*?)\]', |
262 re.MULTILINE | re.DOTALL) | 295 re.MULTILINE | re.DOTALL) |
263 file_pattern = input_api.re.compile(r"'((\.\./.*?)|(<\(webrtc_root\).*?))'") | 296 file_pattern = input_api.re.compile(r"'((\.\./.*?)|(<\(webrtc_root\).*?))'") |
264 violating_gyp_files = set() | 297 violating_gyp_files = set() |
265 violating_source_entries = [] | 298 violating_source_entries = [] |
266 for gyp_file in gyp_files: | 299 for gyp_file in gyp_files: |
267 if 'supplement.gypi' in gyp_file.LocalPath(): | 300 if 'supplement.gypi' in gyp_file.LocalPath(): |
268 # Exclude supplement.gypi from this check, as the LSan and TSan | 301 # Exclude supplement.gypi from this check, as the LSan and TSan |
(...skipping 12 matching lines...) Expand all Loading... | |
281 return [output_api.PresubmitError( | 314 return [output_api.PresubmitError( |
282 'Referencing source files above the directory of the GYP file is not ' | 315 'Referencing source files above the directory of the GYP file is not ' |
283 'allowed. Please introduce new GYP targets and/or GYP files in the ' | 316 'allowed. Please introduce new GYP targets and/or GYP files in the ' |
284 'proper location instead.\n' | 317 'proper location instead.\n' |
285 'Invalid source entries:\n' | 318 'Invalid source entries:\n' |
286 '%s\n' | 319 '%s\n' |
287 'Violating GYP files:' % '\n'.join(violating_source_entries), | 320 'Violating GYP files:' % '\n'.join(violating_source_entries), |
288 items=violating_gyp_files)] | 321 items=violating_gyp_files)] |
289 return [] | 322 return [] |
290 | 323 |
324 def _CheckNoSourcesAboveGn(input_api, gn_files, output_api): | |
325 # Disallow referencing source files with paths above the GN file location. | |
326 source_pattern = input_api.re.compile(r' +sources \+?= \[(.*?)\]', | |
327 re.MULTILINE | re.DOTALL) | |
328 file_pattern = input_api.re.compile(r'"((\.\./.*?)|(//.*?))"') | |
329 violating_gn_files = set() | |
330 violating_source_entries = [] | |
331 for gn_file in gn_files: | |
332 contents = input_api.ReadFile(gn_file) | |
333 for source_block_match in source_pattern.finditer(contents): | |
334 # Find all source list entries starting with ../ in the source block | |
335 # (exclude overrides entries). | |
336 for file_list_match in file_pattern.finditer(source_block_match.group(1)): | |
337 source_file = file_list_match.group(1) | |
338 if 'overrides/' not in source_file: | |
339 violating_source_entries.append(source_file) | |
340 violating_gn_files.add(gn_file) | |
341 if violating_gn_files: | |
342 return [output_api.PresubmitError( | |
343 'Referencing source files above the directory of the GN file is not ' | |
344 'allowed. Please introduce new GYP targets and/or GN files in the ' | |
345 'proper location instead.\n' | |
346 'Invalid source entries:\n' | |
347 '%s\n' | |
348 'Violating GN files:' % '\n'.join(violating_source_entries), | |
349 items=violating_gn_files)] | |
350 return [] | |
351 | |
291 def _CheckGypChanges(input_api, output_api): | 352 def _CheckGypChanges(input_api, output_api): |
292 source_file_filter = lambda x: input_api.FilterSourceFile( | 353 source_file_filter = lambda x: input_api.FilterSourceFile( |
293 x, white_list=(r'.+\.(gyp|gypi)$',)) | 354 x, white_list=(r'.+\.(gyp|gypi)$',)) |
294 | 355 |
295 gyp_files = [] | 356 gyp_files = [] |
296 for f in input_api.AffectedSourceFiles(source_file_filter): | 357 for f in input_api.AffectedSourceFiles(source_file_filter): |
297 if f.LocalPath().startswith('webrtc'): | 358 if f.LocalPath().startswith('webrtc'): |
298 gyp_files.append(f) | 359 gyp_files.append(f) |
299 | 360 |
300 result = [] | 361 result = [] |
301 if gyp_files: | 362 if gyp_files: |
302 result.append(output_api.PresubmitNotifyResult( | 363 result.append(output_api.PresubmitNotifyResult( |
303 'As you\'re changing GYP files: please make sure corresponding ' | 364 'As you\'re changing GYP files: please make sure corresponding ' |
304 'BUILD.gn files are also updated.\nChanged GYP files:', | 365 'BUILD.gn files are also updated.\nChanged GYP files:', |
305 items=gyp_files)) | 366 items=gyp_files)) |
306 result.extend(_CheckNoRtcBaseDeps(input_api, gyp_files, output_api)) | 367 result.extend(_CheckNoRtcBaseDeps(input_api, gyp_files, output_api)) |
307 result.extend(_CheckNoSourcesAboveGyp(input_api, gyp_files, output_api)) | 368 result.extend(_CheckNoSourcesAboveGyp(input_api, gyp_files, output_api)) |
308 return result | 369 return result |
309 | 370 |
371 def _CheckGnChanges(input_api, output_api): | |
372 source_file_filter = lambda x: input_api.FilterSourceFile( | |
373 x, white_list=(r'.+\.(gn|gni)$',)) | |
374 | |
375 gn_files = [] | |
376 for f in input_api.AffectedSourceFiles(source_file_filter): | |
377 if f.LocalPath().startswith('webrtc'): | |
378 gn_files.append(f) | |
379 | |
380 result = [] | |
381 if gn_files: | |
382 result.append(output_api.PresubmitNotifyResult( | |
383 'As you\'re changing GN files: please make sure corresponding GYP' | |
384 'files are also updated.\nChanged GN files:', | |
385 items=gn_files)) | |
386 result.extend(_CheckNoRtcBaseDepsGn(input_api, gn_files, output_api)) | |
387 result.extend(_CheckNoSourcesAboveGn(input_api, gn_files, output_api)) | |
388 return result | |
389 | |
310 def _CheckUnwantedDependencies(input_api, output_api): | 390 def _CheckUnwantedDependencies(input_api, output_api): |
311 """Runs checkdeps on #include statements added in this | 391 """Runs checkdeps on #include statements added in this |
312 change. Breaking - rules is an error, breaking ! rules is a | 392 change. Breaking - rules is an error, breaking ! rules is a |
313 warning. | 393 warning. |
314 """ | 394 """ |
315 # Copied from Chromium's src/PRESUBMIT.py. | 395 # Copied from Chromium's src/PRESUBMIT.py. |
316 | 396 |
317 # We need to wait until we have an input_api object and use this | 397 # We need to wait until we have an input_api object and use this |
318 # roundabout construct to import checkdeps because this file is | 398 # roundabout construct to import checkdeps because this file is |
319 # eval-ed and thus doesn't have __file__. | 399 # eval-ed and thus doesn't have __file__. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
482 results.extend(input_api.canned_checks.CheckChangeHasNoTabs( | 562 results.extend(input_api.canned_checks.CheckChangeHasNoTabs( |
483 input_api, output_api)) | 563 input_api, output_api)) |
484 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace( | 564 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace( |
485 input_api, output_api)) | 565 input_api, output_api)) |
486 results.extend(input_api.canned_checks.CheckChangeTodoHasOwner( | 566 results.extend(input_api.canned_checks.CheckChangeTodoHasOwner( |
487 input_api, output_api)) | 567 input_api, output_api)) |
488 results.extend(_CheckNativeApiHeaderChanges(input_api, output_api)) | 568 results.extend(_CheckNativeApiHeaderChanges(input_api, output_api)) |
489 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) | 569 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) |
490 results.extend(_CheckNoFRIEND_TEST(input_api, output_api)) | 570 results.extend(_CheckNoFRIEND_TEST(input_api, output_api)) |
491 results.extend(_CheckGypChanges(input_api, output_api)) | 571 results.extend(_CheckGypChanges(input_api, output_api)) |
572 results.extend(_CheckGnChanges(input_api, output_api)) | |
492 results.extend(_CheckUnwantedDependencies(input_api, output_api)) | 573 results.extend(_CheckUnwantedDependencies(input_api, output_api)) |
493 results.extend(_CheckJSONParseErrors(input_api, output_api)) | 574 results.extend(_CheckJSONParseErrors(input_api, output_api)) |
494 results.extend(_RunPythonTests(input_api, output_api)) | 575 results.extend(_RunPythonTests(input_api, output_api)) |
495 return results | 576 return results |
496 | 577 |
497 | 578 |
498 def CheckChangeOnUpload(input_api, output_api): | 579 def CheckChangeOnUpload(input_api, output_api): |
499 results = [] | 580 results = [] |
500 results.extend(_CommonChecks(input_api, output_api)) | 581 results.extend(_CommonChecks(input_api, output_api)) |
501 results.extend( | 582 results.extend( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
538 for builder in masters[master]: | 619 for builder in masters[master]: |
539 if 'presubmit' in builder: | 620 if 'presubmit' in builder: |
540 # Do not trigger presubmit builders, since they're likely to fail | 621 # Do not trigger presubmit builders, since they're likely to fail |
541 # (e.g. OWNERS checks before finished code review), and we're running | 622 # (e.g. OWNERS checks before finished code review), and we're running |
542 # local presubmit anyway. | 623 # local presubmit anyway. |
543 pass | 624 pass |
544 else: | 625 else: |
545 try_config[master][builder] = ['defaulttests'] | 626 try_config[master][builder] = ['defaulttests'] |
546 | 627 |
547 return try_config | 628 return try_config |
OLD | NEW |