blob: 41652c2f2df8af2c91bb7afeb0a1358ccb951e93 [file] [log] [blame]
# Copyright 2022 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 CipdResolverApi(recipe_api.RecipeApi):
"""API for finding common tags from a list of CIPD packages."""
def resolve_common_tags(
self,
ref,
tag_name,
packages,
packages_requiring_ref=(),
step_name="resolve common tags",
):
"""Resolve tags shared by a list of CIPD packages.
This is useful when attempting to resolve a version to which a group of
packages should be rolled, where the packages come from the same source
repo and need to stay in sync to ensure mutual compatibility.
"""
args = [
"resolve",
"-json-output",
self.m.json.output(),
"-verbose",
"-ref",
ref,
"-tag",
tag_name,
]
flexible_packages = [p for p in packages if p not in packages_requiring_ref]
for p in flexible_packages:
args += ["-flexible-pkg", p]
for p in packages_requiring_ref:
args += ["-strict-pkg", p]
# TODO(olivernewman): Bubble an error message up to the build's
# summary_markdown.
return self._run(step_name, args).json.output or []
@property
def _cipd_resolver_tool(self):
return self.m.ensure_tool("cipd-resolver", self.resource("tool_manifest.json"))
def _run(self, step_name, args, **kwargs):
return self.m.step(step_name, [self._cipd_resolver_tool] + args, **kwargs)