• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
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
16from __future__ import print_function
17import os
18import argparse
19import subprocess
20
21ROOT_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
22
23
24def protoc_path(out_directory):
25  path = os.path.join(out_directory, 'protoc')
26  assert os.path.isfile(path)
27  return path
28
29
30def call(cmd, *args):
31  path = os.path.join('tools', cmd)
32  command = [path] + list(args)
33  print('Running', ' '.join(command))
34  try:
35    subprocess.check_call(command, cwd=ROOT_DIR)
36  except subprocess.CalledProcessError as e:
37    assert False, 'Command: {} failed'.format(' '.join(command))
38
39
40def main():
41  parser = argparse.ArgumentParser()
42  parser.add_argument('--check-only', default=False, action='store_true')
43  parser.add_argument('OUT')
44  args = parser.parse_args()
45  out = args.OUT
46
47  try:
48    assert os.path.isdir(out), \
49        'Output directory "{}" is not a directory'.format(out)
50    check_only = ['--check-only'] if args.check_only else []
51    call('check_include_violations')
52    call('check_proto_comments')
53    call('fix_include_guards', *check_only)
54    call('gen_bazel', *check_only)
55    call('gen_android_bp', *check_only)
56    call('gen_merged_protos', *check_only)
57    call('ninja', '-C', out, 'protoc')
58    call('gen_binary_descriptors', '--protoc', protoc_path(out), *check_only)
59
60  except AssertionError as e:
61    if not str(e):
62      raise
63    print('Error: {}'.format(e))
64    return 1
65
66  return 0
67
68
69if __name__ == '__main__':
70  exit(main())
71