blob: 3fc527c226e80136f42bc53d1cf1f86923f9d240 [file] [log] [blame]
Alex Kleinf4dc4f52018-12-05 13:55:12 -07001# -*- 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
8from __future__ import print_function
9
10import os
11
12from chromite.lib import commandline
13from chromite.lib import cros_build_lib
14
15
16def GetParser():
17 parser = commandline.ArgumentParser(description=__doc__)
18 return parser
19
20
21def _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
30def 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