1 # Copyright (c) 2010 The Chromium Authors. 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.
5 """Top-level presubmit script for Chromium.
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into gcl.
13 r
"net/tools/spdyshark/[\\\/].*",
24 r
".*? Copyright \(c\) 20[0-9\-]{2,7} The Chromium Authors\. All rights "
26 r
".*? Use of this source code is governed by a BSD-style license that can "
28 r
".*? found in the LICENSE file\."
33 def _CheckConstNSObject(input_api
, output_api
, source_file_filter
):
34 """Checks to make sure no objective-c files have |const NSSomeClass*|."""
35 pattern
= input_api
.re
.compile(r
'const\s+NS\w*\s*\*')
37 for f
in input_api
.AffectedSourceFiles(source_file_filter
):
38 if f
.LocalPath().endswith('.h') or f
.LocalPath().endswith('.mm'):
39 contents
= input_api
.ReadFile(f
)
40 if pattern
.search(contents
):
44 if input_api
.is_committing
:
45 res_type
= output_api
.PresubmitPromptWarning
47 res_type
= output_api
.PresubmitNotifyResult
48 return [ res_type('|const NSClass*| is wrong, see ' +
49 'http://dev.chromium.org/developers/clang-mac',
54 def _CommonChecks(input_api
, output_api
):
56 # What does this code do?
57 # It loads the default black list (e.g. third_party, experimental, etc) and
58 # add our black list (breakpad, skia and v8 are still not following
59 # google style and are not really living this repository).
60 # See presubmit_support.py InputApi.FilterSourceFile for the (simple) usage.
61 black_list
= input_api
.DEFAULT_BLACK_LIST
+ _EXCLUDED_PATHS
62 white_list
= input_api
.DEFAULT_WHITE_LIST
+ _TEXT_FILES
63 sources
= lambda x
: input_api
.FilterSourceFile(x
, black_list
=black_list
)
64 text_files
= lambda x
: input_api
.FilterSourceFile(x
, black_list
=black_list
,
65 white_list
=white_list
)
66 results
.extend(input_api
.canned_checks
.CheckLongLines(
67 input_api
, output_api
, source_file_filter
=sources
))
68 results
.extend(input_api
.canned_checks
.CheckChangeHasNoTabs(
69 input_api
, output_api
, source_file_filter
=sources
))
70 results
.extend(input_api
.canned_checks
.CheckChangeHasNoStrayWhitespace(
71 input_api
, output_api
, source_file_filter
=sources
))
72 results
.extend(input_api
.canned_checks
.CheckChangeHasBugField(
73 input_api
, output_api
))
74 results
.extend(input_api
.canned_checks
.CheckChangeHasTestField(
75 input_api
, output_api
))
76 results
.extend(input_api
.canned_checks
.CheckChangeSvnEolStyle(
77 input_api
, output_api
, source_file_filter
=text_files
))
78 results
.extend(input_api
.canned_checks
.CheckSvnForCommonMimeTypes(
79 input_api
, output_api
))
80 results
.extend(input_api
.canned_checks
.CheckLicense(
81 input_api
, output_api
, _LICENSE_HEADER
, source_file_filter
=sources
))
82 results
.extend(_CheckConstNSObject(
83 input_api
, output_api
, source_file_filter
=sources
))
87 def CheckChangeOnUpload(input_api
, output_api
):
89 results
.extend(_CommonChecks(input_api
, output_api
))
93 def CheckChangeOnCommit(input_api
, output_api
):
95 if not input_api
.json
:
96 results
.append(output_api
.PresubmitNotifyResult(
97 'You don\'t have json nor simplejson installed.\n'
98 ' This is a warning that you will need to upgrade your python '
100 ' This is no big deal but you\'ll eventually need to '
102 ' How? Easy! You can do it right now and shut me off! Just:\n'
103 ' del depot_tools\\python.bat\n'
105 ' Thanks for your patience.'))
106 results
.extend(_CommonChecks(input_api
, output_api
))
107 # TODO(thestig) temporarily disabled, doesn't work in third_party/
108 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
109 # input_api, output_api, sources))
110 # Make sure the tree is 'open'.
111 results
.extend(input_api
.canned_checks
.CheckTreeIsOpen(
114 'http://chromium-status.appspot.com/current?format=raw',
116 results
.extend(input_api
.canned_checks
.CheckRietveldTryJobExecution(input_api
,
117 output_api
, 'http://codereview.chromium.org', ('win', 'linux', 'mac'),
118 'tryserver@chromium.org'))
120 # These builders are just too slow.
124 'Chromium Arm (dbg)',
126 'Chromium Linux x64',
128 results
.extend(input_api
.canned_checks
.CheckBuildbotPendingBuilds(
131 'http://build.chromium.org/buildbot/waterfall/json/builders?filter=1',
137 def GetPreferredTrySlaves():
138 return ['win', 'linux', 'mac']