blob: b1a2a85a1bf1bc94e398edd46a854146afc67b6f [file] [log] [blame]
# 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
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']
self.m.python(
name, self.m.path['checkout'].join('tools', 'gn.py'), args=args)
def _run_build_py(self, name, args):
with self.m.context(infra_steps=False):
self.m.python(
name,
self.m.path['checkout'].join('tools', 'build.py'),
args=args,
timeout=50 * 60)
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 {}