Build API: foundations

The foundations for the build api; the entrypoint itself, a common proto
definitions file, a script to compile the proto, and some scaffolding
to build out requests.

BUG=chromium:912361
TEST=manual, new tests
CQ-DEPEND=CL:1382945

Change-Id: Id3c8ae67b1d8f198f563977fe9c8543af7f41d9a
Reviewed-on: https://chromium-review.googlesource.com/1373996
Commit-Ready: Alex Klein <saklein@chromium.org>
Tested-by: Alex Klein <saklein@chromium.org>
Reviewed-by: Lann Martin <lannm@chromium.org>
diff --git a/api/compile_build_api_proto.py b/api/compile_build_api_proto.py
new file mode 100644
index 0000000..3fc527c
--- /dev/null
+++ b/api/compile_build_api_proto.py
@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*-
+# Copyright 2018 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Compile the Build API's proto."""
+
+from __future__ import print_function
+
+import os
+
+from chromite.lib import commandline
+from chromite.lib import cros_build_lib
+
+
+def GetParser():
+  parser = commandline.ArgumentParser(description=__doc__)
+  return parser
+
+
+def _ParseArguments(argv):
+  """Parse and validate arguments."""
+  parser = GetParser()
+  opts = parser.parse_args(argv)
+
+  opts.Freeze()
+  return opts
+
+
+def main(argv):
+  _opts = _ParseArguments(argv)
+
+  base_dir = os.path.abspath(os.path.join(__file__, '..'))
+  output = os.path.join(base_dir, 'gen')
+  source = os.path.join(base_dir, 'proto')
+  targets = os.path.join(source, '*.proto')
+
+  cmd = ('protoc --python_out %(output)s --proto_path %(source)s %(targets)s'
+         % {'output': output, 'source': source, 'targets': targets})
+
+  result = cros_build_lib.RunCommand(cmd, shell=True, error_code_ok=True)
+  return result.returncode