Factor out some SSL specific configs, and add another reference to /var/run to
[chromium-blink-merge.git] / PRESUBMIT.py
blob311cb203c616b1a67b161a28a055664b0619d720
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.
9 """
11 _EXCLUDED_PATHS = (
12 r"breakpad[\\\/].*",
13 r"net/tools/spdyshark/[\\\/].*",
14 r"skia[\\\/].*",
15 r"v8[\\\/].*",
18 _TEXT_FILES = (
19 r".*\.txt",
20 r".*\.json",
23 _LICENSE_HEADER = (
24 r".*? Copyright \(c\) 20[0-9\-]{2,7} The Chromium Authors\. All rights "
25 r"reserved\." "\n"
26 r".*? Use of this source code is governed by a BSD-style license that can "
27 "be\n"
28 r".*? found in the LICENSE file\."
29 "\n"
32 def _CheckSingletonInHeaders(input_api, output_api, source_file_filter):
33 """Checks to make sure no header files have |Singleton<|."""
34 pattern = input_api.re.compile(r'Singleton<')
35 files = []
36 for f in input_api.AffectedSourceFiles(source_file_filter):
37 if (f.LocalPath().endswith('.h') or f.LocalPath().endswith('.hxx') or
38 f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')):
39 contents = input_api.ReadFile(f)
40 if pattern.search(contents):
41 files.append(f)
43 if len(files):
44 return [ output_api.PresubmitError(
45 'Found Singleton<T> in the following header files.\n' +
46 'Please move them to an appropriate source file so that the ' +
47 'template gets instantiated in a single compilation unit.',
48 files) ]
49 return []
51 def _CheckConstNSObject(input_api, output_api, source_file_filter):
52 """Checks to make sure no objective-c files have |const NSSomeClass*|."""
53 pattern = input_api.re.compile(r'const\s+NS\w*\s*\*')
54 files = []
55 for f in input_api.AffectedSourceFiles(source_file_filter):
56 if f.LocalPath().endswith('.h') or f.LocalPath().endswith('.mm'):
57 contents = input_api.ReadFile(f)
58 if pattern.search(contents):
59 files.append(f)
61 if len(files):
62 if input_api.is_committing:
63 res_type = output_api.PresubmitPromptWarning
64 else:
65 res_type = output_api.PresubmitNotifyResult
66 return [ res_type('|const NSClass*| is wrong, see ' +
67 'http://dev.chromium.org/developers/clang-mac',
68 files) ]
69 return []
72 def _CommonChecks(input_api, output_api):
73 results = []
74 # What does this code do?
75 # It loads the default black list (e.g. third_party, experimental, etc) and
76 # add our black list (breakpad, skia and v8 are still not following
77 # google style and are not really living this repository).
78 # See presubmit_support.py InputApi.FilterSourceFile for the (simple) usage.
79 black_list = input_api.DEFAULT_BLACK_LIST + _EXCLUDED_PATHS
80 white_list = input_api.DEFAULT_WHITE_LIST + _TEXT_FILES
81 sources = lambda x: input_api.FilterSourceFile(x, black_list=black_list)
82 text_files = lambda x: input_api.FilterSourceFile(x, black_list=black_list,
83 white_list=white_list)
84 results.extend(input_api.canned_checks.CheckLongLines(
85 input_api, output_api, source_file_filter=sources))
86 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
87 input_api, output_api, source_file_filter=sources))
88 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
89 input_api, output_api, source_file_filter=sources))
90 results.extend(input_api.canned_checks.CheckChangeHasBugField(
91 input_api, output_api))
92 results.extend(input_api.canned_checks.CheckChangeHasTestField(
93 input_api, output_api))
94 results.extend(input_api.canned_checks.CheckChangeSvnEolStyle(
95 input_api, output_api, source_file_filter=text_files))
96 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes(
97 input_api, output_api))
98 results.extend(input_api.canned_checks.CheckLicense(
99 input_api, output_api, _LICENSE_HEADER, source_file_filter=sources))
100 results.extend(_CheckConstNSObject(
101 input_api, output_api, source_file_filter=sources))
102 results.extend(_CheckSingletonInHeaders(
103 input_api, output_api, source_file_filter=sources))
104 return results
107 def CheckChangeOnUpload(input_api, output_api):
108 results = []
109 results.extend(_CommonChecks(input_api, output_api))
110 return results
113 def CheckChangeOnCommit(input_api, output_api):
114 results = []
115 if not input_api.json:
116 results.append(output_api.PresubmitNotifyResult(
117 'You don\'t have json nor simplejson installed.\n'
118 ' This is a warning that you will need to upgrade your python '
119 'installation.\n'
120 ' This is no big deal but you\'ll eventually need to '
121 'upgrade.\n'
122 ' How? Easy! You can do it right now and shut me off! Just:\n'
123 ' del depot_tools\\python.bat\n'
124 ' gclient\n'
125 ' Thanks for your patience.'))
126 results.extend(_CommonChecks(input_api, output_api))
127 # TODO(thestig) temporarily disabled, doesn't work in third_party/
128 #results.extend(input_api.canned_checks.CheckSvnModifiedDirectories(
129 # input_api, output_api, sources))
130 # Make sure the tree is 'open'.
131 results.extend(input_api.canned_checks.CheckTreeIsOpen(
132 input_api,
133 output_api,
134 json_url='http://chromium-status.appspot.com/current?format=json'))
135 results.extend(input_api.canned_checks.CheckRietveldTryJobExecution(input_api,
136 output_api, 'http://codereview.chromium.org', ('win', 'linux', 'mac'),
137 'tryserver@chromium.org'))
139 # These builders are just too slow.
140 IGNORED_BUILDERS = [
141 'Chromium XP',
142 'Chromium Mac',
143 'Chromium Arm (dbg)',
144 'Chromium Linux',
145 'Chromium Linux x64',
147 results.extend(input_api.canned_checks.CheckBuildbotPendingBuilds(
148 input_api,
149 output_api,
150 'http://build.chromium.org/buildbot/waterfall/json/builders?filter=1',
152 IGNORED_BUILDERS))
153 return results
156 def GetPreferredTrySlaves():
157 return ['win', 'linux', 'mac']