blob: 1123fdbe3983d86256913b48c70cc42a6f399229 [file] [log] [blame]
Alex Klein54e38e32019-06-21 14:54:17 -06001# -*- coding: utf-8 -*-
2# Copyright 2019 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"""API information controller."""
7
8from __future__ import print_function
9
Alex Klein5dffe5e2021-02-19 15:50:00 -070010import os
11
Alex Klein076841b2019-08-29 15:19:39 -060012from chromite.api import faux
Alex Klein54e38e32019-06-21 14:54:17 -060013from chromite.api import router as router_lib
Alex Klein231d2da2019-07-22 16:44:45 -060014from chromite.api import validate
Alex Klein5dffe5e2021-02-19 15:50:00 -070015from chromite.lib import constants
16from chromite.lib import cros_build_lib
Alex Klein54e38e32019-06-21 14:54:17 -060017
Alex Klein104b0672019-06-28 15:43:00 -060018# API version number.
19# The major version MUST be updated on breaking changes.
20VERSION_MAJOR = 1
21# The minor and bug versions are not currently utilized, but put in place
22# to simplify future requirements.
23VERSION_MINOR = 0
24VERSION_BUG = 0
25
Alex Klein54e38e32019-06-21 14:54:17 -060026
Alex Kleinf725e102021-02-19 15:48:54 -070027def _CompileProtoSuccess(_input_proto, output_proto, _config):
28 """Mock success response for CompileProto."""
29 output_proto.modified_files.add().path = '/code/chromite/api/gen/foo_pb2.py'
30
31
32@faux.success(_CompileProtoSuccess)
33@faux.empty_error
34@validate.validation_complete
Alex Klein5dffe5e2021-02-19 15:50:00 -070035def CompileProto(_input_proto, output_proto, _config):
Alex Kleinf725e102021-02-19 15:48:54 -070036 """Compile the Build API proto, returning the list of modified files."""
Alex Klein5dffe5e2021-02-19 15:50:00 -070037 cmd = [os.path.join(constants.CHROMITE_DIR, 'api', 'compile_build_api_proto')]
38 cros_build_lib.run(cmd)
39 result = cros_build_lib.run(['git', 'status', '--porcelain=v1'],
40 cwd=constants.CHROMITE_DIR, capture_output=True,
41 encoding='utf-8')
42 for line in result.stdout.splitlines():
43 if not line:
44 continue
45 path = line.split()[-1]
46 output_proto.modified_files.add().path = os.path.join(
47 constants.CHROMITE_DIR, path)
Alex Kleinf725e102021-02-19 15:48:54 -070048
49
Alex Klein076841b2019-08-29 15:19:39 -060050@faux.all_empty
Alex Klein231d2da2019-07-22 16:44:45 -060051@validate.validation_complete
52def GetMethods(_input_proto, output_proto, _config):
Alex Klein54e38e32019-06-21 14:54:17 -060053 """List all of the registered methods."""
54 router = router_lib.GetRouter()
55 for method in router.ListMethods():
56 output_proto.methods.add().method = method
Alex Klein104b0672019-06-28 15:43:00 -060057
58
Alex Klein231d2da2019-07-22 16:44:45 -060059@validate.validation_complete
60def GetVersion(_input_proto, output_proto, _config):
Alex Klein104b0672019-06-28 15:43:00 -060061 """Get the Build API major version number."""
62 output_proto.version.major = VERSION_MAJOR
63 output_proto.version.minor = VERSION_MINOR
64 output_proto.version.bug = VERSION_BUG