Primiano Tucci | 34bc559 | 2021-02-19 17:53:36 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Hector Dearman | 7e07977 | 2018-11-15 16:08:12 +0000 | [diff] [blame] | 2 | # Copyright (C) 2018 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
Matthew Clarkson | 9a5dfa5 | 2019-10-03 09:54:04 +0100 | [diff] [blame] | 16 | from __future__ import print_function |
Primiano Tucci | eac5d71 | 2021-05-18 20:45:05 +0100 | [diff] [blame] | 17 | |
Hector Dearman | 7e07977 | 2018-11-15 16:08:12 +0000 | [diff] [blame] | 18 | import os |
| 19 | import argparse |
| 20 | import subprocess |
Primiano Tucci | eac5d71 | 2021-05-18 20:45:05 +0100 | [diff] [blame] | 21 | import sys |
Hector Dearman | 7e07977 | 2018-11-15 16:08:12 +0000 | [diff] [blame] | 22 | |
| 23 | ROOT_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) |
Primiano Tucci | eac5d71 | 2021-05-18 20:45:05 +0100 | [diff] [blame] | 24 | IS_WIN = sys.platform.startswith('win') |
Hector Dearman | 7e07977 | 2018-11-15 16:08:12 +0000 | [diff] [blame] | 25 | |
| 26 | |
| 27 | def protoc_path(out_directory): |
Primiano Tucci | eac5d71 | 2021-05-18 20:45:05 +0100 | [diff] [blame] | 28 | path = os.path.join(out_directory, 'protoc') + ('.exe' if IS_WIN else '') |
Hector Dearman | 7e07977 | 2018-11-15 16:08:12 +0000 | [diff] [blame] | 29 | assert os.path.isfile(path) |
| 30 | return path |
| 31 | |
| 32 | |
Sami Kyostila | f15f3f6 | 2019-08-09 11:00:29 +0100 | [diff] [blame] | 33 | def call(cmd, *args): |
Hector Dearman | 7e07977 | 2018-11-15 16:08:12 +0000 | [diff] [blame] | 34 | path = os.path.join('tools', cmd) |
Primiano Tucci | eac5d71 | 2021-05-18 20:45:05 +0100 | [diff] [blame] | 35 | command = ['python3', path] + list(args) |
Matthew Clarkson | 9a5dfa5 | 2019-10-03 09:54:04 +0100 | [diff] [blame] | 36 | print('Running', ' '.join(command)) |
Hector Dearman | 7e07977 | 2018-11-15 16:08:12 +0000 | [diff] [blame] | 37 | try: |
Primiano Tucci | 2854a0a | 2019-06-03 14:51:18 +0100 | [diff] [blame] | 38 | subprocess.check_call(command, cwd=ROOT_DIR) |
Hector Dearman | 7e07977 | 2018-11-15 16:08:12 +0000 | [diff] [blame] | 39 | except subprocess.CalledProcessError as e: |
| 40 | assert False, 'Command: {} failed'.format(' '.join(command)) |
| 41 | |
| 42 | |
| 43 | def main(): |
| 44 | parser = argparse.ArgumentParser() |
Primiano Tucci | 561ba7e | 2019-10-10 21:23:11 +0100 | [diff] [blame] | 45 | parser.add_argument('--check-only', default=False, action='store_true') |
Hector Dearman | 7e07977 | 2018-11-15 16:08:12 +0000 | [diff] [blame] | 46 | parser.add_argument('OUT') |
| 47 | args = parser.parse_args() |
| 48 | out = args.OUT |
| 49 | |
| 50 | try: |
| 51 | assert os.path.isdir(out), \ |
| 52 | 'Output directory "{}" is not a directory'.format(out) |
Primiano Tucci | 561ba7e | 2019-10-10 21:23:11 +0100 | [diff] [blame] | 53 | check_only = ['--check-only'] if args.check_only else [] |
| 54 | call('check_include_violations') |
Anindita Ghosh | 2aa4e42 | 2020-06-26 15:48:32 +0100 | [diff] [blame] | 55 | call('check_proto_comments') |
Primiano Tucci | 561ba7e | 2019-10-10 21:23:11 +0100 | [diff] [blame] | 56 | call('fix_include_guards', *check_only) |
Primiano Tucci | eac5d71 | 2021-05-18 20:45:05 +0100 | [diff] [blame] | 57 | if not IS_WIN: |
| 58 | call('gen_bazel', *check_only) |
| 59 | call('gen_android_bp', *check_only) |
Primiano Tucci | 561ba7e | 2019-10-10 21:23:11 +0100 | [diff] [blame] | 60 | call('gen_merged_protos', *check_only) |
Primiano Tucci | f33540e | 2019-09-19 12:35:57 +0100 | [diff] [blame] | 61 | call('ninja', '-C', out, 'protoc') |
Primiano Tucci | 561ba7e | 2019-10-10 21:23:11 +0100 | [diff] [blame] | 62 | call('gen_binary_descriptors', '--protoc', protoc_path(out), *check_only) |
| 63 | |
Primiano Tucci | eac5d71 | 2021-05-18 20:45:05 +0100 | [diff] [blame] | 64 | if IS_WIN: |
| 65 | print('WARNING: Cannot generate BUILD / Android.bp from Windows. ' + |
| 66 | 'They might be left stale and fail in the CI if you edited any ' + |
| 67 | 'BUILD.gn file') |
| 68 | |
Hector Dearman | 7e07977 | 2018-11-15 16:08:12 +0000 | [diff] [blame] | 69 | except AssertionError as e: |
| 70 | if not str(e): |
| 71 | raise |
| 72 | print('Error: {}'.format(e)) |
| 73 | return 1 |
| 74 | |
| 75 | return 0 |
| 76 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 77 | |
Hector Dearman | 7e07977 | 2018-11-15 16:08:12 +0000 | [diff] [blame] | 78 | if __name__ == '__main__': |
| 79 | exit(main()) |