blob: 238f755662ef50ad8448abe6baf20e5b169f893e [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
Mike Frysinger1cc8f1f2022-04-28 22:40:40 -040015
Alex Klein104b0672019-06-28 15:43:00 -060016# API version number.
17# The major version MUST be updated on breaking changes.
18VERSION_MAJOR = 1
19# The minor and bug versions are not currently utilized, but put in place
20# to simplify future requirements.
21VERSION_MINOR = 0
22VERSION_BUG = 0
23
Alex Klein54e38e32019-06-21 14:54:17 -060024
Alex Kleinf725e102021-02-19 15:48:54 -070025def _CompileProtoSuccess(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -060026 """Mock success response for CompileProto."""
27 output_proto.modified_files.add().path = "/code/chromite/api/gen/foo_pb2.py"
Alex Kleinf725e102021-02-19 15:48:54 -070028
29
30@faux.success(_CompileProtoSuccess)
31@faux.empty_error
32@validate.validation_complete
Alex Klein5dffe5e2021-02-19 15:50:00 -070033def CompileProto(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -060034 """Compile the Build API proto, returning the list of modified files."""
35 cmd = [
36 os.path.join(constants.CHROMITE_DIR, "api", "compile_build_api_proto")
37 ]
38 cros_build_lib.run(cmd)
39 result = cros_build_lib.run(
40 ["git", "status", "--porcelain=v1"],
41 cwd=constants.CHROMITE_DIR,
42 capture_output=True,
43 encoding="utf-8",
44 )
45 for line in result.stdout.splitlines():
46 if not line:
47 continue
48 path = line.split()[-1]
49 output_proto.modified_files.add().path = os.path.join(
50 constants.CHROMITE_DIR, path
51 )
Alex Kleinf725e102021-02-19 15:48:54 -070052
53
Alex Klein076841b2019-08-29 15:19:39 -060054@faux.all_empty
Alex Klein231d2da2019-07-22 16:44:45 -060055@validate.validation_complete
56def GetMethods(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -060057 """List all of the registered methods."""
58 router = router_lib.GetRouter()
59 for method in router.ListMethods():
60 output_proto.methods.add().method = method
Alex Klein104b0672019-06-28 15:43:00 -060061
62
Alex Klein231d2da2019-07-22 16:44:45 -060063@validate.validation_complete
64def GetVersion(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -060065 """Get the Build API major version number."""
66 output_proto.version.major = VERSION_MAJOR
67 output_proto.version.minor = VERSION_MINOR
68 output_proto.version.bug = VERSION_BUG