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

Side by Side Diff: presubmit_canned_checks.py

Issue 2394043002: Remove SVN support from PRESUBMIT (Closed)
Patch Set: Updated patchset dependency Created 4 years, 2 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 | presubmit_support.py » ('j') | presubmit_support.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 """Generic presubmit checks that can be reused by other presubmit checks.""" 5 """Generic presubmit checks that can be reused by other presubmit checks."""
6 6
7 import os as _os 7 import os as _os
8 _HERE = _os.path.dirname(_os.path.abspath(__file__)) 8 _HERE = _os.path.dirname(_os.path.abspath(__file__))
9 9
10 # Justifications for each filter: 10 # Justifications for each filter:
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 continue 413 continue
414 if not license_re.search(contents): 414 if not license_re.search(contents):
415 bad_files.append(f.LocalPath()) 415 bad_files.append(f.LocalPath())
416 if bad_files: 416 if bad_files:
417 return [output_api.PresubmitPromptWarning( 417 return [output_api.PresubmitPromptWarning(
418 'License must match:\n%s\n' % license_re.pattern + 418 'License must match:\n%s\n' % license_re.pattern +
419 'Found a bad license header in these files:', items=bad_files)] 419 'Found a bad license header in these files:', items=bad_files)]
420 return [] 420 return []
421 421
422 422
423 def CheckChangeSvnEolStyle(input_api, output_api, source_file_filter=None):
424 """Checks that the source files have svn:eol-style=LF."""
425 return CheckSvnProperty(input_api, output_api,
426 'svn:eol-style', 'LF',
427 input_api.AffectedSourceFiles(source_file_filter))
428
429
430 def CheckSvnForCommonMimeTypes(input_api, output_api):
431 """Checks that common binary file types have the correct svn:mime-type."""
432 output = []
433 files = input_api.AffectedFiles(include_deletes=False)
434 def IsExts(x, exts):
435 path = x.LocalPath()
436 for extension in exts:
437 if path.endswith(extension):
438 return True
439 return False
440 def FilterFiles(extension):
441 return filter(lambda x: IsExts(x, extension), files)
442 def RunCheck(mime_type, files):
443 output.extend(CheckSvnProperty(input_api, output_api, 'svn:mime-type',
444 mime_type, files))
445 RunCheck('application/pdf', FilterFiles(['.pdf']))
446 RunCheck('image/bmp', FilterFiles(['.bmp']))
447 RunCheck('image/gif', FilterFiles(['.gif']))
448 RunCheck('image/png', FilterFiles(['.png']))
449 RunCheck('image/jpeg', FilterFiles(['.jpg', '.jpeg', '.jpe']))
450 RunCheck('image/vnd.microsoft.icon', FilterFiles(['.ico']))
451 return output
452
453
454 def CheckSvnProperty(input_api, output_api, prop, expected, affected_files):
455 """Checks that affected_files files have prop=expected."""
456 if input_api.change.scm != 'svn':
457 return []
458
459 bad = filter(lambda f: f.Property(prop) != expected, affected_files)
460 if bad:
461 if input_api.is_committing:
462 res_type = output_api.PresubmitError
463 else:
464 res_type = output_api.PresubmitNotifyResult
465 message = 'Run the command: svn pset %s %s \\' % (prop, expected)
466 return [res_type(message, items=bad)]
467 return []
468
469
470 ### Other checks 423 ### Other checks
471 424
472 def CheckDoNotSubmit(input_api, output_api): 425 def CheckDoNotSubmit(input_api, output_api):
473 return ( 426 return (
474 CheckDoNotSubmitInDescription(input_api, output_api) + 427 CheckDoNotSubmitInDescription(input_api, output_api) +
475 CheckDoNotSubmitInFiles(input_api, output_api) 428 CheckDoNotSubmitInFiles(input_api, output_api)
476 ) 429 )
477 430
478 431
479 def CheckTreeIsOpen(input_api, output_api, 432 def CheckTreeIsOpen(input_api, output_api,
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 input_api, output_api, maxlen, source_file_filter=sources)) 1070 input_api, output_api, maxlen, source_file_filter=sources))
1118 snapshot( "checking tabs") 1071 snapshot( "checking tabs")
1119 results.extend(input_api.canned_checks.CheckChangeHasNoTabs( 1072 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
1120 input_api, output_api, source_file_filter=sources)) 1073 input_api, output_api, source_file_filter=sources))
1121 snapshot( "checking stray whitespace") 1074 snapshot( "checking stray whitespace")
1122 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace( 1075 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
1123 input_api, output_api, source_file_filter=sources)) 1076 input_api, output_api, source_file_filter=sources))
1124 snapshot("checking nsobjects") 1077 snapshot("checking nsobjects")
1125 results.extend(_CheckConstNSObject( 1078 results.extend(_CheckConstNSObject(
1126 input_api, output_api, source_file_filter=sources)) 1079 input_api, output_api, source_file_filter=sources))
1127 snapshot("checking eol style")
1128 results.extend(input_api.canned_checks.CheckChangeSvnEolStyle(
1129 input_api, output_api, source_file_filter=text_files))
1130 snapshot("checking license") 1080 snapshot("checking license")
1131 results.extend(input_api.canned_checks.CheckLicense( 1081 results.extend(input_api.canned_checks.CheckLicense(
1132 input_api, output_api, license_header, source_file_filter=sources)) 1082 input_api, output_api, license_header, source_file_filter=sources))
1133 1083
1134 if input_api.is_committing: 1084 if input_api.is_committing:
1135 snapshot("checking svn mime types")
1136 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes(
1137 input_api, output_api))
1138 snapshot("checking was uploaded") 1085 snapshot("checking was uploaded")
1139 results.extend(input_api.canned_checks.CheckChangeWasUploaded( 1086 results.extend(input_api.canned_checks.CheckChangeWasUploaded(
1140 input_api, output_api)) 1087 input_api, output_api))
1141 snapshot("checking description") 1088 snapshot("checking description")
1142 results.extend(input_api.canned_checks.CheckChangeHasDescription( 1089 results.extend(input_api.canned_checks.CheckChangeHasDescription(
1143 input_api, output_api)) 1090 input_api, output_api))
1144 results.extend(input_api.canned_checks.CheckDoNotSubmitInDescription( 1091 results.extend(input_api.canned_checks.CheckDoNotSubmitInDescription(
1145 input_api, output_api)) 1092 input_api, output_api))
1146 snapshot("checking do not submit in files") 1093 snapshot("checking do not submit in files")
1147 results.extend(input_api.canned_checks.CheckDoNotSubmitInFiles( 1094 results.extend(input_api.canned_checks.CheckDoNotSubmitInFiles(
(...skipping 30 matching lines...) Expand all
1178 for f in affected_files: 1125 for f in affected_files:
1179 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] 1126 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()]
1180 rc = gn.main(cmd) 1127 rc = gn.main(cmd)
1181 if rc == 2: 1128 if rc == 2:
1182 warnings.append(output_api.PresubmitPromptWarning( 1129 warnings.append(output_api.PresubmitPromptWarning(
1183 '%s requires formatting. Please run:\n gn format %s' % ( 1130 '%s requires formatting. Please run:\n gn format %s' % (
1184 f.AbsoluteLocalPath(), f.LocalPath()))) 1131 f.AbsoluteLocalPath(), f.LocalPath())))
1185 # It's just a warning, so ignore other types of failures assuming they'll be 1132 # It's just a warning, so ignore other types of failures assuming they'll be
1186 # caught elsewhere. 1133 # caught elsewhere.
1187 return warnings 1134 return warnings
OLDNEW
« no previous file with comments | « no previous file | presubmit_support.py » ('j') | presubmit_support.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698