Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(702)

Side by Side Diff: PRESUBMIT.py

Issue 1342673002: Make PRESUBMIT.py run checks via 'pcg' if it is available in PATH. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pre-commit-go.yml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Top-level presubmit script for client-go. 5 """Top-level presubmit script.
6 6
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for 7 See https://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for
8 details on the presubmit API built into gcl. 8 details on the presubmit API built into depot_tools.
9 """ 9 """
10 10
11 import os
12 import sys
13
14
15 def PreCommitGo(input_api, output_api, pcg_mode):
16 """Run go-specific checks via pre-commit-go (pcg) if it's in PATH."""
17 if input_api.is_committing:
18 error_type = output_api.PresubmitError
19 else:
20 error_type = output_api.PresubmitPromptWarning
21
22 exe = 'pcg.exe' if sys.platform == 'win32' else 'pcg'
23 pcg = None
24 for p in os.environ['PATH'].split(os.pathsep):
25 pcg = os.path.join(p, exe)
26 if os.access(pcg, os.X_OK):
27 break
28 else:
29 return [
30 error_type(
31 'pre-commit-go executable (pcg) could not be found in PATH. All Go '
32 'checks are skipped. See https://github.com/maruel/pre-commit-go.')
33 ]
34
35 # pcg can figure out what files to check on its own based on upstream ref.
36 cmd = [pcg, 'run', '-m', ','.join(pcg_mode)]
37 if input_api.verbose:
38 cmd.append('-v')
39 return input_api.RunTests([
40 input_api.Command(
41 name='pre-commit-go: %s' % ', '.join(pcg_mode),
42 cmd=cmd,
43 kwargs={},
44 message=error_type),
45 ])
46
47
48 def header(input_api):
49 """Returns the expected license header regexp for this project."""
50 current_year = int(input_api.time.strftime('%Y'))
51 allowed_years = (str(s) for s in reversed(xrange(2011, current_year + 1)))
52 years_re = '(' + '|'.join(allowed_years) + ')'
53 license_header = (
54 r'.*? Copyright %(year)s The Chromium Authors\. '
M-A Ruel 2015/09/14 20:14:11 I think we should standardize to LUCI Authors ASAP
55 r'All rights reserved\.\n'
56 r'.*? Use of this source code is governed by a BSD-style license '
57 r'that can be\n'
58 r'.*? found in the LICENSE file\.(?: \*/)?\n'
59 ) % {
60 'year': years_re,
61 }
62 return license_header
63
64
65 def source_file_filter(input_api):
66 """Returns filter that selects source code files only."""
67 bl = list(input_api.DEFAULT_BLACK_LIST) + [
68 r'.+\.pb\.go$',
69 r'.+_string\.go$',
70 ]
71 wl = list(input_api.DEFAULT_WHITE_LIST) + [
72 r'.+\.go$',
73 ]
74 return lambda x: input_api.FilterSourceFile(x, white_list=wl, black_list=bl)
75
11 76
12 def CommonChecks(input_api, output_api): 77 def CommonChecks(input_api, output_api):
13 return [] 78 results = []
79 results.extend(
80 input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
81 input_api, output_api,
82 source_file_filter=source_file_filter(input_api)))
83 results.extend(
84 input_api.canned_checks.CheckLicense(
85 input_api, output_api, header(input_api),
86 source_file_filter=source_file_filter(input_api)))
87 return results
14 88
15 89
16 def CheckChangeOnUpload(input_api, output_api): 90 def CheckChangeOnUpload(input_api, output_api):
17 return CommonChecks(input_api, output_api) 91 results = CommonChecks(input_api, output_api)
92 results.extend(PreCommitGo(input_api, output_api, ['lint', 'pre-commit']))
93 return results
18 94
19 95
20 def CheckChangeOnCommit(input_api, output_api): 96 def CheckChangeOnCommit(input_api, output_api):
21 return CommonChecks(input_api, output_api) 97 results = CommonChecks(input_api, output_api)
98 results.extend(input_api.canned_checks.CheckChangeHasDescription(
99 input_api, output_api))
100 results.extend(input_api.canned_checks.CheckDoNotSubmitInDescription(
101 input_api, output_api))
102 results.extend(input_api.canned_checks.CheckDoNotSubmitInFiles(
103 input_api, output_api))
104 results.extend(PreCommitGo(
105 input_api, output_api, ['lint', 'pre-commit', 'pre-push']))
106 return results
OLDNEW
« no previous file with comments | « no previous file | pre-commit-go.yml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698