Rob Mohr | dd2f30c | 2022-12-06 14:25:16 +0000 | [diff] [blame] | 1 | # Copyright 2022 The Pigweed Authors |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 4 | # use this file except in compliance with the License. You may obtain a copy of |
| 5 | # the License at |
| 6 | # |
| 7 | # https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations under |
| 13 | # the License. |
| 14 | """Calls to build code.""" |
| 15 | |
Rob Mohr | 2f31ceb | 2024-08-13 19:17:44 +0000 | [diff] [blame] | 16 | from __future__ import annotations |
| 17 | |
Rob Mohr | 8653154 | 2024-08-13 19:33:21 +0000 | [diff] [blame] | 18 | from typing import TYPE_CHECKING |
| 19 | |
Rob Mohr | dd2f30c | 2022-12-06 14:25:16 +0000 | [diff] [blame] | 20 | from recipe_engine import recipe_api |
| 21 | |
Rob Mohr | 8653154 | 2024-08-13 19:33:21 +0000 | [diff] [blame] | 22 | if TYPE_CHECKING: # pragma: no cover |
| 23 | from PB.recipe_modules.pigweed.pipeline import properties as properties_pb2 |
Rob Mohr | 796c805 | 2023-11-13 17:10:33 +0000 | [diff] [blame] | 24 | |
Rob Mohr | dd2f30c | 2022-12-06 14:25:16 +0000 | [diff] [blame] | 25 | |
| 26 | class PipelineApi(recipe_api.RecipeApi): |
| 27 | """Calls to build code.""" |
| 28 | |
Rob Mohr | 796c805 | 2023-11-13 17:10:33 +0000 | [diff] [blame] | 29 | def __init__(self, props: properties_pb2.InputProperties, *args, **kwargs): |
Rob Mohr | dd2f30c | 2022-12-06 14:25:16 +0000 | [diff] [blame] | 30 | super().__init__(*args, **kwargs) |
Rob Mohr | 796c805 | 2023-11-13 17:10:33 +0000 | [diff] [blame] | 31 | self._enabled: bool = props.inside_a_pipeline |
| 32 | self._round: int = props.round |
| 33 | self._prev_iteration_builds: tuple[str, ...] = tuple( |
| 34 | props.builds_from_previous_iteration |
| 35 | ) |
Rob Mohr | dd2f30c | 2022-12-06 14:25:16 +0000 | [diff] [blame] | 36 | |
| 37 | @property |
Rob Mohr | 796c805 | 2023-11-13 17:10:33 +0000 | [diff] [blame] | 38 | def in_pipeline(self) -> bool: |
Rob Mohr | dd2f30c | 2022-12-06 14:25:16 +0000 | [diff] [blame] | 39 | return self._enabled |
| 40 | |
| 41 | @property |
Rob Mohr | 796c805 | 2023-11-13 17:10:33 +0000 | [diff] [blame] | 42 | def round(self) -> int: |
Rob Mohr | dd2f30c | 2022-12-06 14:25:16 +0000 | [diff] [blame] | 43 | return self._round if self._enabled else None |
| 44 | |
| 45 | @property |
Rob Mohr | 796c805 | 2023-11-13 17:10:33 +0000 | [diff] [blame] | 46 | def builds_from_previous_iteration(self) -> tuple[str, ...]: |
Rob Mohr | dd2f30c | 2022-12-06 14:25:16 +0000 | [diff] [blame] | 47 | return tuple(self._prev_iteration_builds) if self._enabled else None |