PRESUBMIT.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # Copyright (c) 2012 Google Inc. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. """Top-level presubmit script for GYP.
  5. See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
  6. for more details about the presubmit API built into gcl.
  7. """
  8. PYLINT_BLACKLIST = [
  9. # TODO: fix me.
  10. # From SCons, not done in google style.
  11. 'test/lib/TestCmd.py',
  12. 'test/lib/TestCommon.py',
  13. 'test/lib/TestGyp.py',
  14. # Needs style fix.
  15. 'pylib/gyp/generator/xcode.py',
  16. ]
  17. PYLINT_DISABLED_WARNINGS = [
  18. # TODO: fix me.
  19. # Many tests include modules they don't use.
  20. 'W0611',
  21. # Include order doesn't properly include local files?
  22. 'F0401',
  23. # Some use of built-in names.
  24. 'W0622',
  25. # Some unused variables.
  26. 'W0612',
  27. # Operator not preceded/followed by space.
  28. 'C0323',
  29. 'C0322',
  30. # Unnecessary semicolon.
  31. 'W0301',
  32. # Unused argument.
  33. 'W0613',
  34. # String has no effect (docstring in wrong place).
  35. 'W0105',
  36. # Comma not followed by space.
  37. 'C0324',
  38. # Access to a protected member.
  39. 'W0212',
  40. # Bad indent.
  41. 'W0311',
  42. # Line too long.
  43. 'C0301',
  44. # Undefined variable.
  45. 'E0602',
  46. # Not exception type specified.
  47. 'W0702',
  48. # No member of that name.
  49. 'E1101',
  50. # Dangerous default {}.
  51. 'W0102',
  52. # Others, too many to sort.
  53. 'W0201', 'W0232', 'E1103', 'W0621', 'W0108', 'W0223', 'W0231',
  54. 'R0201', 'E0101', 'C0321',
  55. # ************* Module copy
  56. # W0104:427,12:_test.odict.__setitem__: Statement seems to have no effect
  57. 'W0104',
  58. ]
  59. def CheckChangeOnUpload(input_api, output_api):
  60. report = []
  61. report.extend(input_api.canned_checks.PanProjectChecks(
  62. input_api, output_api))
  63. return report
  64. def CheckChangeOnCommit(input_api, output_api):
  65. report = []
  66. # Accept any year number from 2009 to the current year.
  67. current_year = int(input_api.time.strftime('%Y'))
  68. allowed_years = (str(s) for s in reversed(xrange(2009, current_year + 1)))
  69. years_re = '(' + '|'.join(allowed_years) + ')'
  70. # The (c) is deprecated, but tolerate it until it's removed from all files.
  71. license = (
  72. r'.*? Copyright (\(c\) )?%(year)s Google Inc\. All rights reserved\.\n'
  73. r'.*? Use of this source code is governed by a BSD-style license that '
  74. r'can be\n'
  75. r'.*? found in the LICENSE file\.\n'
  76. ) % {
  77. 'year': years_re,
  78. }
  79. report.extend(input_api.canned_checks.PanProjectChecks(
  80. input_api, output_api, license_header=license))
  81. report.extend(input_api.canned_checks.CheckTreeIsOpen(
  82. input_api, output_api,
  83. 'http://gyp-status.appspot.com/status',
  84. 'http://gyp-status.appspot.com/current'))
  85. import os
  86. import sys
  87. old_sys_path = sys.path
  88. try:
  89. sys.path = ['pylib', 'test/lib'] + sys.path
  90. blacklist = PYLINT_BLACKLIST
  91. if sys.platform == 'win32':
  92. blacklist = [os.path.normpath(x).replace('\\', '\\\\')
  93. for x in PYLINT_BLACKLIST]
  94. report.extend(input_api.canned_checks.RunPylint(
  95. input_api,
  96. output_api,
  97. black_list=blacklist,
  98. disabled_warnings=PYLINT_DISABLED_WARNINGS))
  99. finally:
  100. sys.path = old_sys_path
  101. return report
  102. def GetPreferredTrySlaves():
  103. return ['gyp-win32', 'gyp-win64', 'gyp-linux', 'gyp-mac', 'gyp-android']