blob: ad839c4f2972b5192bac3c93afe042c682706dca [file] [log] [blame]
Hector Dearman534765e2017-11-01 11:17:38 +00001# Copyright (C) 2017 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Sami Kyostilab27619f2017-12-13 19:22:16 +000015import subprocess
16
17
Hector Dearman534765e2017-11-01 11:17:38 +000018def CheckChange(input, output):
Sami Kyostilab27619f2017-12-13 19:22:16 +000019 # There apparently is no way to wrap strings in blueprints, so ignore long
20 # lines in them.
21 long_line_sources = lambda x: input.FilterSourceFile(
22 x, white_list=".*", black_list=['Android[.]bp'])
Hector Dearman534765e2017-11-01 11:17:38 +000023 results = []
24 results += input.canned_checks.CheckDoNotSubmit(input, output)
25 results += input.canned_checks.CheckChangeHasNoTabs(input, output)
Sami Kyostilab27619f2017-12-13 19:22:16 +000026 results += input.canned_checks.CheckLongLines(
27 input, output, 80, source_file_filter=long_line_sources)
Hector Dearman534765e2017-11-01 11:17:38 +000028 results += input.canned_checks.CheckPatchFormatted(input, output)
29 results += input.canned_checks.CheckGNFormatted(input, output)
Primiano Tucci40e98722018-02-16 11:50:17 +000030 results += CheckIncludeGuards(input, output)
Sami Kyostilab27619f2017-12-13 19:22:16 +000031 results += CheckAndroidBlueprint(input, output)
Primiano Tuccic5010802018-01-19 17:13:21 +000032 results += CheckMergedTraceConfigProto(input, output)
Hector Dearman534765e2017-11-01 11:17:38 +000033 return results
34
Sami Kyostilab27619f2017-12-13 19:22:16 +000035
Hector Dearman534765e2017-11-01 11:17:38 +000036def CheckChangeOnUpload(input_api, output_api):
37 return CheckChange(input_api, output_api)
38
Sami Kyostilab27619f2017-12-13 19:22:16 +000039
Hector Dearman534765e2017-11-01 11:17:38 +000040def CheckChangeOnCommit(input_api, output_api):
41 return CheckChange(input_api, output_api)
42
Sami Kyostilab27619f2017-12-13 19:22:16 +000043
44def CheckAndroidBlueprint(input_api, output_api):
45 # If no GN files were modified, bail out.
46 build_file_filter = lambda x: input_api.FilterSourceFile(
47 x,
48 white_list=('.*BUILD[.]gn$', '.*[.]gni$', 'tools/gen_android_bp'))
49 if not input_api.AffectedSourceFiles(build_file_filter):
50 return []
51
52 with open('Android.bp') as f:
53 current_blueprint = f.read()
Primiano Tucci40e98722018-02-16 11:50:17 +000054
Sami Kyostilab27619f2017-12-13 19:22:16 +000055 new_blueprint = subprocess.check_output(
56 ['tools/gen_android_bp', '--output', '/dev/stdout'])
57
58 if current_blueprint != new_blueprint:
59 return [
60 output_api.PresubmitError(
61 'Android.bp is out of date. Please run tools/gen_android_bp '
62 'to update it.')
63 ]
64 return []
Primiano Tuccic5010802018-01-19 17:13:21 +000065
66
Primiano Tucci40e98722018-02-16 11:50:17 +000067def CheckIncludeGuards(input_api, output_api):
68 tool = 'tools/fix_include_guards'
69 file_filter = lambda x: input_api.FilterSourceFile(
70 x,
71 white_list=('.*[.]cc$', '.*[.]h$', tool))
72 if not input_api.AffectedSourceFiles(file_filter):
73 return []
74 if subprocess.call([tool, '--check-only']):
75 return [
76 output_api.PresubmitError(
77 'Please run ' + tool + ' to fix include guards.')
78 ]
79 return []
80
81
Primiano Tuccic5010802018-01-19 17:13:21 +000082def CheckMergedTraceConfigProto(input_api, output_api):
Hector Dearman55ef3e02018-04-11 17:28:55 +010083 tool = 'tools/gen_merged_protos'
Primiano Tuccic5010802018-01-19 17:13:21 +000084 build_file_filter = lambda x: input_api.FilterSourceFile(
85 x,
Hector Dearman55ef3e02018-04-11 17:28:55 +010086 white_list=('protos/perfetto/.*[.]proto$', tool))
Primiano Tuccic5010802018-01-19 17:13:21 +000087 if not input_api.AffectedSourceFiles(build_file_filter):
88 return []
89 if subprocess.call([tool, '--check-only']):
90 return [
91 output_api.PresubmitError(
Hector Dearman55ef3e02018-04-11 17:28:55 +010092 'perfetto_config.proto or perfetto_trace.proto is out of ' +
93 'date. Please run ' + tool + ' to update it.')
Primiano Tuccic5010802018-01-19 17:13:21 +000094 ]
95 return []