blob: 77ea6fe7311ee8f2ef0de40f51f4b2793a1b6be6 [file] [log] [blame]
Mandeep Singh Baines116ad102011-04-27 15:16:37 -07001# Copyright (c) 2011 The Chromium OS 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.
4
Ryan Cui9b651632011-05-11 11:38:58 -07005import ConfigParser
Dale Curtis2975c432011-05-03 17:25:20 -07006import json
Mandeep Singh Baines116ad102011-04-27 15:16:37 -07007import os
Ryan Cuiec4d6332011-05-02 14:15:25 -07008import re
Mandeep Singh Bainesa7ffa4b2011-05-03 11:37:02 -07009import sys
Mandeep Singh Baines116ad102011-04-27 15:16:37 -070010import subprocess
11
Ryan Cui1562fb82011-05-09 11:01:31 -070012from errors import (VerifyException, HookFailure, PrintErrorForProject,
13 PrintErrorsForCommit)
Ryan Cuiec4d6332011-05-02 14:15:25 -070014
Ryan Cuiec4d6332011-05-02 14:15:25 -070015
16COMMON_INCLUDED_PATHS = [
17 # C++ and friends
18 r".*\.c$", r".*\.cc$", r".*\.cpp$", r".*\.h$", r".*\.m$", r".*\.mm$",
19 r".*\.inl$", r".*\.asm$", r".*\.hxx$", r".*\.hpp$", r".*\.s$", r".*\.S$",
20 # Scripts
21 r".*\.js$", r".*\.py$", r".*\.sh$", r".*\.rb$", r".*\.pl$", r".*\.pm$",
22 # No extension at all, note that ALL CAPS files are black listed in
23 # COMMON_EXCLUDED_LIST below.
24 r"(^|.*?[\\\/])[^.]+$",
25 # Other
26 r".*\.java$", r".*\.mk$", r".*\.am$",
27]
28
Ryan Cui1562fb82011-05-09 11:01:31 -070029
Ryan Cuiec4d6332011-05-02 14:15:25 -070030COMMON_EXCLUDED_PATHS = [
Ryan Cui31e0c172011-05-04 21:00:45 -070031 # avoid doing source file checks for kernel
32 r"/src/third_party/kernel/",
33 r"/src/third_party/kernel-next/",
Paul Taysomf8b6e012011-05-09 14:32:42 -070034 r"/src/third_party/ktop/",
35 r"/src/third_party/punybench/",
Ryan Cuiec4d6332011-05-02 14:15:25 -070036 r".*\bexperimental[\\\/].*",
37 r".*\b[A-Z0-9_]{2,}$",
38 r".*[\\\/]debian[\\\/]rules$",
Brian Harringd780d602011-10-18 16:48:08 -070039 # for ebuild trees, ignore any caches and manifest data
40 r".*/Manifest$",
41 r".*/metadata/[^/]*cache[^/]*/[^/]+/[^/]+$",
Doug Anderson5bfb6792011-10-25 16:45:41 -070042
43 # ignore profiles data (like overlay-tegra2/profiles)
44 r".*/overlay-.*/profiles/.*",
Ryan Cuiec4d6332011-05-02 14:15:25 -070045]
Mandeep Singh Baines116ad102011-04-27 15:16:37 -070046
Ryan Cui1562fb82011-05-09 11:01:31 -070047
Ryan Cui9b651632011-05-11 11:38:58 -070048_CONFIG_FILE = 'PRESUBMIT.cfg'
49
50
Ryan Cui1562fb82011-05-09 11:01:31 -070051# General Helpers
52
Sean Paulba01d402011-05-05 11:36:23 -040053
Ryan Cui72834d12011-05-05 14:51:33 -070054def _run_command(cmd):
55 """Executes the passed in command and returns raw stdout output."""
56 return subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
57
Ryan Cui1562fb82011-05-09 11:01:31 -070058
Mandeep Singh Baines116ad102011-04-27 15:16:37 -070059def _get_hooks_dir():
Ryan Cuiec4d6332011-05-02 14:15:25 -070060 """Returns the absolute path to the repohooks directory."""
Mandeep Singh Baines116ad102011-04-27 15:16:37 -070061 cmd = ['repo', 'forall', 'chromiumos/repohooks', '-c', 'pwd']
Ryan Cui72834d12011-05-05 14:51:33 -070062 return _run_command(cmd).strip()
Mandeep Singh Baines116ad102011-04-27 15:16:37 -070063
Ryan Cui1562fb82011-05-09 11:01:31 -070064
Ryan Cuiec4d6332011-05-02 14:15:25 -070065def _match_regex_list(subject, expressions):
66 """Try to match a list of regular expressions to a string.
67
68 Args:
69 subject: The string to match regexes on
70 expressions: A list of regular expressions to check for matches with.
71
72 Returns:
73 Whether the passed in subject matches any of the passed in regexes.
74 """
75 for expr in expressions:
76 if (re.search(expr, subject)):
77 return True
78 return False
79
Ryan Cui1562fb82011-05-09 11:01:31 -070080
Ryan Cuiec4d6332011-05-02 14:15:25 -070081def _filter_files(files, include_list, exclude_list=[]):
82 """Filter out files based on the conditions passed in.
83
84 Args:
85 files: list of filepaths to filter
86 include_list: list of regex that when matched with a file path will cause it
87 to be added to the output list unless the file is also matched with a
88 regex in the exclude_list.
89 exclude_list: list of regex that when matched with a file will prevent it
90 from being added to the output list, even if it is also matched with a
91 regex in the include_list.
92
93 Returns:
94 A list of filepaths that contain files matched in the include_list and not
95 in the exclude_list.
96 """
97 filtered = []
98 for f in files:
99 if (_match_regex_list(f, include_list) and
100 not _match_regex_list(f, exclude_list)):
101 filtered.append(f)
102 return filtered
103
Ryan Cuiec4d6332011-05-02 14:15:25 -0700104
105# Git Helpers
Ryan Cui1562fb82011-05-09 11:01:31 -0700106
107
Ryan Cui4725d952011-05-05 15:41:19 -0700108def _get_upstream_branch():
109 """Returns the upstream tracking branch of the current branch.
110
111 Raises:
112 Error if there is no tracking branch
113 """
114 current_branch = _run_command(['git', 'symbolic-ref', 'HEAD']).strip()
115 current_branch = current_branch.replace('refs/heads/', '')
116 if not current_branch:
Ryan Cui1562fb82011-05-09 11:01:31 -0700117 raise VerifyException('Need to be on a tracking branch')
Ryan Cui4725d952011-05-05 15:41:19 -0700118
119 cfg_option = 'branch.' + current_branch + '.%s'
120 full_upstream = _run_command(['git', 'config', cfg_option % 'merge']).strip()
121 remote = _run_command(['git', 'config', cfg_option % 'remote']).strip()
122 if not remote or not full_upstream:
Ryan Cui1562fb82011-05-09 11:01:31 -0700123 raise VerifyException('Need to be on a tracking branch')
Ryan Cui4725d952011-05-05 15:41:19 -0700124
125 return full_upstream.replace('heads', 'remotes/' + remote)
126
Ryan Cui1562fb82011-05-09 11:01:31 -0700127
Mandeep Singh Bainesb9ed1402011-04-29 15:32:06 -0700128def _get_diff(commit):
Ryan Cuiec4d6332011-05-02 14:15:25 -0700129 """Returns the diff for this commit."""
Ryan Cui72834d12011-05-05 14:51:33 -0700130 return _run_command(['git', 'show', commit])
Mandeep Singh Baines116ad102011-04-27 15:16:37 -0700131
Ryan Cui1562fb82011-05-09 11:01:31 -0700132
Ryan Cuiec4d6332011-05-02 14:15:25 -0700133def _get_file_diff(file, commit):
134 """Returns a list of (linenum, lines) tuples that the commit touched."""
Ryan Cui72834d12011-05-05 14:51:33 -0700135 output = _run_command(['git', 'show', '-p', '--no-ext-diff', commit, file])
Ryan Cuiec4d6332011-05-02 14:15:25 -0700136
137 new_lines = []
138 line_num = 0
139 for line in output.splitlines():
140 m = re.match(r'^@@ [0-9\,\+\-]+ \+([0-9]+)\,[0-9]+ @@', line)
141 if m:
142 line_num = int(m.groups(1)[0])
143 continue
144 if line.startswith('+') and not line.startswith('++'):
145 new_lines.append((line_num, line[1:]))
146 if not line.startswith('-'):
147 line_num += 1
148 return new_lines
149
Ryan Cui1562fb82011-05-09 11:01:31 -0700150
Ryan Cuiec4d6332011-05-02 14:15:25 -0700151def _get_affected_files(commit):
152 """Returns list of absolute filepaths that were modified/added."""
Ryan Cui72834d12011-05-05 14:51:33 -0700153 output = _run_command(['git', 'diff', '--name-status', commit + '^!'])
Ryan Cuiec4d6332011-05-02 14:15:25 -0700154 files = []
155 for statusline in output.splitlines():
156 m = re.match('^(\w)+\t(.+)$', statusline.rstrip())
157 # Ignore deleted files, and return absolute paths of files
158 if (m.group(1)[0] != 'D'):
159 pwd = os.getcwd()
160 files.append(os.path.join(pwd, m.group(2)))
161 return files
162
Ryan Cui1562fb82011-05-09 11:01:31 -0700163
Mandeep Singh Bainesb9ed1402011-04-29 15:32:06 -0700164def _get_commits():
Ryan Cuiec4d6332011-05-02 14:15:25 -0700165 """Returns a list of commits for this review."""
Ryan Cui4725d952011-05-05 15:41:19 -0700166 cmd = ['git', 'log', '%s..' % _get_upstream_branch(), '--format=%H']
Ryan Cui72834d12011-05-05 14:51:33 -0700167 return _run_command(cmd).split()
Mandeep Singh Bainesb9ed1402011-04-29 15:32:06 -0700168
Ryan Cui1562fb82011-05-09 11:01:31 -0700169
Ryan Cuiec4d6332011-05-02 14:15:25 -0700170def _get_commit_desc(commit):
171 """Returns the full commit message of a commit."""
Sean Paul23a2c582011-05-06 13:10:44 -0400172 return _run_command(['git', 'log', '--format=%s%n%n%b', commit + '^!'])
Ryan Cuiec4d6332011-05-02 14:15:25 -0700173
174
175# Common Hooks
176
Ryan Cui1562fb82011-05-09 11:01:31 -0700177
Ryan Cuiec4d6332011-05-02 14:15:25 -0700178def _check_no_long_lines(project, commit):
179 """Checks that there aren't any lines longer than maxlen characters in any of
180 the text files to be submitted.
181 """
182 MAX_LEN = 80
183
184 errors = []
185 files = _filter_files(_get_affected_files(commit),
186 COMMON_INCLUDED_PATHS,
187 COMMON_EXCLUDED_PATHS)
188
189 for afile in files:
190 for line_num, line in _get_file_diff(afile, commit):
191 # Allow certain lines to exceed the maxlen rule.
192 if (len(line) > MAX_LEN and
193 not 'http://' in line and
194 not 'https://' in line and
195 not line.startswith('#define') and
196 not line.startswith('#include') and
197 not line.startswith('#import') and
198 not line.startswith('#pragma') and
199 not line.startswith('#if') and
200 not line.startswith('#endif')):
201 errors.append('%s, line %s, %s chars' % (afile, line_num, len(line)))
202 if len(errors) == 5: # Just show the first 5 errors.
203 break
204
205 if errors:
206 msg = 'Found lines longer than %s characters (first 5 shown):' % MAX_LEN
Ryan Cui1562fb82011-05-09 11:01:31 -0700207 return HookFailure(msg, errors)
208
Ryan Cuiec4d6332011-05-02 14:15:25 -0700209
210def _check_no_stray_whitespace(project, commit):
211 """Checks that there is no stray whitespace at source lines end."""
212 errors = []
213 files = _filter_files(_get_affected_files(commit),
214 COMMON_INCLUDED_PATHS,
215 COMMON_EXCLUDED_PATHS)
216
217 for afile in files:
218 for line_num, line in _get_file_diff(afile, commit):
219 if line.rstrip() != line:
220 errors.append('%s, line %s' % (afile, line_num))
221 if errors:
Ryan Cui1562fb82011-05-09 11:01:31 -0700222 return HookFailure('Found line ending with white space in:', errors)
223
Ryan Cuiec4d6332011-05-02 14:15:25 -0700224
225def _check_no_tabs(project, commit):
226 """Checks there are no unexpanded tabs."""
227 TAB_OK_PATHS = [
Ryan Cui31e0c172011-05-04 21:00:45 -0700228 r"/src/third_party/u-boot/",
Ryan Cuiec4d6332011-05-02 14:15:25 -0700229 r".*\.ebuild$",
230 r".*\.eclass$",
231 r".*/[M|m]akefile$"
232 ]
233
234 errors = []
235 files = _filter_files(_get_affected_files(commit),
236 COMMON_INCLUDED_PATHS,
237 COMMON_EXCLUDED_PATHS + TAB_OK_PATHS)
238
239 for afile in files:
240 for line_num, line in _get_file_diff(afile, commit):
241 if '\t' in line:
242 errors.append('%s, line %s' % (afile, line_num))
243 if errors:
Ryan Cui1562fb82011-05-09 11:01:31 -0700244 return HookFailure('Found a tab character in:', errors)
245
Ryan Cuiec4d6332011-05-02 14:15:25 -0700246
247def _check_change_has_test_field(project, commit):
248 """Check for a non-empty 'TEST=' field in the commit message."""
David McMahon8f6553e2011-06-10 15:46:36 -0700249 TEST_RE = r'\nTEST=\S+'
Ryan Cuiec4d6332011-05-02 14:15:25 -0700250
Mandeep Singh Baines96a53be2011-05-03 11:10:25 -0700251 if not re.search(TEST_RE, _get_commit_desc(commit)):
Ryan Cui1562fb82011-05-09 11:01:31 -0700252 msg = 'Changelist description needs TEST field (after first line)'
253 return HookFailure(msg)
254
Ryan Cuiec4d6332011-05-02 14:15:25 -0700255
256def _check_change_has_bug_field(project, commit):
David McMahon8f6553e2011-06-10 15:46:36 -0700257 """Check for a correctly formatted 'BUG=' field in the commit message."""
258 BUG_RE = r'\nBUG=([Nn]one|(chrome-os-partner|chromium-os):\d+)'
Ryan Cuiec4d6332011-05-02 14:15:25 -0700259
Mandeep Singh Baines96a53be2011-05-03 11:10:25 -0700260 if not re.search(BUG_RE, _get_commit_desc(commit)):
David McMahon8f6553e2011-06-10 15:46:36 -0700261 msg = ('Changelist description needs BUG field (after first line):\n'
262 'BUG=chromium-os:99999 (for public tracker)\n'
263 'BUG=chrome-os-partner:9999 (for partner tracker)\n'
264 'BUG=None')
Ryan Cui1562fb82011-05-09 11:01:31 -0700265 return HookFailure(msg)
266
Ryan Cuiec4d6332011-05-02 14:15:25 -0700267
Mandeep Singh Bainesa23eb5f2011-05-04 13:43:25 -0700268def _check_change_has_proper_changeid(project, commit):
269 """Verify that Change-ID is present in last paragraph of commit message."""
270 desc = _get_commit_desc(commit)
271 loc = desc.rfind('\nChange-Id:')
272 if loc == -1 or re.search('\n\s*\n\s*\S+', desc[loc:]):
Ryan Cui1562fb82011-05-09 11:01:31 -0700273 return HookFailure('Change-Id must be in last paragraph of description.')
274
Mandeep Singh Bainesa23eb5f2011-05-04 13:43:25 -0700275
Ryan Cuiec4d6332011-05-02 14:15:25 -0700276def _check_license(project, commit):
277 """Verifies the license header."""
278 LICENSE_HEADER = (
279 r".*? Copyright \(c\) 20[-0-9]{2,7} The Chromium OS Authors\. All rights "
280 r"reserved\." "\n"
281 r".*? Use of this source code is governed by a BSD-style license that can "
282 "be\n"
283 r".*? found in the LICENSE file\."
284 "\n"
285 )
286
287 license_re = re.compile(LICENSE_HEADER, re.MULTILINE)
288 bad_files = []
289 files = _filter_files(_get_affected_files(commit),
290 COMMON_INCLUDED_PATHS,
291 COMMON_EXCLUDED_PATHS)
292
293 for f in files:
294 contents = open(f).read()
295 if len(contents) == 0: continue # Ignore empty files
296 if not license_re.search(contents):
297 bad_files.append(f)
298 if bad_files:
Ryan Cui1562fb82011-05-09 11:01:31 -0700299 return HookFailure('License must match:\n%s\n' % license_re.pattern +
300 'Found a bad license header in these files:',
301 bad_files)
Ryan Cuiec4d6332011-05-02 14:15:25 -0700302
303
304# Project-specific hooks
Mandeep Singh Baines116ad102011-04-27 15:16:37 -0700305
Ryan Cui1562fb82011-05-09 11:01:31 -0700306
Anton Staaf815d6852011-08-22 10:08:45 -0700307def _run_checkpatch(project, commit, options=[]):
Mandeep Singh Baines116ad102011-04-27 15:16:37 -0700308 """Runs checkpatch.pl on the given project"""
309 hooks_dir = _get_hooks_dir()
Anton Staaf815d6852011-08-22 10:08:45 -0700310 cmd = ['%s/checkpatch.pl' % hooks_dir] + options + ['-']
Mandeep Singh Baines116ad102011-04-27 15:16:37 -0700311 p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
Mandeep Singh Bainesb9ed1402011-04-29 15:32:06 -0700312 output = p.communicate(_get_diff(commit))[0]
Mandeep Singh Baines116ad102011-04-27 15:16:37 -0700313 if p.returncode:
Ryan Cui1562fb82011-05-09 11:01:31 -0700314 return HookFailure('checkpatch.pl errors/warnings\n\n' + output)
Ryan Cuiec4d6332011-05-02 14:15:25 -0700315
Mandeep Singh Baines116ad102011-04-27 15:16:37 -0700316
Anton Staaf815d6852011-08-22 10:08:45 -0700317def _run_checkpatch_no_tree(project, commit):
318 return _run_checkpatch(project, commit, ['--no-tree'])
319
320
Dale Curtis2975c432011-05-03 17:25:20 -0700321def _run_json_check(project, commit):
322 """Checks that all JSON files are syntactically valid."""
Dale Curtisa039cfd2011-05-04 12:01:05 -0700323 for f in _filter_files(_get_affected_files(commit), [r'.*\.json']):
Dale Curtis2975c432011-05-03 17:25:20 -0700324 try:
325 json.load(open(f))
326 except Exception, e:
Ryan Cui1562fb82011-05-09 11:01:31 -0700327 return HookFailure('Invalid JSON in %s: %s' % (f, e))
Dale Curtis2975c432011-05-03 17:25:20 -0700328
329
Mandeep Singh Baines116ad102011-04-27 15:16:37 -0700330# Base
331
Ryan Cui1562fb82011-05-09 11:01:31 -0700332
Ryan Cui9b651632011-05-11 11:38:58 -0700333# A list of hooks that are not project-specific
334_COMMON_HOOKS = [
335 _check_change_has_bug_field,
336 _check_change_has_test_field,
337 _check_change_has_proper_changeid,
338 _check_no_stray_whitespace,
339 _check_no_long_lines,
340 _check_license,
341 _check_no_tabs,
342]
Ryan Cuiec4d6332011-05-02 14:15:25 -0700343
Ryan Cui1562fb82011-05-09 11:01:31 -0700344
Ryan Cui9b651632011-05-11 11:38:58 -0700345# A dictionary of project-specific hooks(callbacks), indexed by project name.
346# dict[project] = [callback1, callback2]
347_PROJECT_SPECIFIC_HOOKS = {
Doug Anderson830216f2011-05-02 10:08:37 -0700348 "chromiumos/third_party/kernel": [_run_checkpatch],
349 "chromiumos/third_party/kernel-next": [_run_checkpatch],
Anton Staaf815d6852011-08-22 10:08:45 -0700350 "chromiumos/third_party/u-boot": [_run_checkpatch_no_tree],
Che-Liang Chiou1eb0ab62011-10-20 16:14:38 +0800351 "chromiumos/platform/u-boot-vboot-integration": [_run_checkpatch_no_tree],
Dale Curtis2975c432011-05-03 17:25:20 -0700352 "chromeos/autotest-tools": [_run_json_check],
Ryan Cui9b651632011-05-11 11:38:58 -0700353}
Mandeep Singh Baines116ad102011-04-27 15:16:37 -0700354
Ryan Cui1562fb82011-05-09 11:01:31 -0700355
Ryan Cui9b651632011-05-11 11:38:58 -0700356# A dictionary of flags (keys) that can appear in the config file, and the hook
357# that the flag disables (value)
358_DISABLE_FLAGS = {
359 'stray_whitespace_check': _check_no_stray_whitespace,
360 'long_line_check': _check_no_long_lines,
361 'cros_license_check': _check_license,
362 'tab_check': _check_no_tabs,
363}
364
365
366def _get_disabled_hooks():
367 """Returns a set of hooks disabled by the current project's config file.
368
369 Expects to be called within the project root.
370 """
371 SECTION = 'Hook Overrides'
372 config = ConfigParser.RawConfigParser()
373 try:
374 config.read(_CONFIG_FILE)
375 flags = config.options(SECTION)
376 except ConfigParser.Error:
377 return set([])
378
379 disable_flags = []
380 for flag in flags:
381 try:
382 if not config.getboolean(SECTION, flag): disable_flags.append(flag)
383 except ValueError as e:
384 msg = "Error parsing flag \'%s\' in %s file - " % (flag, _CONFIG_FILE)
385 print msg + str(e)
386
387 disabled_keys = set(_DISABLE_FLAGS.iterkeys()).intersection(disable_flags)
388 return set([_DISABLE_FLAGS[key] for key in disabled_keys])
389
390
391def _get_project_hooks(project):
392 """Returns a list of hooks that need to be run for a project.
393
394 Expects to be called from within the project root.
395 """
396 disabled_hooks = _get_disabled_hooks()
397 hooks = [hook for hook in _COMMON_HOOKS if hook not in disabled_hooks]
398
399 if project in _PROJECT_SPECIFIC_HOOKS:
400 hooks.extend(_PROJECT_SPECIFIC_HOOKS[project])
401
402 return hooks
403
404
405def _run_project_hooks(project):
Ryan Cui1562fb82011-05-09 11:01:31 -0700406 """For each project run its project specific hook from the hooks dictionary.
407
408 Args:
409 project: name of project to run hooks for.
Ryan Cui1562fb82011-05-09 11:01:31 -0700410
411 Returns:
412 Boolean value of whether any errors were ecountered while running the hooks.
413 """
Ryan Cui72834d12011-05-05 14:51:33 -0700414 proj_dir = _run_command(['repo', 'forall', project, '-c', 'pwd']).strip()
Ryan Cuiec4d6332011-05-02 14:15:25 -0700415 pwd = os.getcwd()
416 # hooks assume they are run from the root of the project
417 os.chdir(proj_dir)
418
Ryan Cuifa55df52011-05-06 11:16:55 -0700419 try:
420 commit_list = _get_commits()
Don Garrettdba548a2011-05-05 15:17:14 -0700421 except VerifyException as e:
Ryan Cui1562fb82011-05-09 11:01:31 -0700422 PrintErrorForProject(project, HookFailure(str(e)))
423 os.chdir(pwd)
424 return True
Ryan Cuifa55df52011-05-06 11:16:55 -0700425
Ryan Cui9b651632011-05-11 11:38:58 -0700426 hooks = _get_project_hooks(project)
Ryan Cui1562fb82011-05-09 11:01:31 -0700427 error_found = False
Ryan Cuifa55df52011-05-06 11:16:55 -0700428 for commit in commit_list:
Ryan Cui1562fb82011-05-09 11:01:31 -0700429 error_list = []
Ryan Cui9b651632011-05-11 11:38:58 -0700430 for hook in hooks:
Ryan Cui1562fb82011-05-09 11:01:31 -0700431 hook_error = hook(project, commit)
432 if hook_error:
433 error_list.append(hook_error)
434 error_found = True
435 if error_list:
436 PrintErrorsForCommit(project, commit, _get_commit_desc(commit),
437 error_list)
Don Garrettdba548a2011-05-05 15:17:14 -0700438
Ryan Cuiec4d6332011-05-02 14:15:25 -0700439 os.chdir(pwd)
Ryan Cui1562fb82011-05-09 11:01:31 -0700440 return error_found
Mandeep Singh Baines116ad102011-04-27 15:16:37 -0700441
Ryan Cui72834d12011-05-05 14:51:33 -0700442
Mandeep Singh Baines116ad102011-04-27 15:16:37 -0700443# Main
Mandeep Singh Baines69e470e2011-04-06 10:34:52 -0700444
Ryan Cui1562fb82011-05-09 11:01:31 -0700445
Anush Elangovan63afad72011-03-23 00:41:27 -0700446def main(project_list, **kwargs):
Ryan Cui1562fb82011-05-09 11:01:31 -0700447 found_error = False
448 for project in project_list:
Ryan Cui9b651632011-05-11 11:38:58 -0700449 if _run_project_hooks(project):
Ryan Cui1562fb82011-05-09 11:01:31 -0700450 found_error = True
451
452 if (found_error):
453 msg = ('Preupload failed due to errors in project(s). HINTS:\n'
Ryan Cui9b651632011-05-11 11:38:58 -0700454 '- To disable some source style checks, and for other hints, see '
455 '<checkout_dir>/src/repohooks/README\n'
456 '- To upload only current project, run \'repo upload .\'')
Ryan Cui1562fb82011-05-09 11:01:31 -0700457 print >> sys.stderr, msg
Don Garrettdba548a2011-05-05 15:17:14 -0700458 sys.exit(1)
Anush Elangovan63afad72011-03-23 00:41:27 -0700459
Ryan Cui1562fb82011-05-09 11:01:31 -0700460
Mandeep Singh Baines69e470e2011-04-06 10:34:52 -0700461if __name__ == '__main__':
462 main()