Alex Klein | f4dc4f5 | 2018-12-05 13:55:12 -0700 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | # Copyright 2018 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """Compile the Build API's proto.""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | |
| 10 | import os |
| 11 | |
| 12 | from chromite.lib import commandline |
| 13 | from chromite.lib import cros_build_lib |
| 14 | |
| 15 | |
| 16 | def GetParser(): |
| 17 | parser = commandline.ArgumentParser(description=__doc__) |
| 18 | return parser |
| 19 | |
| 20 | |
| 21 | def _ParseArguments(argv): |
| 22 | """Parse and validate arguments.""" |
| 23 | parser = GetParser() |
| 24 | opts = parser.parse_args(argv) |
| 25 | |
| 26 | opts.Freeze() |
| 27 | return opts |
| 28 | |
| 29 | |
| 30 | def main(argv): |
| 31 | _opts = _ParseArguments(argv) |
| 32 | |
| 33 | base_dir = os.path.abspath(os.path.join(__file__, '..')) |
| 34 | output = os.path.join(base_dir, 'gen') |
| 35 | source = os.path.join(base_dir, 'proto') |
| 36 | targets = os.path.join(source, '*.proto') |
| 37 | |
| 38 | cmd = ('protoc --python_out %(output)s --proto_path %(source)s %(targets)s' |
| 39 | % {'output': output, 'source': source, 'targets': targets}) |
| 40 | |
| 41 | result = cros_build_lib.RunCommand(cmd, shell=True, error_code_ok=True) |
| 42 | return result.returncode |