blob: 4a647cd560c59f92b322b2a01023aff19e44171f [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[^/]*/[^/]+/[^/]+$",
Ryan Cuiec4d6332011-05-02 14:15:25 -070042]
Mandeep Singh Baines116ad102011-04-27 15:16:37 -070043
Ryan Cui1562fb82011-05-09 11:01:31 -070044
Ryan Cui9b651632011-05-11 11:38:58 -070045_CONFIG_FILE = 'PRESUBMIT.cfg'
46
47
Ryan Cui1562fb82011-05-09 11:01:31 -070048# General Helpers
49
Sean Paulba01d402011-05-05 11:36:23 -040050
Ryan Cui72834d12011-05-05 14:51:33 -070051def _run_command(cmd):
52 """Executes the passed in command and returns raw stdout output."""
53 return subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
54
Ryan Cui1562fb82011-05-09 11:01:31 -070055
Mandeep Singh Baines116ad102011-04-27 15:16:37 -070056def _get_hooks_dir():
Ryan Cuiec4d6332011-05-02 14:15:25 -070057 """Returns the absolute path to the repohooks directory."""
Mandeep Singh Baines116ad102011-04-27 15:16:37 -070058 cmd = ['repo', 'forall', 'chromiumos/repohooks', '-c', 'pwd']
Ryan Cui72834d12011-05-05 14:51:33 -070059 return _run_command(cmd).strip()
Mandeep Singh Baines116ad102011-04-27 15:16:37 -070060
Ryan Cui1562fb82011-05-09 11:01:31 -070061
Ryan Cuiec4d6332011-05-02 14:15:25 -070062def _match_regex_list(subject, expressions):
63 """Try to match a list of regular expressions to a string.
64
65 Args:
66 subject: The string to match regexes on
67 expressions: A list of regular expressions to check for matches with.
68
69 Returns:
70 Whether the passed in subject matches any of the passed in regexes.
71 """
72 for expr in expressions:
73 if (re.search(expr, subject)):
74 return True
75 return False
76
Ryan Cui1562fb82011-05-09 11:01:31 -070077
Ryan Cuiec4d6332011-05-02 14:15:25 -070078def _filter_files(files, include_list, exclude_list=[]):
79 """Filter out files based on the conditions passed in.
80
81 Args:
82 files: list of filepaths to filter
83 include_list: list of regex that when matched with a file path will cause it
84 to be added to the output list unless the file is also matched with a
85 regex in the exclude_list.
86 exclude_list: list of regex that when matched with a file will prevent it
87 from being added to the output list, even if it is also matched with a
88 regex in the include_list.
89
90 Returns:
91 A list of filepaths that contain files matched in the include_list and not
92 in the exclude_list.
93 """
94 filtered = []
95 for f in files:
96 if (_match_regex_list(f, include_list) and
97 not _match_regex_list(f, exclude_list)):
98 filtered.append(f)
99 return filtered
100
Ryan Cuiec4d6332011-05-02 14:15:25 -0700101
102# Git Helpers
Ryan Cui1562fb82011-05-09 11:01:31 -0700103
104
Ryan Cui4725d952011-05-05 15:41:19 -0700105def _get_upstream_branch():
106 """Returns the upstream tracking branch of the current branch.
107
108 Raises:
109 Error if there is no tracking branch
110 """
111 current_branch = _run_command(['git', 'symbolic-ref', 'HEAD']).strip()
112 current_branch = current_branch.replace('refs/heads/', '')
113 if not current_branch:
Ryan Cui1562fb82011-05-09 11:01:31 -0700114 raise VerifyException('Need to be on a tracking branch')
Ryan Cui4725d952011-05-05 15:41:19 -0700115
116 cfg_option = 'branch.' + current_branch + '.%s'
117 full_upstream = _run_command(['git', 'config', cfg_option % 'merge']).strip()
118 remote = _run_command(['git', 'config', cfg_option % 'remote']).strip()
119 if not remote or not full_upstream:
Ryan Cui1562fb82011-05-09 11:01:31 -0700120 raise VerifyException('Need to be on a tracking branch')
Ryan Cui4725d952011-05-05 15:41:19 -0700121
122 return full_upstream.replace('heads', 'remotes/' + remote)
123
Ryan Cui1562fb82011-05-09 11:01:31 -0700124
Mandeep Singh Bainesb9ed1402011-04-29 15:32:06 -0700125def _get_diff(commit):
Ryan Cuiec4d6332011-05-02 14:15:25 -0700126 """Returns the diff for this commit."""
Ryan Cui72834d12011-05-05 14:51:33 -0700127 return _run_command(['git', 'show', commit])
Mandeep Singh Baines116ad102011-04-27 15:16:37 -0700128
Ryan Cui1562fb82011-05-09 11:01:31 -0700129
Ryan Cuiec4d6332011-05-02 14:15:25 -0700130def _get_file_diff(file, commit):
131 """Returns a list of (linenum, lines) tuples that the commit touched."""
Ryan Cui72834d12011-05-05 14:51:33 -0700132 output = _run_command(['git', 'show', '-p', '--no-ext-diff', commit, file])
Ryan Cuiec4d6332011-05-02 14:15:25 -0700133
134 new_lines = []
135 line_num = 0
136 for line in output.splitlines():
137 m = re.match(r'^@@ [0-9\,\+\-]+ \+([0-9]+)\,[0-9]+ @@', line)
138 if m:
139 line_num = int(m.groups(1)[0])
140 continue
141 if line.startswith('+') and not line.startswith('++'):
142 new_lines.append((line_num, line[1:]))
143 if not line.startswith('-'):
144 line_num += 1
145 return new_lines
146
Ryan Cui1562fb82011-05-09 11:01:31 -0700147
Ryan Cuiec4d6332011-05-02 14:15:25 -0700148def _get_affected_files(commit):
149 """Returns list of absolute filepaths that were modified/added."""
Ryan Cui72834d12011-05-05 14:51:33 -0700150 output = _run_command(['git', 'diff', '--name-status', commit + '^!'])
Ryan Cuiec4d6332011-05-02 14:15:25 -0700151 files = []
152 for statusline in output.splitlines():
153 m = re.match('^(\w)+\t(.+)$', statusline.rstrip())
154 # Ignore deleted files, and return absolute paths of files
155 if (m.group(1)[0] != 'D'):
156 pwd = os.getcwd()
157 files.append(os.path.join(pwd, m.group(2)))
158 return files
159
Ryan Cui1562fb82011-05-09 11:01:31 -0700160
Mandeep Singh Bainesb9ed1402011-04-29 15:32:06 -0700161def _get_commits():
Ryan Cuiec4d6332011-05-02 14:15:25 -0700162 """Returns a list of commits for this review."""
Ryan Cui4725d952011-05-05 15:41:19 -0700163 cmd = ['git', 'log', '%s..' % _get_upstream_branch(), '--format=%H']
Ryan Cui72834d12011-05-05 14:51:33 -0700164 return _run_command(cmd).split()
Mandeep Singh Bainesb9ed1402011-04-29 15:32:06 -0700165
Ryan Cui1562fb82011-05-09 11:01:31 -0700166
Ryan Cuiec4d6332011-05-02 14:15:25 -0700167def _get_commit_desc(commit):
168 """Returns the full commit message of a commit."""
Sean Paul23a2c582011-05-06 13:10:44 -0400169 return _run_command(['git', 'log', '--format=%s%n%n%b', commit + '^!'])
Ryan Cuiec4d6332011-05-02 14:15:25 -0700170
171
172# Common Hooks
173
Ryan Cui1562fb82011-05-09 11:01:31 -0700174
Ryan Cuiec4d6332011-05-02 14:15:25 -0700175def _check_no_long_lines(project, commit):
176 """Checks that there aren't any lines longer than maxlen characters in any of
177 the text files to be submitted.
178 """
179 MAX_LEN = 80
180
181 errors = []
182 files = _filter_files(_get_affected_files(commit),
183 COMMON_INCLUDED_PATHS,
184 COMMON_EXCLUDED_PATHS)
185
186 for afile in files:
187 for line_num, line in _get_file_diff(afile, commit):
188 # Allow certain lines to exceed the maxlen rule.
189 if (len(line) > MAX_LEN and
190 not 'http://' in line and
191 not 'https://' in line and
192 not line.startswith('#define') and
193 not line.startswith('#include') and
194 not line.startswith('#import') and
195 not line.startswith('#pragma') and
196 not line.startswith('#if') and
197 not line.startswith('#endif')):
198 errors.append('%s, line %s, %s chars' % (afile, line_num, len(line)))
199 if len(errors) == 5: # Just show the first 5 errors.
200 break
201
202 if errors:
203 msg = 'Found lines longer than %s characters (first 5 shown):' % MAX_LEN
Ryan Cui1562fb82011-05-09 11:01:31 -0700204 return HookFailure(msg, errors)
205
Ryan Cuiec4d6332011-05-02 14:15:25 -0700206
207def _check_no_stray_whitespace(project, commit):
208 """Checks that there is no stray whitespace at source lines end."""
209 errors = []
210 files = _filter_files(_get_affected_files(commit),
211 COMMON_INCLUDED_PATHS,
212 COMMON_EXCLUDED_PATHS)
213
214 for afile in files:
215 for line_num, line in _get_file_diff(afile, commit):
216 if line.rstrip() != line:
217 errors.append('%s, line %s' % (afile, line_num))
218 if errors:
Ryan Cui1562fb82011-05-09 11:01:31 -0700219 return HookFailure('Found line ending with white space in:', errors)
220
Ryan Cuiec4d6332011-05-02 14:15:25 -0700221
222def _check_no_tabs(project, commit):
223 """Checks there are no unexpanded tabs."""
224 TAB_OK_PATHS = [
Ryan Cui31e0c172011-05-04 21:00:45 -0700225 r"/src/third_party/u-boot/",
Ryan Cuiec4d6332011-05-02 14:15:25 -0700226 r".*\.ebuild$",
227 r".*\.eclass$",
228 r".*/[M|m]akefile$"
229 ]
230
231 errors = []
232 files = _filter_files(_get_affected_files(commit),
233 COMMON_INCLUDED_PATHS,
234 COMMON_EXCLUDED_PATHS + TAB_OK_PATHS)
235
236 for afile in files:
237 for line_num, line in _get_file_diff(afile, commit):
238 if '\t' in line:
239 errors.append('%s, line %s' % (afile, line_num))
240 if errors:
Ryan Cui1562fb82011-05-09 11:01:31 -0700241 return HookFailure('Found a tab character in:', errors)
242
Ryan Cuiec4d6332011-05-02 14:15:25 -0700243
244def _check_change_has_test_field(project, commit):
245 """Check for a non-empty 'TEST=' field in the commit message."""
David McMahon8f6553e2011-06-10 15:46:36 -0700246 TEST_RE = r'\nTEST=\S+'
Ryan Cuiec4d6332011-05-02 14:15:25 -0700247
Mandeep Singh Baines96a53be2011-05-03 11:10:25 -0700248 if not re.search(TEST_RE, _get_commit_desc(commit)):
Ryan Cui1562fb82011-05-09 11:01:31 -0700249 msg = 'Changelist description needs TEST field (after first line)'
250 return HookFailure(msg)
251
Ryan Cuiec4d6332011-05-02 14:15:25 -0700252
253def _check_change_has_bug_field(project, commit):
David McMahon8f6553e2011-06-10 15:46:36 -0700254 """Check for a correctly formatted 'BUG=' field in the commit message."""
255 BUG_RE = r'\nBUG=([Nn]one|(chrome-os-partner|chromium-os):\d+)'
Ryan Cuiec4d6332011-05-02 14:15:25 -0700256
Mandeep Singh Baines96a53be2011-05-03 11:10:25 -0700257 if not re.search(BUG_RE, _get_commit_desc(commit)):
David McMahon8f6553e2011-06-10 15:46:36 -0700258 msg = ('Changelist description needs BUG field (after first line):\n'
259 'BUG=chromium-os:99999 (for public tracker)\n'
260 'BUG=chrome-os-partner:9999 (for partner tracker)\n'
261 'BUG=None')
Ryan Cui1562fb82011-05-09 11:01:31 -0700262 return HookFailure(msg)
263
Ryan Cuiec4d6332011-05-02 14:15:25 -0700264
Mandeep Singh Bainesa23eb5f2011-05-04 13:43:25 -0700265def _check_change_has_proper_changeid(project, commit):
266 """Verify that Change-ID is present in last paragraph of commit message."""
267 desc = _get_commit_desc(commit)
268 loc = desc.rfind('\nChange-Id:')
269 if loc == -1 or re.search('\n\s*\n\s*\S+', desc[loc:]):
Ryan Cui1562fb82011-05-09 11:01:31 -0700270 return HookFailure('Change-Id must be in last paragraph of description.')
271
Mandeep Singh Bainesa23eb5f2011-05-04 13:43:25 -0700272
Ryan Cuiec4d6332011-05-02 14:15:25 -0700273def _check_license(project, commit):
274 """Verifies the license header."""
275 LICENSE_HEADER = (
276 r".*? Copyright \(c\) 20[-0-9]{2,7} The Chromium OS Authors\. All rights "
277 r"reserved\." "\n"
278 r".*? Use of this source code is governed by a BSD-style license that can "
279 "be\n"
280 r".*? found in the LICENSE file\."
281 "\n"
282 )
283
284 license_re = re.compile(LICENSE_HEADER, re.MULTILINE)
285 bad_files = []
286 files = _filter_files(_get_affected_files(commit),
287 COMMON_INCLUDED_PATHS,
288 COMMON_EXCLUDED_PATHS)
289
290 for f in files:
291 contents = open(f).read()
292 if len(contents) == 0: continue # Ignore empty files
293 if not license_re.search(contents):
294 bad_files.append(f)
295 if bad_files:
Ryan Cui1562fb82011-05-09 11:01:31 -0700296 return HookFailure('License must match:\n%s\n' % license_re.pattern +
297 'Found a bad license header in these files:',
298 bad_files)
Ryan Cuiec4d6332011-05-02 14:15:25 -0700299
300
301# Project-specific hooks
Mandeep Singh Baines116ad102011-04-27 15:16:37 -0700302
Ryan Cui1562fb82011-05-09 11:01:31 -0700303
Anton Staaf815d6852011-08-22 10:08:45 -0700304def _run_checkpatch(project, commit, options=[]):
Mandeep Singh Baines116ad102011-04-27 15:16:37 -0700305 """Runs checkpatch.pl on the given project"""
306 hooks_dir = _get_hooks_dir()
Anton Staaf815d6852011-08-22 10:08:45 -0700307 cmd = ['%s/checkpatch.pl' % hooks_dir] + options + ['-']
Mandeep Singh Baines116ad102011-04-27 15:16:37 -0700308 p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
Mandeep Singh Bainesb9ed1402011-04-29 15:32:06 -0700309 output = p.communicate(_get_diff(commit))[0]
Mandeep Singh Baines116ad102011-04-27 15:16:37 -0700310 if p.returncode:
Ryan Cui1562fb82011-05-09 11:01:31 -0700311 return HookFailure('checkpatch.pl errors/warnings\n\n' + output)
Ryan Cuiec4d6332011-05-02 14:15:25 -0700312
Mandeep Singh Baines116ad102011-04-27 15:16:37 -0700313
Anton Staaf815d6852011-08-22 10:08:45 -0700314def _run_checkpatch_no_tree(project, commit):
315 return _run_checkpatch(project, commit, ['--no-tree'])
316
317
Dale Curtis2975c432011-05-03 17:25:20 -0700318def _run_json_check(project, commit):
319 """Checks that all JSON files are syntactically valid."""
Dale Curtisa039cfd2011-05-04 12:01:05 -0700320 for f in _filter_files(_get_affected_files(commit), [r'.*\.json']):
Dale Curtis2975c432011-05-03 17:25:20 -0700321 try:
322 json.load(open(f))
323 except Exception, e:
Ryan Cui1562fb82011-05-09 11:01:31 -0700324 return HookFailure('Invalid JSON in %s: %s' % (f, e))
Dale Curtis2975c432011-05-03 17:25:20 -0700325
326
Mandeep Singh Baines116ad102011-04-27 15:16:37 -0700327# Base
328
Ryan Cui1562fb82011-05-09 11:01:31 -0700329
Ryan Cui9b651632011-05-11 11:38:58 -0700330# A list of hooks that are not project-specific
331_COMMON_HOOKS = [
332 _check_change_has_bug_field,
333 _check_change_has_test_field,
334 _check_change_has_proper_changeid,
335 _check_no_stray_whitespace,
336 _check_no_long_lines,
337 _check_license,
338 _check_no_tabs,
339]
Ryan Cuiec4d6332011-05-02 14:15:25 -0700340
Ryan Cui1562fb82011-05-09 11:01:31 -0700341
Ryan Cui9b651632011-05-11 11:38:58 -0700342# A dictionary of project-specific hooks(callbacks), indexed by project name.
343# dict[project] = [callback1, callback2]
344_PROJECT_SPECIFIC_HOOKS = {
Doug Anderson830216f2011-05-02 10:08:37 -0700345 "chromiumos/third_party/kernel": [_run_checkpatch],
346 "chromiumos/third_party/kernel-next": [_run_checkpatch],
Anton Staaf815d6852011-08-22 10:08:45 -0700347 "chromiumos/third_party/u-boot": [_run_checkpatch_no_tree],
Che-Liang Chiou1eb0ab62011-10-20 16:14:38 +0800348 "chromiumos/platform/u-boot-vboot-integration": [_run_checkpatch_no_tree],
Dale Curtis2975c432011-05-03 17:25:20 -0700349 "chromeos/autotest-tools": [_run_json_check],
Ryan Cui9b651632011-05-11 11:38:58 -0700350}
Mandeep Singh Baines116ad102011-04-27 15:16:37 -0700351
Ryan Cui1562fb82011-05-09 11:01:31 -0700352
Ryan Cui9b651632011-05-11 11:38:58 -0700353# A dictionary of flags (keys) that can appear in the config file, and the hook
354# that the flag disables (value)
355_DISABLE_FLAGS = {
356 'stray_whitespace_check': _check_no_stray_whitespace,
357 'long_line_check': _check_no_long_lines,
358 'cros_license_check': _check_license,
359 'tab_check': _check_no_tabs,
360}
361
362
363def _get_disabled_hooks():
364 """Returns a set of hooks disabled by the current project's config file.
365
366 Expects to be called within the project root.
367 """
368 SECTION = 'Hook Overrides'
369 config = ConfigParser.RawConfigParser()
370 try:
371 config.read(_CONFIG_FILE)
372 flags = config.options(SECTION)
373 except ConfigParser.Error:
374 return set([])
375
376 disable_flags = []
377 for flag in flags:
378 try:
379 if not config.getboolean(SECTION, flag): disable_flags.append(flag)
380 except ValueError as e:
381 msg = "Error parsing flag \'%s\' in %s file - " % (flag, _CONFIG_FILE)
382 print msg + str(e)
383
384 disabled_keys = set(_DISABLE_FLAGS.iterkeys()).intersection(disable_flags)
385 return set([_DISABLE_FLAGS[key] for key in disabled_keys])
386
387
388def _get_project_hooks(project):
389 """Returns a list of hooks that need to be run for a project.
390
391 Expects to be called from within the project root.
392 """
393 disabled_hooks = _get_disabled_hooks()
394 hooks = [hook for hook in _COMMON_HOOKS if hook not in disabled_hooks]
395
396 if project in _PROJECT_SPECIFIC_HOOKS:
397 hooks.extend(_PROJECT_SPECIFIC_HOOKS[project])
398
399 return hooks
400
401
402def _run_project_hooks(project):
Ryan Cui1562fb82011-05-09 11:01:31 -0700403 """For each project run its project specific hook from the hooks dictionary.
404
405 Args:
406 project: name of project to run hooks for.
Ryan Cui1562fb82011-05-09 11:01:31 -0700407
408 Returns:
409 Boolean value of whether any errors were ecountered while running the hooks.
410 """
Ryan Cui72834d12011-05-05 14:51:33 -0700411 proj_dir = _run_command(['repo', 'forall', project, '-c', 'pwd']).strip()
Ryan Cuiec4d6332011-05-02 14:15:25 -0700412 pwd = os.getcwd()
413 # hooks assume they are run from the root of the project
414 os.chdir(proj_dir)
415
Ryan Cuifa55df52011-05-06 11:16:55 -0700416 try:
417 commit_list = _get_commits()
Don Garrettdba548a2011-05-05 15:17:14 -0700418 except VerifyException as e:
Ryan Cui1562fb82011-05-09 11:01:31 -0700419 PrintErrorForProject(project, HookFailure(str(e)))
420 os.chdir(pwd)
421 return True
Ryan Cuifa55df52011-05-06 11:16:55 -0700422
Ryan Cui9b651632011-05-11 11:38:58 -0700423 hooks = _get_project_hooks(project)
Ryan Cui1562fb82011-05-09 11:01:31 -0700424 error_found = False
Ryan Cuifa55df52011-05-06 11:16:55 -0700425 for commit in commit_list:
Ryan Cui1562fb82011-05-09 11:01:31 -0700426 error_list = []
Ryan Cui9b651632011-05-11 11:38:58 -0700427 for hook in hooks:
Ryan Cui1562fb82011-05-09 11:01:31 -0700428 hook_error = hook(project, commit)
429 if hook_error:
430 error_list.append(hook_error)
431 error_found = True
432 if error_list:
433 PrintErrorsForCommit(project, commit, _get_commit_desc(commit),
434 error_list)
Don Garrettdba548a2011-05-05 15:17:14 -0700435
Ryan Cuiec4d6332011-05-02 14:15:25 -0700436 os.chdir(pwd)
Ryan Cui1562fb82011-05-09 11:01:31 -0700437 return error_found
Mandeep Singh Baines116ad102011-04-27 15:16:37 -0700438
Ryan Cui72834d12011-05-05 14:51:33 -0700439
Mandeep Singh Baines116ad102011-04-27 15:16:37 -0700440# Main
Mandeep Singh Baines69e470e2011-04-06 10:34:52 -0700441
Ryan Cui1562fb82011-05-09 11:01:31 -0700442
Anush Elangovan63afad72011-03-23 00:41:27 -0700443def main(project_list, **kwargs):
Ryan Cui1562fb82011-05-09 11:01:31 -0700444 found_error = False
445 for project in project_list:
Ryan Cui9b651632011-05-11 11:38:58 -0700446 if _run_project_hooks(project):
Ryan Cui1562fb82011-05-09 11:01:31 -0700447 found_error = True
448
449 if (found_error):
450 msg = ('Preupload failed due to errors in project(s). HINTS:\n'
Ryan Cui9b651632011-05-11 11:38:58 -0700451 '- To disable some source style checks, and for other hints, see '
452 '<checkout_dir>/src/repohooks/README\n'
453 '- To upload only current project, run \'repo upload .\'')
Ryan Cui1562fb82011-05-09 11:01:31 -0700454 print >> sys.stderr, msg
Don Garrettdba548a2011-05-05 15:17:14 -0700455 sys.exit(1)
Anush Elangovan63afad72011-03-23 00:41:27 -0700456
Ryan Cui1562fb82011-05-09 11:01:31 -0700457
Mandeep Singh Baines69e470e2011-04-06 10:34:52 -0700458if __name__ == '__main__':
459 main()