2017-02-02 14:02:37 +00:00
|
|
|
# Copyright 2016 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.
|
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable=W0201
|
|
|
|
|
|
|
|
|
|
|
|
from recipe_engine import recipe_api
|
|
|
|
|
|
|
|
|
2018-03-19 20:52:37 +00:00
|
|
|
TEST_DEFAULT_ASSET_VERSION = '42'
|
2017-02-02 14:02:37 +00:00
|
|
|
|
|
|
|
class SkiaStepApi(recipe_api.RecipeApi):
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
"""Initialize the recipe module."""
|
|
|
|
super(SkiaStepApi, self).__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
self._already_ran = {}
|
|
|
|
self._ccache = None
|
|
|
|
self._checked_for_ccache = False
|
|
|
|
self._failed = []
|
|
|
|
|
|
|
|
def check_failure(self):
|
|
|
|
"""Raise an exception if any step failed."""
|
|
|
|
if self._failed:
|
|
|
|
raise self.m.step.StepFailure('Failed build steps: %s' %
|
|
|
|
', '.join([f.name for f in self._failed]))
|
|
|
|
|
2017-02-09 15:08:13 +00:00
|
|
|
@property
|
|
|
|
def failed_steps(self):
|
|
|
|
return self._failed[:]
|
|
|
|
|
2017-02-02 14:02:37 +00:00
|
|
|
def run_once(self, fn, *args, **kwargs):
|
|
|
|
if not fn.__name__ in self._already_ran:
|
|
|
|
self._already_ran[fn.__name__] = fn(*args, **kwargs)
|
|
|
|
return self._already_ran[fn.__name__]
|
|
|
|
|
|
|
|
def readfile(self, filename, *args, **kwargs):
|
|
|
|
"""Convenience function for reading files."""
|
2017-04-18 19:49:27 +00:00
|
|
|
name = kwargs.pop('name', 'read %s' % self.m.path.basename(filename))
|
2017-06-16 17:10:22 +00:00
|
|
|
return self.m.file.read_text(name, filename, *args, **kwargs)
|
2017-02-02 14:02:37 +00:00
|
|
|
|
|
|
|
def writefile(self, filename, contents):
|
|
|
|
"""Convenience function for writing files."""
|
2017-06-16 17:10:22 +00:00
|
|
|
return self.m.file.write_text('write %s' % self.m.path.basename(filename),
|
|
|
|
filename, contents)
|
2017-02-02 14:02:37 +00:00
|
|
|
|
|
|
|
def rmtree(self, path):
|
2017-06-16 17:10:22 +00:00
|
|
|
"""Wrapper around api.file.rmtree."""
|
|
|
|
self.m.file.rmtree('rmtree %s' % self.m.path.basename(path), path)
|
2017-02-21 12:22:20 +00:00
|
|
|
|
2018-05-18 11:36:55 +00:00
|
|
|
def asset_version(self, asset_name, skia_dir, test_data=None):
|
2018-03-19 20:52:37 +00:00
|
|
|
"""Return the contents of VERSION for the given asset as a string.
|
|
|
|
|
|
|
|
If test_data is not specified, reads the property
|
|
|
|
'test_<asset_name>_version' or if not present, uses
|
|
|
|
TEST_DEFAULT_ASSET_VERSION."""
|
2018-05-18 11:36:55 +00:00
|
|
|
version_file = skia_dir.join(
|
|
|
|
'infra', 'bots', 'assets', asset_name, 'VERSION')
|
2018-03-19 20:52:37 +00:00
|
|
|
if not test_data:
|
|
|
|
test_data = self.m.properties.get(
|
|
|
|
'test_%s_version' % asset_name, TEST_DEFAULT_ASSET_VERSION)
|
|
|
|
return self.m.file.read_text('Get %s VERSION' % asset_name,
|
|
|
|
version_file,
|
|
|
|
test_data=test_data).rstrip()
|
|
|
|
|
2017-02-02 14:02:37 +00:00
|
|
|
def __call__(self, steptype, name, abort_on_failure=True,
|
2017-03-20 19:40:12 +00:00
|
|
|
fail_build_on_failure=True, **kwargs):
|
2017-02-02 14:02:37 +00:00
|
|
|
"""Run a step. If it fails, keep going but mark the build status failed."""
|
|
|
|
try:
|
2017-04-24 17:22:56 +00:00
|
|
|
with self.m.env(self.m.vars.default_env):
|
2017-03-21 12:20:33 +00:00
|
|
|
return steptype(name=name, **kwargs)
|
2017-02-02 14:02:37 +00:00
|
|
|
except self.m.step.StepFailure as e:
|
2017-09-08 18:06:38 +00:00
|
|
|
if fail_build_on_failure:
|
2017-02-13 15:35:39 +00:00
|
|
|
self._failed.append(e)
|
2017-02-02 14:02:37 +00:00
|
|
|
if abort_on_failure:
|
2017-04-19 18:39:21 +00:00
|
|
|
raise
|
2017-02-02 14:02:37 +00:00
|
|
|
|
2017-09-08 18:06:38 +00:00
|
|
|
def with_retry(self, steptype, name, attempts, between_attempts_fn=None,
|
|
|
|
abort_on_failure=True, fail_build_on_failure=True, **kwargs):
|
2017-02-02 14:02:37 +00:00
|
|
|
for attempt in xrange(attempts):
|
|
|
|
step_name = name
|
|
|
|
if attempt > 0:
|
|
|
|
step_name += ' (attempt %d)' % (attempt + 1)
|
|
|
|
try:
|
2017-09-08 18:06:38 +00:00
|
|
|
res = self(steptype, name=step_name, abort_on_failure=True,
|
|
|
|
fail_build_on_failure=fail_build_on_failure, **kwargs)
|
|
|
|
if attempt > 0 and fail_build_on_failure:
|
|
|
|
del self._failed[-attempt:]
|
2017-02-21 12:22:20 +00:00
|
|
|
return res
|
2017-02-02 14:02:37 +00:00
|
|
|
except self.m.step.StepFailure:
|
|
|
|
if attempt == attempts - 1:
|
2017-09-08 18:06:38 +00:00
|
|
|
if abort_on_failure:
|
|
|
|
raise
|
|
|
|
elif between_attempts_fn:
|
|
|
|
between_attempts_fn(attempt+1)
|