| # 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.""" |
| |
| # Tool location: google3/turquoise/infra/foundation/go/submodule_update/ |
| |
| 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 (Path): Path for input as JSON. |
| Need to pass all available flags in integration_update to json: |
| google3/turquoise/infra/foundation/go/submodule_update/integration_update.go |
| |
| |
| Returns: |
| TODO(yupingz): Add return json file containing submodules that needed updating. |
| """ |
| args = [ |
| "integration_update", |
| "-json-input", |
| json_input, |
| "-json-output", |
| self.m.json.output(), |
| ] |
| if no_commit: |
| args.append("-no-commit") |
| return self._run(step_name, args).json.output |
| |
| def submodule_update(self, step_name, json_input): |
| """Update corresponding submodules. |
| |
| Args: |
| step_name (str): Name of the step. |
| json_input (Path): Path for input as JSON. |
| Need to pass all available flags in submodule_update to json: |
| google3/turquoise/infra/foundation/go/submodule_update/submodule_update.go |
| |
| Returns: |
| TODO(yupingz): Add return json file of submodules that have been updated. |
| """ |
| args = [ |
| "submodule_update", |
| "-json-input", |
| json_input, |
| "-json-output", |
| self.m.json.output(), |
| ] |
| return self._run(step_name, args).json.output |
| |
| @property |
| def _submodule_update_tool(self): |
| return self.m.ensure_tool( |
| "submodule_update", self.resource("tool_manifest.json") |
| ) |
| |
| def _run(self, step_name, args): |
| return self.m.step(step_name, [self._submodule_update_tool] + args) |