blob: 6d1fbf1bd6cfcd39d49fb3fafd2e949adac77578 [file] [log] [blame]
Rob Mohrdd2f30c2022-12-06 14:25:16 +00001# 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 Mohr2f31ceb2024-08-13 19:17:44 +000016from __future__ import annotations
17
Rob Mohr86531542024-08-13 19:33:21 +000018from typing import TYPE_CHECKING
19
Rob Mohrdd2f30c2022-12-06 14:25:16 +000020from recipe_engine import recipe_api
21
Rob Mohr86531542024-08-13 19:33:21 +000022if TYPE_CHECKING: # pragma: no cover
23 from PB.recipe_modules.pigweed.pipeline import properties as properties_pb2
Rob Mohr796c8052023-11-13 17:10:33 +000024
Rob Mohrdd2f30c2022-12-06 14:25:16 +000025
26class PipelineApi(recipe_api.RecipeApi):
27 """Calls to build code."""
28
Rob Mohr796c8052023-11-13 17:10:33 +000029 def __init__(self, props: properties_pb2.InputProperties, *args, **kwargs):
Rob Mohrdd2f30c2022-12-06 14:25:16 +000030 super().__init__(*args, **kwargs)
Rob Mohr796c8052023-11-13 17:10:33 +000031 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 Mohrdd2f30c2022-12-06 14:25:16 +000036
37 @property
Rob Mohr796c8052023-11-13 17:10:33 +000038 def in_pipeline(self) -> bool:
Rob Mohrdd2f30c2022-12-06 14:25:16 +000039 return self._enabled
40
41 @property
Rob Mohr796c8052023-11-13 17:10:33 +000042 def round(self) -> int:
Rob Mohrdd2f30c2022-12-06 14:25:16 +000043 return self._round if self._enabled else None
44
45 @property
Rob Mohr796c8052023-11-13 17:10:33 +000046 def builds_from_previous_iteration(self) -> tuple[str, ...]:
Rob Mohrdd2f30c2022-12-06 14:25:16 +000047 return tuple(self._prev_iteration_builds) if self._enabled else None