18 if filename.endswith(os.path.join(
'platform',
'globals.h'))
or \
19 filename.find(
'third_party') != -1:
21 fh = open(filename,
'r')
23 match = re.search(
'\\bmemcpy\\b', content)
25 offset = match.start()
26 end_of_line = content.index(
'\n', offset)
28 if 'NOLINT' not in content[offset:end_of_line]:
29 line_number = content[0:match.start()].
count(
'\n') + 1
30 print(
"%s:%d: use of memcpy is forbidden" % (filename, line_number))
37 cpplint._cpplint_state.ResetErrorCounts()
38 memcpy_match_count = 0
40 for git_file
in input_api.AffectedTextFiles():
41 filename = git_file.AbsoluteLocalPath()
42 if filename.endswith(
'.cc')
or (
46 not filename.endswith(
'.pbzero.h')
and filename.endswith(
'.h')):
48 cpplint.ProcessFile(filename, 1)
53 if cpplint._cpplint_state.error_count > 0
or memcpy_match_count > 0:
54 result = [output_api.PresubmitError(
'Failed cpplint check.')]
59 return input_api.canned_checks.CheckGNFormatted(input_api, output_api)
64 def convert_warning_to_error(presubmit_result):
65 if not presubmit_result.fatal:
67 result_json = presubmit_result.json_format()
68 return output_api.PresubmitError(
69 message=result_json[
'message'],
70 items=result_json[
'items'],
71 long_text=result_json[
'long_text'])
72 return presubmit_result
74 results = input_api.canned_checks.CheckPatchFormatted(input_api, output_api)
75 return [convert_warning_to_error(r)
for r
in results]
79 return (
RunLint(input_api, output_api) +
CheckGn(input_api, output_api) +
84 return (
RunLint(input_api, output_api) +
CheckGn(input_api, output_api) +
def CheckChangeOnCommit(input_api, output_api)
def CheckChangeOnUpload(input_api, output_api)
def CheckMemcpy(filename)
def CheckGn(input_api, output_api)
def CheckFormatted(input_api, output_api)
def RunLint(input_api, output_api)
def print(*args, **kwargs)