| # Copyright 2020 The Chromium Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| REPOS = { |
| 'flutter': |
| 'https://chromium.googlesource.com/external/github.com/flutter/flutter', |
| 'engine': |
| 'https://chromium.googlesource.com/external/github.com/flutter/engine', |
| 'cocoon': |
| 'https://chromium.googlesource.com/external/github.com/flutter/cocoon', |
| 'packages': |
| 'https://github.com/flutter/packages', |
| } |
| |
| from recipe_engine import recipe_api |
| |
| |
| class RepoUtilApi(recipe_api.RecipeApi): |
| """Provides utilities to work with flutter repos.""" |
| |
| def engine_checkout(self, checkout_path, env, env_prefixes): |
| """Checkout code using gclient. |
| |
| Args: |
| checkout_path(Path): The path to checkout source code and dependencies. |
| """ |
| git_url = REPOS['engine'] |
| git_id = self.m.buildbucket.gitiles_commit.id |
| git_ref = self.m.buildbucket.gitiles_commit.ref |
| if 'git_url' in self.m.properties and 'git_ref' in self.m.properties: |
| git_url = self.m.properties['git_url'] |
| git_id = self.m.properties['git_ref'] |
| git_ref = self.m.properties['git_ref'] |
| |
| # Inner function to execute code a second time in case of failure. |
| def _InnerCheckout(): |
| with self.m.context(cwd=checkout_path), self.m.depot_tools.on_path(): |
| src_cfg = self.m.gclient.make_config() |
| soln = src_cfg.solutions.add() |
| soln.name = 'src/flutter' |
| soln.url = git_url |
| soln.revision = git_id |
| src_cfg.parent_got_revision_mapping[ |
| 'parent_got_revision'] = 'got_revision' |
| src_cfg.repo_path_map[git_url] = ('src/flutter', git_ref) |
| self.m.gclient.c = src_cfg |
| self.m.gclient.c.got_revision_mapping[ |
| 'src/flutter'] = 'got_engine_revision' |
| self.m.bot_update.ensure_checkout() |
| self.m.gclient.runhooks() |
| |
| try: |
| _InnerCheckout() |
| except (self.m.step.StepFailure, self.m.step.InfraFailure): |
| # Run this out of context |
| self.m.file.rmtree('Clobber cache', checkout_path) |
| self.m.file.ensure_directory('Ensure checkout cache', checkout_path) |
| # Now try a second time |
| _InnerCheckout() |
| |
| def checkout(self, name, checkout_path, url=None, ref=None): |
| """Checks out a repo and returns sha1 of checked out revision. |
| |
| The supproted repository names and their urls are defined in the global |
| REPOS variable. |
| |
| Args: |
| name (str): name of the supported repository. |
| checkout_path (Path): directory to clone into. |
| url (str): optional url overwrite of the remote repo. |
| ref (str): optional ref overwrite to fetch and check out. |
| """ |
| if name not in REPOS: |
| raise ValueError('Unsupported repo: %s' % name) |
| |
| git_url = url or REPOS[name] |
| git_ref = ref or self.m.buildbucket.gitiles_commit.ref |
| return self.m.git.checkout( |
| git_url, |
| dir_path=checkout_path, |
| ref=git_ref, |
| recursive=True, |
| set_got_revision=True, |
| tags=True) |
| |
| def flutter_environment(self, checkout_path): |
| """Returns env and env_prefixes of an flutter/dart command environment.""" |
| dart_bin = checkout_path.join('bin', 'cache', 'dart-sdk', 'bin') |
| flutter_bin = checkout_path.join('bin') |
| # Fail if dart and flutter bin folders do not exist. |
| if not (self.m.path.exists(dart_bin) and self.m.path.exists(flutter_bin)): |
| msg = ('dart or flutter bin folders do not exist,' |
| 'did you forget to checkout flutter repo?') |
| self.m.python.failing_step('Flutter Environment', msg) |
| |
| env = { |
| # Setup our own pub_cache to not affect other slaves on this machine, |
| # and so that the pre-populated pub cache is contained in the package. |
| 'PUB_CACHE': checkout_path.join('.pub-cache'), |
| # Windows Packaging script assumes this is set. |
| 'DEPOT_TOOLS': str(self.m.depot_tools.root), |
| } |
| env_prefixes = {'PATH': [flutter_bin, dart_bin]} |
| return env, env_prefixes |