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

Side by Side Diff: infra/bots/recipes/swarm_RecreateSKPs.py

Issue 2175373002: Move Skia recipes from build repo (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address more comments 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 2014 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 """Recipe for the Skia RecreateSKPs Bot."""
7
8
9 DEPS = [
10 'build/file',
11 'depot_tools/gclient',
12 'recipe_engine/path',
13 'recipe_engine/properties',
14 'recipe_engine/python',
15 'recipe_engine/raw_io',
16 'recipe_engine/step',
17 'skia',
18 ]
19
20
21 TEST_BUILDERS = {
22 'client.skia.compile': {
23 'skiabot-linux-swarm-000': [
24 'Housekeeper-Nightly-RecreateSKPs_Canary',
25 'Housekeeper-Weekly-RecreateSKPs',
26 ],
27 },
28 }
29
30
31 DEPOT_TOOLS_AUTH_TOKEN_FILE = '.depot_tools_oauth2_tokens'
32 DEPOT_TOOLS_AUTH_TOKEN_FILE_BACKUP = '.depot_tools_oauth2_tokens.old'
33 UPDATE_SKPS_KEY = 'depot_tools_auth_update_skps'
34
35
36 class depot_tools_auth(object):
37 """Temporarily authenticate to depot_tools via GCE metadata."""
38 def __init__(self, api, metadata_key):
39 self.m = api
40 self._key = metadata_key
41
42 def __enter__(self):
43 return self.m.python.inline(
44 'depot-tools-auth login',
45 """
46 import os
47 import urllib2
48
49 TOKEN_FILE = '%s'
50 TOKEN_FILE_BACKUP = '%s'
51 TOKEN_URL = 'http://metadata/computeMetadata/v1/project/attributes/%s'
52
53 req = urllib2.Request(TOKEN_URL, headers={'Metadata-Flavor': 'Google'})
54 contents = urllib2.urlopen(req).read()
55
56 home = os.path.expanduser('~')
57 token_file = os.path.join(home, TOKEN_FILE)
58 if os.path.isfile(token_file):
59 os.rename(token_file, os.path.join(home, TOKEN_FILE_BACKUP))
60
61 with open(token_file, 'w') as f:
62 f.write(contents)
63 """ % (DEPOT_TOOLS_AUTH_TOKEN_FILE,
64 DEPOT_TOOLS_AUTH_TOKEN_FILE_BACKUP,
65 self._key),
66 )
67
68 def __exit__(self, t, v, tb):
69 return self.m.python.inline(
70 'depot-tools-auth logout',
71 """
72 import os
73
74
75 TOKEN_FILE = '%s'
76 TOKEN_FILE_BACKUP = '%s'
77
78
79 home = os.path.expanduser('~')
80 token_file = os.path.join(home, TOKEN_FILE)
81 if os.path.isfile(token_file):
82 os.remove(token_file)
83
84 backup_file = os.path.join(home, TOKEN_FILE_BACKUP)
85 if os.path.isfile(backup_file):
86 os.rename(backup_file, token_file)
87 """ % (DEPOT_TOOLS_AUTH_TOKEN_FILE,
88 DEPOT_TOOLS_AUTH_TOKEN_FILE_BACKUP),
89 )
90
91
92 def RunSteps(api):
93 # Check out Chrome.
94 api.skia.setup()
95 api.gclient.runhooks(
96 env={'CPPFLAGS': '-DSK_ALLOW_CROSSPROCESS_PICTUREIMAGEFILTERS=1'})
97
98 src_dir = api.skia.checkout_root.join('src')
99
100 # Call build/gyp_chromium
101 api.step('gyp_chromium',
102 ['build/gyp_chromium'],
103 env={'CPPFLAGS': '-DSK_ALLOW_CROSSPROCESS_PICTUREIMAGEFILTERS=1',
104 'GYP_GENERATORS': 'ninja'},
105 cwd=src_dir)
106 # Build Chrome.
107 api.step('Build Chrome',
108 ['ninja', '-C', 'out/Release', 'chrome'],
109 cwd=src_dir)
110
111 # Download boto file (needed by recreate_skps.py) to tmp dir.
112 boto_file = api.path['slave_build'].join('tmp', '.boto')
113 api.python.inline(
114 'download boto file',
115 """
116 import os
117 import urllib2
118
119 BOTO_URL = 'http://metadata/computeMetadata/v1/project/attributes/boto-file'
120
121 dest_path = '%s'
122 dest_dir = os.path.dirname(dest_path)
123 if not os.path.exists(dest_dir):
124 os.makedirs(dest_dir)
125
126 req = urllib2.Request(BOTO_URL, headers={'Metadata-Flavor': 'Google'})
127 contents = urllib2.urlopen(req).read()
128
129 with open(dest_path, 'w') as f:
130 f.write(contents)
131 """ % boto_file)
132
133 # Clean up the output dir.
134 output_dir = api.path['slave_build'].join('skp_output')
135 if api.path.exists(output_dir):
136 api.file.rmtree('skp_output', output_dir)
137 api.file.makedirs('skp_output', output_dir)
138
139 # Capture the SKPs.
140 path_var= api.path.pathsep.join([str(api.path['depot_tools']), '%(PATH)s'])
141 env = {
142 'CHROME_HEADLESS': '1',
143 'PATH': path_var,
144 }
145 boto_env = {
146 'AWS_CREDENTIAL_FILE': boto_file,
147 'BOTO_CONFIG': boto_file,
148 }
149 recreate_skps_env = {}
150 recreate_skps_env.update(env)
151 recreate_skps_env.update(boto_env)
152 asset_dir = api.skia.infrabots_dir.join('assets', 'skp')
153 cmd = ['python', asset_dir.join('create.py'),
154 '--chrome_src_path', src_dir,
155 '--browser_executable', src_dir.join('out', 'Release', 'chrome'),
156 '--target_dir', output_dir]
157 if 'Canary' not in api.properties['buildername']:
158 cmd.append('--upload_to_partner_bucket')
159 api.step('Recreate SKPs',
160 cmd=cmd,
161 cwd=api.skia.skia_dir,
162 env=recreate_skps_env)
163
164 # Upload the SKPs.
165 if 'Canary' not in api.properties['buildername']:
166 cmd = ['python',
167 api.skia.skia_dir.join('infra', 'bots', 'upload_skps.py'),
168 '--target_dir', output_dir]
169 with depot_tools_auth(api, UPDATE_SKPS_KEY):
170 api.step('Upload SKPs',
171 cmd=cmd,
172 cwd=api.skia.skia_dir,
173 env=env)
174
175
176 def GenTests(api):
177 for mastername, slaves in TEST_BUILDERS.iteritems():
178 for slavename, builders_by_slave in slaves.iteritems():
179 for builder in builders_by_slave:
180 test = (
181 api.test(builder) +
182 api.properties(buildername=builder,
183 mastername=mastername,
184 slavename=slavename,
185 revision='abc123',
186 buildnumber=2,
187 path_config='kitchen',
188 swarm_out_dir='[SWARM_OUT_DIR]') +
189 api.path.exists(api.path['slave_build'].join('skp_output'))
190 )
191 yield test
OLDNEW
« no previous file with comments | « infra/bots/recipes.py ('k') | infra/bots/recipes/swarm_RecreateSKPs.expected/Housekeeper-Nightly-RecreateSKPs_Canary.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698