| # Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file |
| # for details. 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 BuildApi(recipe_api.RecipeApi): |
| """Recipe module for building the Dart SDK with and without goma.""" |
| |
| def __init__(self, properties, *args, **kwargs): |
| super(BuildApi, self).__init__(*args, **kwargs) |
| self._goma = not properties.disable_goma |
| # No need to download goma if it's disabled. |
| self._goma_ensured = properties.disable_goma |
| self._timeout = properties.timeout or 50 * 60 # 50 minutes |
| self._python = None |
| |
| def build(self, name='build dart', args=None): |
| """Builds dart using the specified args""" |
| if not args: # pragma: no cover |
| args = [] |
| with self.m.depot_tools.on_path(), self.m.context( |
| cwd=self.m.path['checkout']): |
| if self._goma: |
| self._build_with_goma(name, args) |
| else: |
| if '--no-goma' not in args: |
| args = args + ['--no-goma'] |
| self._run_build_py(name, args) |
| |
| def gn(self, name='gn', args=None): |
| """Runs gn.py using the specified args""" |
| self._ensure_goma() |
| with self.m.context(env=self._build_env): |
| if not self._goma and '--no-goma' not in args: |
| args = args + ['--no-goma'] |
| gn_py = self.m.path['checkout'].join('tools', 'gn.py') |
| self.m.step(name, [self.python, '-u', gn_py] + args) |
| |
| def _run_build_py(self, name, args): |
| with self.m.context(infra_steps=False): |
| build_py = self.m.path['checkout'].join('tools', 'build.py') |
| self.m.step( |
| name, [self.python, '-u', build_py] + args, timeout=self._timeout) |
| |
| def _build_with_goma(self, name, args): |
| self._ensure_goma() |
| build_exit_status = None |
| with self.m.context(env=self._build_env): |
| try: |
| self.m.goma.start() |
| args = args + ['--no-start-goma', '-j200'] |
| try: |
| self._run_build_py(name, args) |
| finally: |
| build_exit_status = self.m.step.active_result.retcode |
| finally: |
| self.m.goma.stop(build_exit_status=build_exit_status) |
| |
| def _ensure_goma(self): |
| if not self._goma_ensured: |
| self.m.goma.ensure_goma() |
| self._goma_ensured = True |
| |
| @property |
| def _build_env(self): |
| return {'GOMA_DIR': self.m.goma.goma_dir} if self._goma else {} |
| |
| @property |
| def python(self): |
| if self._python: |
| return self._python |
| # TODO(athom): remove after python3 migration is complete. |
| build_py = self.m.path['checkout'].join('tools', 'build.py') |
| is_python3 = self.m.file.read_text( |
| 'detect python version', build_py).startswith('#!/usr/bin/env python3') |
| detected_python = 'python3' if is_python3 else 'python' |
| python = self.m.properties.get('python_version', detected_python) |
| assert (python in ['python', 'python3']) |
| self._python = python |
| return self._python |