| # Copyright 2018 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 google.protobuf import text_format |
| |
| from recipe_engine import recipe_api |
| |
| from PB.infra.fuchsia import Fuchsia |
| |
| |
| class FuchsiaApi(recipe_api.RecipeApi): |
| """APIs for checking out, building, and testing Fuchsia.""" |
| |
| def setup(self): |
| """Resolve the build input to always contain a Gitiles commit.""" |
| self.m.build_input_resolver.resolve( |
| default_project_url="https://fuchsia.googlesource.com/fuchsia" |
| ) |
| |
| def setup_with_spec(self, spec_remote, spec_revision=None): |
| """Runs the steps required before checking out Fuchsia code from a spec. |
| |
| These steps include resolving the build input gitiles commit and loading |
| the specified spec. |
| |
| Returns the spec and spec_revision. |
| """ |
| self.setup() |
| bb_input = self.m.buildbucket.build_input |
| commit_remote = "https://%s/%s" % ( |
| bb_input.gitiles_commit.host, |
| bb_input.gitiles_commit.project, |
| ) |
| if commit_remote == spec_remote: |
| # If the spec_revision was not resolved, use the revision that we |
| # resolved immediately above. |
| if not spec_revision: |
| spec_revision = bb_input.gitiles_commit.id |
| # Otherwise the spec_revision was specified, and we want all |
| # accesses to that remote to use that revision. In this case, |
| # build_input_resolver.resolve() is unnecessary since we overwrite the |
| # revision, but we only use it to pre-populate the gitiles_commit of the |
| # build input and to keep the conditional logic simpler. |
| else: |
| bb_input.gitiles_commit.id = spec_revision |
| |
| with self.m.step.nest("load spec") as presentation: |
| try: |
| spec, spec_revision = self.m.spec.get_spec_revision( |
| spec_remote=spec_remote, |
| Type=Fuchsia, |
| spec_revision=spec_revision, |
| ) |
| except self.m.spec.ParseError as e: |
| raise self.m.step.StepFailure("failed to parse spec: %s" % str(e)) |
| |
| presentation.logs["textproto"] = text_format.MessageToString(spec).split( |
| "\n" |
| ) |
| # The following tools depend on this property: |
| # * fuchsia.googlesource.com/infra/infra/+/main/cmd/artifacts |
| presentation.properties["gcs_bucket"] = spec.gcs_bucket |
| |
| # The following tools depend on this property: |
| # * fuchsia.googlesource.com/infra/infra/+/main/cmd/artifacts |
| # * bisect-tool |
| presentation.properties["artifact_gcs_bucket"] = spec.artifact_gcs_bucket |
| return spec, spec_revision |