-
Notifications
You must be signed in to change notification settings - Fork 4
/
PRESUBMIT.py
executable file
·160 lines (128 loc) · 5 KB
/
PRESUBMIT.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# Copyright (c) 2011 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Documentation on PRESUBMIT.py can be found at:
# http://www.chromium.org/developers/how-tos/depottools/presubmit-scripts
import os
import subprocess
PYTHON = 'build_tools/python_wrapper'
_EXCLUDED_PATHS = (
# patch_configure.py contains long lines embedded in multi-line
# strings.
r"^build_tools[\\\/]patch_configure.py",
)
def RunPylint(input_api, output_api):
output = []
canned = input_api.canned_checks
disabled_warnings = [
'W0613', # Unused argument
]
black_list = list(input_api.DEFAULT_BLACK_LIST) + [
r'ports[\/\\]ipython-ppapi[\/\\]kernel\.py',
]
output.extend(canned.RunPylint(input_api, output_api, black_list=black_list,
disabled_warnings=disabled_warnings, extra_paths_list=['lib']))
return output
def RunCommand(name, cmd, input_api, output_api):
try:
subprocess.check_call(cmd)
except subprocess.CalledProcessError:
message = '%s failed.' % name
return [output_api.PresubmitError(message)]
return []
def RunPythonCommand(cmd, input_api, output_api):
return RunCommand(cmd[0], [PYTHON] + cmd, input_api, output_api)
def CheckCQConfig(input_api, output_api):
def f(x):
return input_api.FilterSourceFile(x,
white_list=['build_tools/commit_queue/cq_config.json'])
if not input_api.AffectedFiles(file_filter=f):
return []
return RunPythonCommand(['build_tools/commit_queue/test_cq_config.py'],
input_api,
output_api)
def CheckPartioning(input_api, output_api):
return RunPythonCommand(['build_tools/partition.py', '--check'],
input_api,
output_api)
def CheckDeps(input_api, output_api):
return RunPythonCommand(['build_tools/check_deps.py'],
input_api,
output_api)
def CheckMirror(input_api, output_api):
return RunPythonCommand(['build_tools/update_mirror.py', '--check'],
input_api,
output_api)
def RunUnittests(input_api, output_api):
return RunCommand('unittests', ['make', 'test'], input_api, output_api)
# This check was copied from the chromium version.
# TODO(sbc): should we add this to canned_checks?
def CheckAuthorizedAuthor(input_api, output_api):
"""Verify the author's email address is in AUTHORS.
"""
import fnmatch
author = input_api.change.author_email
if not author:
input_api.logging.info('No author, skipping AUTHOR check')
return []
authors_path = input_api.os_path.join(
input_api.PresubmitLocalPath(), 'AUTHORS')
valid_authors = (
input_api.re.match(r'[^#]+\s+\<(.+?)\>\s*$', line)
for line in open(authors_path))
valid_authors = [item.group(1).lower() for item in valid_authors if item]
if not any(fnmatch.fnmatch(author.lower(), valid) for valid in valid_authors):
input_api.logging.info('Valid authors are %s', ', '.join(valid_authors))
return [output_api.PresubmitPromptWarning(
('%s is not in AUTHORS file. If you are a new contributor, please visit'
'\n'
'http://www.chromium.org/developers/contributing-code and read the '
'"Legal" section.\n') % author)]
return []
def CheckChangeOnUpload(input_api, output_api):
report = []
report.extend(CheckAuthorizedAuthor(input_api, output_api))
report.extend(CheckCQConfig(input_api, output_api))
report.extend(RunPylint(input_api, output_api))
report.extend(RunUnittests(input_api, output_api))
report.extend(CheckDeps(input_api, output_api))
report.extend(input_api.canned_checks.PanProjectChecks(
input_api, output_api, project_name='Native Client',
excluded_paths=_EXCLUDED_PATHS))
return report
def CheckChangeOnCommit(input_api, output_api):
report = []
report.extend(CheckChangeOnUpload(input_api, output_api))
report.extend(CheckMirror(input_api, output_api))
report.extend(CheckPartioning(input_api, output_api))
report.extend(input_api.canned_checks.CheckTreeIsOpen(
input_api, output_api,
json_url='http://naclports-status.appspot.com/current?format=json'))
return report
TRYBOTS = [
'naclports-linux-glibc-0',
'naclports-linux-glibc-1',
'naclports-linux-glibc-2',
'naclports-linux-glibc-3',
'naclports-linux-glibc-4',
'naclports-linux-newlib-0',
'naclports-linux-newlib-1',
'naclports-linux-newlib-2',
'naclports-linux-newlib-3',
'naclports-linux-newlib-4',
'naclports-linux-pnacl-0',
'naclports-linux-pnacl-1',
'naclports-linux-pnacl-2',
'naclports-linux-pnacl-3',
'naclports-linux-pnacl-4',
'naclports-linux-clang-0',
'naclports-linux-clang-1',
'naclports-linux-clang-2',
'naclports-linux-clang-3',
'naclports-linux-clang-4',
'naclports-linux-emscripten-0',
]
def GetPreferredTryMasters(_, change):
return {
'tryserver.nacl': { t: set(['defaulttests']) for t in TRYBOTS },
}