blob: d911b2bfa2fabe15b8667575da035bdb4b6b5a80 [file] [log] [blame]
# Copyright 2024 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from recipe_engine import recipe_api
class RollerConfiguratorApi(recipe_api.RecipeApi):
def validate(self, path_to_text_proto=None):
"""Validate a rollers.textproto file."""
subcommand = "validate"
args = [subcommand]
if path_to_text_proto:
args.append("--config")
args.append(path_to_text_proto)
try:
return self._run(
subcommand,
args,
stdout=self.m.raw_io.output_text(add_output_log=True),
)
except self.m.step.StepFailure as step_failure:
raise self.m.step.StepFailure("the rollers.textproto is incorrect")
def resolve(self, output_path, path_to_text_proto=None):
"""Process a rollers.textproto file.
Produces a corresponding JSON file at `output_path` with implicit values
filled in.
"""
subcommand = "resolve"
args = [subcommand]
if path_to_text_proto:
args.append("--config")
args.append(path_to_text_proto)
return self._run(
subcommand,
args,
stdout=self.m.raw_io.output_text(add_output_log=True, leak_to=output_path),
)
def _run(self, name, args, **kwargs):
return self.m.step(name, [self._roller_configuration_tool] + args, **kwargs)
@property
def _roller_configuration_tool(self):
return self.m.cipd_ensure(
self.resource("cipd.ensure"),
"fuchsia/infra/roller-configurator/${platform}",
)