Hector Dearman | 534765e | 2017-11-01 11:17:38 +0000 | [diff] [blame] | 1 | # 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 Kyostila | b27619f | 2017-12-13 19:22:16 +0000 | [diff] [blame^] | 15 | import subprocess |
| 16 | |
| 17 | |
Hector Dearman | 534765e | 2017-11-01 11:17:38 +0000 | [diff] [blame] | 18 | def CheckChange(input, output): |
Sami Kyostila | b27619f | 2017-12-13 19:22:16 +0000 | [diff] [blame^] | 19 | # 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 Dearman | 534765e | 2017-11-01 11:17:38 +0000 | [diff] [blame] | 24 | results = [] |
| 25 | results += input.canned_checks.CheckDoNotSubmit(input, output) |
| 26 | results += input.canned_checks.CheckChangeHasNoTabs(input, output) |
Sami Kyostila | b27619f | 2017-12-13 19:22:16 +0000 | [diff] [blame^] | 27 | results += input.canned_checks.CheckLongLines( |
| 28 | input, output, 80, source_file_filter=long_line_sources) |
Hector Dearman | 534765e | 2017-11-01 11:17:38 +0000 | [diff] [blame] | 29 | results += input.canned_checks.CheckPatchFormatted(input, output) |
| 30 | results += input.canned_checks.CheckGNFormatted(input, output) |
Sami Kyostila | b27619f | 2017-12-13 19:22:16 +0000 | [diff] [blame^] | 31 | results += CheckAndroidBlueprint(input, output) |
Hector Dearman | 534765e | 2017-11-01 11:17:38 +0000 | [diff] [blame] | 32 | return results |
| 33 | |
Sami Kyostila | b27619f | 2017-12-13 19:22:16 +0000 | [diff] [blame^] | 34 | |
Hector Dearman | 534765e | 2017-11-01 11:17:38 +0000 | [diff] [blame] | 35 | def CheckChangeOnUpload(input_api, output_api): |
| 36 | return CheckChange(input_api, output_api) |
| 37 | |
Sami Kyostila | b27619f | 2017-12-13 19:22:16 +0000 | [diff] [blame^] | 38 | |
Hector Dearman | 534765e | 2017-11-01 11:17:38 +0000 | [diff] [blame] | 39 | def CheckChangeOnCommit(input_api, output_api): |
| 40 | return CheckChange(input_api, output_api) |
| 41 | |
Sami Kyostila | b27619f | 2017-12-13 19:22:16 +0000 | [diff] [blame^] | 42 | |
| 43 | def 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 [] |