forked from dart-archive/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PRESUBMIT.py
68 lines (60 loc) · 2.86 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
# Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE.md file.
import cpplint
"""Top-level presubmit script for Fletch.
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
for more details about the presubmit API built into gcl.
"""
# We have auto generated code that we do not want to lint.
NO_LINTING = (
r"^pkg[\\\/]immi_samples[\\\/]lib[\\\/]ios[\\\/].*",
r"^package[\\\/]immi[\\\/]objc[\\\/].*",
r"^package[\\\/]service[\\\/]cc[\\\/].*"
r"^package[\\\/]service[\\\/]java[\\\/]jni[\\\/].*",
r"^samples[\\\/]github[\\\/]ios[\\\/].*",
r"^samples[\\\/]buildbot[\\\/]cc[\\\/].*",
r"^samples[\\\/]buildbot[\\\/]ios[\\\/].*",
r"^samples[\\\/]buildbot[\\\/]java[\\\/]jni[\\\/].*",
r"^samples[\\\/]buildbot[\\\/]objc[\\\/].*",
r"^samples[\\\/]myapi[\\\/]generated[\\\/]java[\\\/]jni[\\\/].*",
r"^samples[\\\/]todomvc[\\\/]cc[\\\/].*",
r"^samples[\\\/]todomvc[\\\/]ios[\\\/].*",
r"^samples[\\\/]todomvc[\\\/]java[\\\/]jni[\\\/].*",
r"^tests[\\\/]service_tests[\\\/]conformance[\\\/]cc[\\\/].*",
r"^tests[\\\/]service_tests[\\\/]conformance[\\\/]java[\\\/]jni[\\\/].*",
r"^tests[\\\/]service_tests[\\\/]performance[\\\/]cc[\\\/].*",
r"^tests[\\\/]service_tests[\\\/]performance[\\\/]java[\\\/]jni[\\\/].*",
r"^tests[\\\/]service_tests[\\\/]multiple_services[\\\/]cc[\\\/].*",
r"^tests[\\\/]service_tests[\\\/]multiple_services[\\\/]java[\\\/]jni[\\\/].*",
r"^third_party[\\\/]double-conversion[\\\/]src[\\\/].*",
r"^tools[\\\/]immic[\\\/]lib[\\\/]src[\\\/]resources[\\\/]objc[\\\/].*",
r"^tools[\\\/]servicec[\\\/]lib[\\\/]src[\\\/]resources[\\\/]cc[\\\/].*",
)
def CheckChangeOnCommit(input_api, output_api):
results = []
status_check = input_api.canned_checks.CheckTreeIsOpen(
input_api,
output_api,
json_url='http://fletch-status.appspot.com/current?format=json')
results.extend(status_check)
results.extend(RunLint(input_api, output_api))
return results
def CheckChangeOnUpload(input_api, output_api):
return RunLint(input_api, output_api)
def RunLint(input_api, output_api):
def FilterFile(file):
return input_api.FilterSourceFile(file,
black_list=NO_LINTING)
result = []
cpplint._cpplint_state.ResetErrorCounts()
# Find all .cc and .h files in the change list.
for f in input_api.AffectedSourceFiles(FilterFile):
filename = f.AbsoluteLocalPath()
if filename.endswith('.cc') or filename.endswith('.h'):
# Run cpplint on the file.
cpplint.ProcessFile(filename, 1)
# Report a presubmit error if any of the files had an error.
if cpplint._cpplint_state.error_count > 0:
result = [output_api.PresubmitError('Failed cpplint check.')]
return result