Mandeep Singh Baines | 863b757 | 2010-10-13 13:48:04 -0700 | [diff] [blame] | 1 | # Copyright (c) 2010 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 | |
| 5 | """Top-level presubmit script for kernel. |
| 6 | |
| 7 | See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 8 | for more details about the presubmit API built into gcl and git cl. |
| 9 | """ |
| 10 | |
Mandeep Singh Baines | 9824dd9 | 2010-11-29 13:24:16 -0800 | [diff] [blame^] | 11 | import subprocess |
| 12 | |
| 13 | def CheckPatch(input_api, output_api, source_file_filter=None): |
| 14 | """Checks that there is a Signed-off-by in the description.""" |
| 15 | output = [] |
| 16 | checkpatch = 'scripts/checkpatch.pl' |
| 17 | for affected_file in input_api.AffectedSourceFiles(source_file_filter): |
| 18 | file_name = affected_file.LocalPath() |
| 19 | if file_name.endswith('.c') or file_name.endswith('.h'): |
| 20 | cmd = subprocess.Popen([checkpatch, '-f', file_name], |
| 21 | stdout=subprocess.PIPE) |
| 22 | stdout, _ = cmd.communicate() |
| 23 | if cmd.returncode: |
| 24 | output.append(output_api.PresubmitPromptWarning(stdout)) |
| 25 | return output |
| 26 | |
Mandeep Singh Baines | 863b757 | 2010-10-13 13:48:04 -0700 | [diff] [blame] | 27 | def CheckSignOff(input_api, output_api, source_file_filter=None): |
| 28 | """Checks that there is a Signed-off-by in the description.""" |
| 29 | output = [] |
| 30 | if input_api.change.DescriptionText().count('Signed-off-by:') == 0: |
| 31 | output.append(output_api.PresubmitError( |
| 32 | 'This project requires all commits to contain a Signed-off-by:')) |
| 33 | return output |
| 34 | |
| 35 | def CheckChange(input_api, output_api, committing): |
| 36 | results = [] |
| 37 | results += CheckSignOff(input_api, output_api) |
Mandeep Singh Baines | 9824dd9 | 2010-11-29 13:24:16 -0800 | [diff] [blame^] | 38 | results += CheckPatch(input_api, output_api) |
Mandeep Singh Baines | 863b757 | 2010-10-13 13:48:04 -0700 | [diff] [blame] | 39 | return results |
| 40 | |
| 41 | def CheckChangeOnUpload(input_api, output_api): |
| 42 | return CheckChange(input_api, output_api, False) |
| 43 | |
| 44 | def CheckChangeOnCommit(input_api, output_api): |
| 45 | return CheckChange(input_api, output_api, True) |