blob: ef9641e5526675e8d4f655e385e8e75c70aa744d [file] [log] [blame]
Mike Frysingerf1ba7ad2022-09-12 05:42:57 -04001# Copyright 2019 The ChromiumOS Authors
Alex Klein54e38e32019-06-21 14:54:17 -06002# 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 Klein076841b2019-08-29 15:19:39 -06007from chromite.api import faux
Alex Klein54e38e32019-06-21 14:54:17 -06008from chromite.api import router as router_lib
Alex Klein231d2da2019-07-22 16:44:45 -06009from chromite.api import validate
Alex Klein5dffe5e2021-02-19 15:50:00 -070010from chromite.lib import constants
11from chromite.lib import cros_build_lib
Alex Klein54e38e32019-06-21 14:54:17 -060012
Mike Frysinger1cc8f1f2022-04-28 22:40:40 -040013
Alex Klein104b0672019-06-28 15:43:00 -060014# API version number.
15# The major version MUST be updated on breaking changes.
16VERSION_MAJOR = 1
17# The minor and bug versions are not currently utilized, but put in place
18# to simplify future requirements.
19VERSION_MINOR = 0
20VERSION_BUG = 0
21
Alex Klein54e38e32019-06-21 14:54:17 -060022
Alex Kleinf725e102021-02-19 15:48:54 -070023def _CompileProtoSuccess(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -060024 """Mock success response for CompileProto."""
25 output_proto.modified_files.add().path = "/code/chromite/api/gen/foo_pb2.py"
Alex Kleinf725e102021-02-19 15:48:54 -070026
27
28@faux.success(_CompileProtoSuccess)
29@faux.empty_error
30@validate.validation_complete
Alex Klein5dffe5e2021-02-19 15:50:00 -070031def CompileProto(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -060032 """Compile the Build API proto, returning the list of modified files."""
Mike Frysingera69df982023-03-21 16:52:27 -040033 cmd = [constants.CHROMITE_DIR / "api" / "compile_build_api_proto"]
Alex Klein1699fab2022-09-08 08:46:06 -060034 cros_build_lib.run(cmd)
35 result = cros_build_lib.run(
36 ["git", "status", "--porcelain=v1"],
37 cwd=constants.CHROMITE_DIR,
38 capture_output=True,
39 encoding="utf-8",
40 )
41 for line in result.stdout.splitlines():
42 if not line:
43 continue
44 path = line.split()[-1]
Mike Frysingera69df982023-03-21 16:52:27 -040045 output_proto.modified_files.add().path = str(
46 constants.CHROMITE_DIR / path
Alex Klein1699fab2022-09-08 08:46:06 -060047 )
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 Klein1699fab2022-09-08 08:46:06 -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 Klein1699fab2022-09-08 08:46:06 -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