| # 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_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. |
| """ |
| # Resolve the build input to always contain a Gitiles commit. |
| self.m.build_input_resolver.resolve( |
| default_project_url='https://fuchsia.googlesource.com/fuchsia') |
| 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 there was no parent build, then spec_revision may not have been |
| # resolved, so use the revision that we resolved immediately above. |
| if spec_revision == 'HEAD': |
| spec_revision = bb_input.gitiles_commit.id |
| # Otherwise the spec_revision was specified by the parent, 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 artifacts tool relies on this output property. |
| # This design has been fragile. Please don't add more dependencies on any |
| # additional output properties. |
| presentation.properties['gcs_bucket'] = spec.gcs_bucket |
| return spec, spec_revision |