Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(455)

Side by Side Diff: PRESUBMIT.py

Issue 1682393002: PRESUBMIT: Add check for JSON parse errors + fix JSON (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Reduced unnecessary code. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/build/ios/client.webrtc.fyi/iOS32_Simulator_Debug.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 error_descriptions)) 332 error_descriptions))
333 if warning_descriptions: 333 if warning_descriptions:
334 results.append(output_api.PresubmitPromptOrNotify( 334 results.append(output_api.PresubmitPromptOrNotify(
335 'You added one or more #includes of files that are temporarily\n' 335 'You added one or more #includes of files that are temporarily\n'
336 'allowed but being removed. Can you avoid introducing the\n' 336 'allowed but being removed. Can you avoid introducing the\n'
337 '#include? See relevant DEPS file(s) for details and contacts.', 337 '#include? See relevant DEPS file(s) for details and contacts.',
338 warning_descriptions)) 338 warning_descriptions))
339 return results 339 return results
340 340
341 341
342 def _CheckJSONParseErrors(input_api, output_api):
343 """Check that JSON files do not contain syntax errors."""
344
345 def FilterFile(affected_file):
346 return input_api.os_path.splitext(affected_file.LocalPath())[1] == '.json'
347
348 def GetJSONParseError(input_api, filename):
349 try:
350 contents = input_api.ReadFile(filename)
351 input_api.json.loads(contents)
352 except ValueError as e:
353 return e
354 return None
355
356 results = []
357 for affected_file in input_api.AffectedFiles(
358 file_filter=FilterFile, include_deletes=False):
359 parse_error = GetJSONParseError(input_api,
360 affected_file.AbsoluteLocalPath())
361 if parse_error:
362 results.append(output_api.PresubmitError('%s could not be parsed: %s' %
363 (affected_file.LocalPath(), parse_error)))
364 return results
365
366
342 def _RunPythonTests(input_api, output_api): 367 def _RunPythonTests(input_api, output_api):
343 def join(*args): 368 def join(*args):
344 return input_api.os_path.join(input_api.PresubmitLocalPath(), *args) 369 return input_api.os_path.join(input_api.PresubmitLocalPath(), *args)
345 370
346 test_directories = [ 371 test_directories = [
347 join('tools', 'autoroller', 'unittests'), 372 join('tools', 'autoroller', 'unittests'),
348 ] 373 ]
349 374
350 tests = [] 375 tests = []
351 for directory in test_directories: 376 for directory in test_directories:
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 # TODO(phoglund): should arguably be checked. 421 # TODO(phoglund): should arguably be checked.
397 r'^tools[\\\/]valgrind-webrtc[\\\/].*\.py$', 422 r'^tools[\\\/]valgrind-webrtc[\\\/].*\.py$',
398 r'^tools[\\\/]valgrind[\\\/].*\.py$', 423 r'^tools[\\\/]valgrind[\\\/].*\.py$',
399 r'^tools[\\\/]win[\\\/].*\.py$', 424 r'^tools[\\\/]win[\\\/].*\.py$',
400 r'^xcodebuild.*[\\\/].*\.py$',), 425 r'^xcodebuild.*[\\\/].*\.py$',),
401 disabled_warnings=['F0401', # Failed to import x 426 disabled_warnings=['F0401', # Failed to import x
402 'E0611', # No package y in x 427 'E0611', # No package y in x
403 'W0232', # Class has no __init__ method 428 'W0232', # Class has no __init__ method
404 ], 429 ],
405 pylintrc='pylintrc')) 430 pylintrc='pylintrc'))
431
406 # WebRTC can't use the presubmit_canned_checks.PanProjectChecks function since 432 # WebRTC can't use the presubmit_canned_checks.PanProjectChecks function since
407 # we need to have different license checks in talk/ and webrtc/ directories. 433 # we need to have different license checks in talk/ and webrtc/ directories.
408 # Instead, hand-picked checks are included below. 434 # Instead, hand-picked checks are included below.
409 435
410 # Skip long-lines check for DEPS, GN and GYP files. 436 # Skip long-lines check for DEPS, GN and GYP files.
411 long_lines_sources = lambda x: input_api.FilterSourceFile(x, 437 long_lines_sources = lambda x: input_api.FilterSourceFile(x,
412 black_list=(r'.+\.gyp$', r'.+\.gypi$', r'.+\.gn$', r'.+\.gni$', 'DEPS')) 438 black_list=(r'.+\.gyp$', r'.+\.gypi$', r'.+\.gn$', r'.+\.gni$', 'DEPS'))
413 results.extend(input_api.canned_checks.CheckLongLines( 439 results.extend(input_api.canned_checks.CheckLongLines(
414 input_api, output_api, maxlen=80, source_file_filter=long_lines_sources)) 440 input_api, output_api, maxlen=80, source_file_filter=long_lines_sources))
415 results.extend(input_api.canned_checks.CheckChangeHasNoTabs( 441 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
416 input_api, output_api)) 442 input_api, output_api))
417 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace( 443 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
418 input_api, output_api)) 444 input_api, output_api))
419 results.extend(input_api.canned_checks.CheckChangeTodoHasOwner( 445 results.extend(input_api.canned_checks.CheckChangeTodoHasOwner(
420 input_api, output_api)) 446 input_api, output_api))
421 results.extend(_CheckNativeApiHeaderChanges(input_api, output_api)) 447 results.extend(_CheckNativeApiHeaderChanges(input_api, output_api))
422 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) 448 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
423 results.extend(_CheckNoFRIEND_TEST(input_api, output_api)) 449 results.extend(_CheckNoFRIEND_TEST(input_api, output_api))
424 results.extend(_CheckGypChanges(input_api, output_api)) 450 results.extend(_CheckGypChanges(input_api, output_api))
425 results.extend(_CheckUnwantedDependencies(input_api, output_api)) 451 results.extend(_CheckUnwantedDependencies(input_api, output_api))
452 results.extend(_CheckJSONParseErrors(input_api, output_api))
426 results.extend(_RunPythonTests(input_api, output_api)) 453 results.extend(_RunPythonTests(input_api, output_api))
427 return results 454 return results
428 455
429 456
430 def CheckChangeOnUpload(input_api, output_api): 457 def CheckChangeOnUpload(input_api, output_api):
431 results = [] 458 results = []
432 results.extend(_CommonChecks(input_api, output_api)) 459 results.extend(_CommonChecks(input_api, output_api))
433 results.extend( 460 results.extend(
434 input_api.canned_checks.CheckGNFormatted(input_api, output_api)) 461 input_api.canned_checks.CheckGNFormatted(input_api, output_api))
435 return results 462 return results
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 for builder in masters[master]: 497 for builder in masters[master]:
471 if 'presubmit' in builder: 498 if 'presubmit' in builder:
472 # Do not trigger presubmit builders, since they're likely to fail 499 # Do not trigger presubmit builders, since they're likely to fail
473 # (e.g. OWNERS checks before finished code review), and we're running 500 # (e.g. OWNERS checks before finished code review), and we're running
474 # local presubmit anyway. 501 # local presubmit anyway.
475 pass 502 pass
476 else: 503 else:
477 try_config[master][builder] = ['defaulttests'] 504 try_config[master][builder] = ['defaulttests']
478 505
479 return try_config 506 return try_config
OLDNEW
« no previous file with comments | « no previous file | webrtc/build/ios/client.webrtc.fyi/iOS32_Simulator_Debug.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698