blob: 2088a4ae32a28d0fa186c31f6821595a4b0e822f [file] [log] [blame]
Mandeep Singh Baines863b7572010-10-13 13:48:04 -07001# 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
7See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8for more details about the presubmit API built into gcl and git cl.
9"""
10
Mandeep Singh Baines9824dd92010-11-29 13:24:16 -080011import subprocess
12
13def 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 Baines863b7572010-10-13 13:48:04 -070027def 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
35def CheckChange(input_api, output_api, committing):
36 results = []
37 results += CheckSignOff(input_api, output_api)
Mandeep Singh Baines9824dd92010-11-29 13:24:16 -080038 results += CheckPatch(input_api, output_api)
Mandeep Singh Baines863b7572010-10-13 13:48:04 -070039 return results
40
41def CheckChangeOnUpload(input_api, output_api):
42 return CheckChange(input_api, output_api, False)
43
44def CheckChangeOnCommit(input_api, output_api):
45 return CheckChange(input_api, output_api, True)