Alex Klein | 54e38e3 | 2019-06-21 14:54:17 -0600 | [diff] [blame] | 1 | # 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 Klein | 5dffe5e | 2021-02-19 15:50:00 -0700 | [diff] [blame] | 7 | import os |
| 8 | |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 9 | from chromite.api import faux |
Alex Klein | 54e38e3 | 2019-06-21 14:54:17 -0600 | [diff] [blame] | 10 | from chromite.api import router as router_lib |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 11 | from chromite.api import validate |
Alex Klein | 5dffe5e | 2021-02-19 15:50:00 -0700 | [diff] [blame] | 12 | from chromite.lib import constants |
| 13 | from chromite.lib import cros_build_lib |
Alex Klein | 54e38e3 | 2019-06-21 14:54:17 -0600 | [diff] [blame] | 14 | |
Alex Klein | 104b067 | 2019-06-28 15:43:00 -0600 | [diff] [blame] | 15 | # API version number. |
| 16 | # The major version MUST be updated on breaking changes. |
| 17 | VERSION_MAJOR = 1 |
| 18 | # The minor and bug versions are not currently utilized, but put in place |
| 19 | # to simplify future requirements. |
| 20 | VERSION_MINOR = 0 |
| 21 | VERSION_BUG = 0 |
| 22 | |
Alex Klein | 54e38e3 | 2019-06-21 14:54:17 -0600 | [diff] [blame] | 23 | |
Alex Klein | f725e10 | 2021-02-19 15:48:54 -0700 | [diff] [blame] | 24 | def _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 Klein | 5dffe5e | 2021-02-19 15:50:00 -0700 | [diff] [blame] | 32 | def CompileProto(_input_proto, output_proto, _config): |
Alex Klein | f725e10 | 2021-02-19 15:48:54 -0700 | [diff] [blame] | 33 | """Compile the Build API proto, returning the list of modified files.""" |
Alex Klein | 5dffe5e | 2021-02-19 15:50:00 -0700 | [diff] [blame] | 34 | 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 Klein | f725e10 | 2021-02-19 15:48:54 -0700 | [diff] [blame] | 45 | |
| 46 | |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 47 | @faux.all_empty |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 48 | @validate.validation_complete |
| 49 | def GetMethods(_input_proto, output_proto, _config): |
Alex Klein | 54e38e3 | 2019-06-21 14:54:17 -0600 | [diff] [blame] | 50 | """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 Klein | 104b067 | 2019-06-28 15:43:00 -0600 | [diff] [blame] | 54 | |
| 55 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 56 | @validate.validation_complete |
| 57 | def GetVersion(_input_proto, output_proto, _config): |
Alex Klein | 104b067 | 2019-06-28 15:43:00 -0600 | [diff] [blame] | 58 | """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 |