OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 |
| 6 # pylint: disable=W0201 |
| 7 |
| 8 |
| 9 from recipe_engine import recipe_api |
| 10 |
| 11 |
| 12 BUILD_PRODUCTS_ISOLATE_WHITELIST = [ |
| 13 'dm', |
| 14 'dm.exe', |
| 15 'nanobench', |
| 16 'nanobench.exe', |
| 17 '*.so', |
| 18 '*.dll', |
| 19 '*.dylib', |
| 20 'skia_launcher', |
| 21 'lib/*.so', |
| 22 'iOSShell.app', |
| 23 'iOSShell.ipa', |
| 24 'visualbench', |
| 25 'visualbench.exe', |
| 26 'vulkan-1.dll', |
| 27 ] |
| 28 |
| 29 |
| 30 class SkiaStepApi(recipe_api.RecipeApi): |
| 31 |
| 32 def __init__(self, *args, **kwargs): |
| 33 """Initialize the recipe module.""" |
| 34 super(SkiaStepApi, self).__init__(*args, **kwargs) |
| 35 |
| 36 self._already_ran = {} |
| 37 self._ccache = None |
| 38 self._checked_for_ccache = False |
| 39 self._failed = [] |
| 40 |
| 41 def check_failure(self): |
| 42 """Raise an exception if any step failed.""" |
| 43 if self._failed: |
| 44 raise self.m.step.StepFailure('Failed build steps: %s' % |
| 45 ', '.join([f.name for f in self._failed])) |
| 46 |
| 47 def run_once(self, fn, *args, **kwargs): |
| 48 if not fn.__name__ in self._already_ran: |
| 49 self._already_ran[fn.__name__] = fn(*args, **kwargs) |
| 50 return self._already_ran[fn.__name__] |
| 51 |
| 52 def readfile(self, filename, *args, **kwargs): |
| 53 """Convenience function for reading files.""" |
| 54 name = kwargs.pop('name') or 'read %s' % self.m.path.basename(filename) |
| 55 return self.m.file.read(name, filename, infra_step=True, *args, **kwargs) |
| 56 |
| 57 def writefile(self, filename, contents): |
| 58 """Convenience function for writing files.""" |
| 59 return self.m.file.write('write %s' % self.m.path.basename(filename), |
| 60 filename, contents, infra_step=True) |
| 61 |
| 62 def rmtree(self, path): |
| 63 """Wrapper around api.file.rmtree with environment fix.""" |
| 64 env = {} |
| 65 env['PYTHONPATH'] = str(self.m.path['checkout'].join( |
| 66 'infra', 'bots', '.recipe_deps', 'build', 'scripts')) |
| 67 self.m.file.rmtree(self.m.path.basename(path), |
| 68 path, |
| 69 env=env, |
| 70 infra_step=True) |
| 71 |
| 72 def __call__(self, steptype, name, abort_on_failure=True, |
| 73 fail_build_on_failure=True, env=None, **kwargs): |
| 74 """Run a step. If it fails, keep going but mark the build status failed.""" |
| 75 env = dict(env or {}) |
| 76 env.update(self.m.vars.default_env) |
| 77 try: |
| 78 return steptype(name=name, env=env, **kwargs) |
| 79 except self.m.step.StepFailure as e: |
| 80 if abort_on_failure: |
| 81 raise # pragma: no cover |
| 82 if fail_build_on_failure: |
| 83 self._failed.append(e) |
| 84 |
| 85 def json_from_file(self, filename, cwd, builder_name, test_data): |
| 86 """Execute the given script to obtain JSON data.""" |
| 87 return self.m.python( |
| 88 'exec %s' % self.m.path.basename(filename), |
| 89 filename, |
| 90 args=[self.m.json.output(), builder_name], |
| 91 step_test_data=lambda: self.m.json.test_api.output(test_data), |
| 92 cwd=cwd, |
| 93 infra_step=True).json.output |
| 94 |
| 95 def copy_build_products(self, src, dst): |
| 96 """Copy whitelisted build products from src to dst.""" |
| 97 self.m.python.inline( |
| 98 name='copy build products', |
| 99 program='''import errno |
| 100 import glob |
| 101 import os |
| 102 import shutil |
| 103 import sys |
| 104 |
| 105 src = sys.argv[1] |
| 106 dst = sys.argv[2] |
| 107 build_products_whitelist = %s |
| 108 |
| 109 try: |
| 110 os.makedirs(dst) |
| 111 except OSError as e: |
| 112 if e.errno != errno.EEXIST: |
| 113 raise |
| 114 |
| 115 for pattern in build_products_whitelist: |
| 116 path = os.path.join(src, pattern) |
| 117 for f in glob.glob(path): |
| 118 dst_path = os.path.join(dst, os.path.relpath(f, src)) |
| 119 if not os.path.isdir(os.path.dirname(dst_path)): |
| 120 os.makedirs(os.path.dirname(dst_path)) |
| 121 print 'Copying build product %%s to %%s' %% (f, dst_path) |
| 122 shutil.move(f, dst_path) |
| 123 ''' % str(BUILD_PRODUCTS_ISOLATE_WHITELIST), |
| 124 args=[src, dst], |
| 125 infra_step=True) |
| 126 |
| 127 def ccache(self): |
| 128 if not self._checked_for_ccache: |
| 129 self._checked_for_ccache = True |
| 130 if not self.m.platform.is_win: |
| 131 result = self( |
| 132 self.m.python.inline, |
| 133 name='has ccache?', |
| 134 program='''import json |
| 135 import subprocess |
| 136 import sys |
| 137 |
| 138 ccache = None |
| 139 try: |
| 140 ccache = subprocess.check_output(['which', 'ccache']).rstrip() |
| 141 except: |
| 142 pass |
| 143 print json.dumps({'ccache': ccache}) |
| 144 ''', |
| 145 stdout=self.m.json.output(), |
| 146 infra_step=True, |
| 147 abort_on_failure=False, |
| 148 fail_build_on_failure=False) |
| 149 if result and result.stdout and result.stdout.get('ccache'): |
| 150 self._ccache = result.stdout['ccache'] |
| 151 |
| 152 return self._ccache |
OLD | NEW |