blob: 2a1456fadbdc42dbf330d7f8bf459f8b3ce4d38a [file] [log] [blame]
Alex Klein54e38e32019-06-21 14:54:17 -06001# Copyright 2019 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""API information controller."""
6
Alex Klein5dffe5e2021-02-19 15:50:00 -07007import os
8
Alex Klein076841b2019-08-29 15:19:39 -06009from chromite.api import faux
Alex Klein54e38e32019-06-21 14:54:17 -060010from chromite.api import router as router_lib
Alex Klein231d2da2019-07-22 16:44:45 -060011from chromite.api import validate
Alex Klein5dffe5e2021-02-19 15:50:00 -070012from chromite.lib import constants
13from chromite.lib import cros_build_lib
Alex Klein54e38e32019-06-21 14:54:17 -060014
Alex Klein104b0672019-06-28 15:43:00 -060015# API version number.
16# The major version MUST be updated on breaking changes.
17VERSION_MAJOR = 1
18# The minor and bug versions are not currently utilized, but put in place
19# to simplify future requirements.
20VERSION_MINOR = 0
21VERSION_BUG = 0
22
Alex Klein54e38e32019-06-21 14:54:17 -060023
Alex Kleinf725e102021-02-19 15:48:54 -070024def _CompileProtoSuccess(_input_proto, output_proto, _config):
25 """Mock success response for CompileProto."""
26 output_proto.modified_files.add().path = '/code/chromite/api/gen/foo_pb2.py'
27
28
29@faux.success(_CompileProtoSuccess)
30@faux.empty_error
31@validate.validation_complete
Alex Klein5dffe5e2021-02-19 15:50:00 -070032def CompileProto(_input_proto, output_proto, _config):
Alex Kleinf725e102021-02-19 15:48:54 -070033 """Compile the Build API proto, returning the list of modified files."""
Alex Klein5dffe5e2021-02-19 15:50:00 -070034 cmd = [os.path.join(constants.CHROMITE_DIR, 'api', 'compile_build_api_proto')]
35 cros_build_lib.run(cmd)
36 result = cros_build_lib.run(['git', 'status', '--porcelain=v1'],
37 cwd=constants.CHROMITE_DIR, capture_output=True,
38 encoding='utf-8')
39 for line in result.stdout.splitlines():
40 if not line:
41 continue
42 path = line.split()[-1]
43 output_proto.modified_files.add().path = os.path.join(
44 constants.CHROMITE_DIR, path)
Alex Kleinf725e102021-02-19 15:48:54 -070045
46
Alex Klein076841b2019-08-29 15:19:39 -060047@faux.all_empty
Alex Klein231d2da2019-07-22 16:44:45 -060048@validate.validation_complete
49def GetMethods(_input_proto, output_proto, _config):
Alex Klein54e38e32019-06-21 14:54:17 -060050 """List all of the registered methods."""
51 router = router_lib.GetRouter()
52 for method in router.ListMethods():
53 output_proto.methods.add().method = method
Alex Klein104b0672019-06-28 15:43:00 -060054
55
Alex Klein231d2da2019-07-22 16:44:45 -060056@validate.validation_complete
57def GetVersion(_input_proto, output_proto, _config):
Alex Klein104b0672019-06-28 15:43:00 -060058 """Get the Build API major version number."""
59 output_proto.version.major = VERSION_MAJOR
60 output_proto.version.minor = VERSION_MINOR
61 output_proto.version.bug = VERSION_BUG