Mike Frysinger | f1ba7ad | 2022-09-12 05:42:57 -0400 | [diff] [blame] | 1 | # Copyright 2019 The ChromiumOS Authors |
Alex Klein | 54e38e3 | 2019-06-21 14:54:17 -0600 | [diff] [blame] | 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 Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 7 | from chromite.api import faux |
Alex Klein | 54e38e3 | 2019-06-21 14:54:17 -0600 | [diff] [blame] | 8 | from chromite.api import router as router_lib |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 9 | from chromite.api import validate |
Alex Klein | 5dffe5e | 2021-02-19 15:50:00 -0700 | [diff] [blame] | 10 | from chromite.lib import constants |
| 11 | from chromite.lib import cros_build_lib |
Alex Klein | 54e38e3 | 2019-06-21 14:54:17 -0600 | [diff] [blame] | 12 | |
Mike Frysinger | 1cc8f1f | 2022-04-28 22:40:40 -0400 | [diff] [blame] | 13 | |
Alex Klein | 104b067 | 2019-06-28 15:43:00 -0600 | [diff] [blame] | 14 | # API version number. |
| 15 | # The major version MUST be updated on breaking changes. |
| 16 | VERSION_MAJOR = 1 |
| 17 | # The minor and bug versions are not currently utilized, but put in place |
| 18 | # to simplify future requirements. |
| 19 | VERSION_MINOR = 0 |
| 20 | VERSION_BUG = 0 |
| 21 | |
Alex Klein | 54e38e3 | 2019-06-21 14:54:17 -0600 | [diff] [blame] | 22 | |
Alex Klein | f725e10 | 2021-02-19 15:48:54 -0700 | [diff] [blame] | 23 | def _CompileProtoSuccess(_input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 24 | """Mock success response for CompileProto.""" |
| 25 | output_proto.modified_files.add().path = "/code/chromite/api/gen/foo_pb2.py" |
Alex Klein | f725e10 | 2021-02-19 15:48:54 -0700 | [diff] [blame] | 26 | |
| 27 | |
| 28 | @faux.success(_CompileProtoSuccess) |
| 29 | @faux.empty_error |
| 30 | @validate.validation_complete |
Alex Klein | 5dffe5e | 2021-02-19 15:50:00 -0700 | [diff] [blame] | 31 | def CompileProto(_input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 32 | """Compile the Build API proto, returning the list of modified files.""" |
Mike Frysinger | a69df98 | 2023-03-21 16:52:27 -0400 | [diff] [blame] | 33 | cmd = [constants.CHROMITE_DIR / "api" / "compile_build_api_proto"] |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 34 | 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 Frysinger | a69df98 | 2023-03-21 16:52:27 -0400 | [diff] [blame] | 45 | output_proto.modified_files.add().path = str( |
| 46 | constants.CHROMITE_DIR / path |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 47 | ) |
Alex Klein | f725e10 | 2021-02-19 15:48:54 -0700 | [diff] [blame] | 48 | |
| 49 | |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 50 | @faux.all_empty |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 51 | @validate.validation_complete |
| 52 | def GetMethods(_input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 53 | """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 Klein | 104b067 | 2019-06-28 15:43:00 -0600 | [diff] [blame] | 57 | |
| 58 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 59 | @validate.validation_complete |
| 60 | def GetVersion(_input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 61 | """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 |