| # Copyright 2021 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 SubmoduleUpdateApi(recipe_api.RecipeApi): |
| """APIs for updating submodules across projects.""" |
| |
| def integration_update(self, step_name, json_input, no_commit=False): |
| """Find submodules that need updating. |
| |
| Args: |
| step_name (str): Name of the step. |
| json_input (dict): Input as JSON. |
| """ |
| args = [ |
| "integration_update", |
| "-json-input", |
| self.m.json.input(json_input), |
| "-json-output", |
| self.m.json.output(), |
| ] |
| if no_commit: |
| args.append("-no-commit") |
| |
| step = None |
| try: |
| step = self._run(step_name, args) |
| except self.m.step.StepFailure as e: |
| step = e.result |
| raise |
| finally: |
| if step: |
| step.presentation.logs["json input"] = self.m.json.dumps( |
| json_input, indent=2 |
| ) |
| return step.json.output |
| |
| @property |
| def _submodule_update_tool(self): |
| return self.m.cipd_ensure( |
| self.resource("cipd.ensure"), |
| "fuchsia/infra/submodule_update/${platform}", |
| ) |
| |
| def _run(self, step_name, args): |
| return self.m.step(step_name, [self._submodule_update_tool] + args) |