blob: 846927bb39fd8dfc7d8aa4f8955fea92cef14e31 [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'])
23
Hector Dearman534765e2017-11-01 11:17:38 +000024 results = []
25 results += input.canned_checks.CheckDoNotSubmit(input, output)
26 results += input.canned_checks.CheckChangeHasNoTabs(input, output)
Sami Kyostilab27619f2017-12-13 19:22:16 +000027 results += input.canned_checks.CheckLongLines(
28 input, output, 80, source_file_filter=long_line_sources)
Hector Dearman534765e2017-11-01 11:17:38 +000029 results += input.canned_checks.CheckPatchFormatted(input, output)
30 results += input.canned_checks.CheckGNFormatted(input, output)
Sami Kyostilab27619f2017-12-13 19:22:16 +000031 results += CheckAndroidBlueprint(input, output)
Hector Dearman534765e2017-11-01 11:17:38 +000032 return results
33
Sami Kyostilab27619f2017-12-13 19:22:16 +000034
Hector Dearman534765e2017-11-01 11:17:38 +000035def CheckChangeOnUpload(input_api, output_api):
36 return CheckChange(input_api, output_api)
37
Sami Kyostilab27619f2017-12-13 19:22:16 +000038
Hector Dearman534765e2017-11-01 11:17:38 +000039def CheckChangeOnCommit(input_api, output_api):
40 return CheckChange(input_api, output_api)
41
Sami Kyostilab27619f2017-12-13 19:22:16 +000042
43def CheckAndroidBlueprint(input_api, output_api):
44 # If no GN files were modified, bail out.
45 build_file_filter = lambda x: input_api.FilterSourceFile(
46 x,
47 white_list=('.*BUILD[.]gn$', '.*[.]gni$', 'tools/gen_android_bp'))
48 if not input_api.AffectedSourceFiles(build_file_filter):
49 return []
50
51 with open('Android.bp') as f:
52 current_blueprint = f.read()
53 new_blueprint = subprocess.check_output(
54 ['tools/gen_android_bp', '--output', '/dev/stdout'])
55
56 if current_blueprint != new_blueprint:
57 return [
58 output_api.PresubmitError(
59 'Android.bp is out of date. Please run tools/gen_android_bp '
60 'to update it.')
61 ]
62 return []