Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: infra/bots/recipe_modules/run/api.py

Issue 2198173002: Re-organize Skia recipes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rename modules, add README.md Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 setup(self):
rmistry 2016/08/03 14:15:16 Looks like a constructor should work here.
borenet 2016/08/03 14:30:00 Done.
33 """Initialize the recipe module."""
34 self._already_ran = {}
35 self._ccache = None
36 self._checked_for_ccache = False
37 self._failed = []
38
39 def check_failure(self):
40 """Raise an exception if any step failed."""
41 if self._failed:
42 raise self.m.step.StepFailure('Failed build steps: %s' %
43 ', '.join([f.name for f in self._failed]))
44
45 def run_once(self, fn, *args, **kwargs):
46 if not fn.__name__ in self._already_ran:
47 self._already_ran[fn.__name__] = fn(*args, **kwargs)
48 return self._already_ran[fn.__name__]
49
50 def readfile(self, filename, *args, **kwargs):
51 """Convenience function for reading files."""
52 name = kwargs.pop('name') or 'read %s' % self.m.path.basename(filename)
53 return self.m.file.read(name, filename, infra_step=True, *args, **kwargs)
54
55 def writefile(self, filename, contents):
56 """Convenience function for writing files."""
57 return self.m.file.write('write %s' % self.m.path.basename(filename),
58 filename, contents, infra_step=True)
59
60 def rmtree(self, path):
61 """Wrapper around api.file.rmtree with environment fix."""
62 env = {}
63 env['PYTHONPATH'] = str(self.m.path['checkout'].join(
64 'infra', 'bots', '.recipe_deps', 'build', 'scripts'))
65 self.m.file.rmtree(self.m.path.basename(path),
66 path,
67 env=env,
68 infra_step=True)
69
70 def __call__(self, steptype, name, abort_on_failure=True,
71 fail_build_on_failure=True, env=None, **kwargs):
72 """Run a step. If it fails, keep going but mark the build status failed."""
73 env = dict(env or {})
74 env.update(self.m.vars.default_env)
75 try:
76 return steptype(name=name, env=env, **kwargs)
77 except self.m.step.StepFailure as e:
78 if abort_on_failure:
79 raise # pragma: no cover
80 if fail_build_on_failure:
81 self._failed.append(e)
82
83 def json_from_file(self, filename, cwd, builder_name, test_data):
84 """Execute the given script to obtain JSON data."""
85 return self.m.python(
86 'exec %s' % self.m.path.basename(filename),
87 filename,
88 args=[self.m.json.output(), builder_name],
89 step_test_data=lambda: self.m.json.test_api.output(test_data),
90 cwd=cwd,
91 infra_step=True).json.output
92
93 def copy_build_products(self, src, dst):
94 """Copy whitelisted build products from src to dst."""
95 self.m.python.inline(
96 name='copy build products',
97 program='''import errno
98 import glob
99 import os
100 import shutil
101 import sys
102
103 src = sys.argv[1]
104 dst = sys.argv[2]
105 build_products_whitelist = %s
106
107 try:
108 os.makedirs(dst)
109 except OSError as e:
110 if e.errno != errno.EEXIST:
111 raise
112
113 for pattern in build_products_whitelist:
114 path = os.path.join(src, pattern)
115 for f in glob.glob(path):
116 dst_path = os.path.join(dst, os.path.relpath(f, src))
117 if not os.path.isdir(os.path.dirname(dst_path)):
118 os.makedirs(os.path.dirname(dst_path))
119 print 'Copying build product %%s to %%s' %% (f, dst_path)
120 shutil.move(f, dst_path)
121 ''' % str(BUILD_PRODUCTS_ISOLATE_WHITELIST),
122 args=[src, dst],
123 infra_step=True)
124
125 def ccache(self):
126 if not self._checked_for_ccache:
127 self._checked_for_ccache = True
128 if not self.m.platform.is_win:
129 result = self(
130 self.m.python.inline,
131 name='has ccache?',
132 program='''import json
133 import subprocess
134 import sys
135
136 ccache = None
137 try:
138 ccache = subprocess.check_output(['which', 'ccache']).rstrip()
139 except:
140 pass
141 print json.dumps({'ccache': ccache})
142 ''',
143 stdout=self.m.json.output(),
144 infra_step=True,
145 abort_on_failure=False,
146 fail_build_on_failure=False)
147 if result and result.stdout and result.stdout.get('ccache'):
148 self._ccache = result.stdout['ccache']
149
150 return self._ccache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698