blob: 577385e39585edcfcae108abcc48fd28e58f02e6 [file] [log] [blame]
borenet1ed2ae42016-07-26 11:52:17 -07001# 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
9DEPS = [
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',
Eric Boren6441a462017-01-13 13:37:53 -050017 'skia-recipes/core',
18 'skia-recipes/infra',
19 'skia-recipes/vars',
borenet1ed2ae42016-07-26 11:52:17 -070020]
21
22
23TEST_BUILDERS = {
24 'client.skia.compile': {
25 'skiabot-linux-swarm-000': [
26 'Housekeeper-Nightly-RecreateSKPs_Canary',
27 'Housekeeper-Weekly-RecreateSKPs',
28 ],
29 },
30}
31
32
Ravi Mistrybadc1372016-11-23 08:38:18 -050033UPDATE_SKPS_GITCOOKIES_FILE = 'update_skps.git_cookies'
34UPDATE_SKPS_KEY = 'update_skps_git_cookies'
borenet1ed2ae42016-07-26 11:52:17 -070035
36
Ravi Mistrybadc1372016-11-23 08:38:18 -050037class gitcookies_auth(object):
38 """Download update-skps@skia.org's .gitcookies."""
borenet1ed2ae42016-07-26 11:52:17 -070039 def __init__(self, api, metadata_key):
40 self.m = api
41 self._key = metadata_key
42
43 def __enter__(self):
44 return self.m.python.inline(
Ravi Mistrybadc1372016-11-23 08:38:18 -050045 'download update-skps.gitcookies',
borenet1ed2ae42016-07-26 11:52:17 -070046 """
47import os
48import urllib2
49
50TOKEN_FILE = '%s'
borenet1ed2ae42016-07-26 11:52:17 -070051TOKEN_URL = 'http://metadata/computeMetadata/v1/project/attributes/%s'
52
53req = urllib2.Request(TOKEN_URL, headers={'Metadata-Flavor': 'Google'})
54contents = urllib2.urlopen(req).read()
55
56home = os.path.expanduser('~')
57token_file = os.path.join(home, TOKEN_FILE)
borenet1ed2ae42016-07-26 11:52:17 -070058
59with open(token_file, 'w') as f:
60 f.write(contents)
Ravi Mistrybadc1372016-11-23 08:38:18 -050061 """ % (UPDATE_SKPS_GITCOOKIES_FILE,
borenet1ed2ae42016-07-26 11:52:17 -070062 self._key),
63 )
64
65 def __exit__(self, t, v, tb):
borenetb2cf2662016-10-24 08:40:26 -070066 self.m.python.inline(
Ravi Mistrybadc1372016-11-23 08:38:18 -050067 'cleanup update-skps.gitcookies',
borenet1ed2ae42016-07-26 11:52:17 -070068 """
69import os
70
71
72TOKEN_FILE = '%s'
borenet1ed2ae42016-07-26 11:52:17 -070073
74
75home = os.path.expanduser('~')
76token_file = os.path.join(home, TOKEN_FILE)
77if os.path.isfile(token_file):
78 os.remove(token_file)
Ravi Mistrybadc1372016-11-23 08:38:18 -050079 """ % (UPDATE_SKPS_GITCOOKIES_FILE),
borenet1ed2ae42016-07-26 11:52:17 -070080 )
borenetb2cf2662016-10-24 08:40:26 -070081 return v is None
borenet1ed2ae42016-07-26 11:52:17 -070082
83
84def RunSteps(api):
85 # Check out Chrome.
borenet1436a092016-08-03 08:23:10 -070086 api.core.setup()
borenet1ed2ae42016-07-26 11:52:17 -070087
borenet1436a092016-08-03 08:23:10 -070088 src_dir = api.vars.checkout_root.join('src')
borenetb6aafe62016-08-02 07:02:52 -070089 out_dir = src_dir.join('out', 'Release')
borenet1ed2ae42016-07-26 11:52:17 -070090
borenetb6aafe62016-08-02 07:02:52 -070091 # Call GN.
92 platform = 'linux64' # This bot only runs on linux; don't bother checking.
93 gn = src_dir.join('buildtools', platform, 'gn')
94 api.step('GN',
95 [gn, 'gen', out_dir],
borenet1ed2ae42016-07-26 11:52:17 -070096 env={'CPPFLAGS': '-DSK_ALLOW_CROSSPROCESS_PICTUREIMAGEFILTERS=1',
97 'GYP_GENERATORS': 'ninja'},
98 cwd=src_dir)
99 # Build Chrome.
100 api.step('Build Chrome',
borenetb6aafe62016-08-02 07:02:52 -0700101 ['ninja', '-C', out_dir, 'chrome'],
borenet1ed2ae42016-07-26 11:52:17 -0700102 cwd=src_dir)
103
borenet1ed2ae42016-07-26 11:52:17 -0700104 # Clean up the output dir.
Ravi Mistry9bcca6a2016-11-21 16:06:19 -0500105 output_dir = api.path['start_dir'].join('skp_output')
borenet1ed2ae42016-07-26 11:52:17 -0700106 if api.path.exists(output_dir):
107 api.file.rmtree('skp_output', output_dir)
108 api.file.makedirs('skp_output', output_dir)
109
110 # Capture the SKPs.
111 path_var= api.path.pathsep.join([str(api.path['depot_tools']), '%(PATH)s'])
112 env = {
113 'CHROME_HEADLESS': '1',
114 'PATH': path_var,
115 }
borenet1436a092016-08-03 08:23:10 -0700116 asset_dir = api.vars.infrabots_dir.join('assets', 'skp')
borenet1ed2ae42016-07-26 11:52:17 -0700117 cmd = ['python', asset_dir.join('create.py'),
118 '--chrome_src_path', src_dir,
119 '--browser_executable', src_dir.join('out', 'Release', 'chrome'),
120 '--target_dir', output_dir]
121 if 'Canary' not in api.properties['buildername']:
122 cmd.append('--upload_to_partner_bucket')
123 api.step('Recreate SKPs',
124 cmd=cmd,
borenet1436a092016-08-03 08:23:10 -0700125 cwd=api.vars.skia_dir,
borenet76bcd4f2016-10-10 10:37:30 -0700126 env=env)
borenet1ed2ae42016-07-26 11:52:17 -0700127
128 # Upload the SKPs.
129 if 'Canary' not in api.properties['buildername']:
borenet09732a62016-10-24 06:36:30 -0700130 api.infra.update_go_deps()
Ravi Mistrybadc1372016-11-23 08:38:18 -0500131 update_skps_gitcookies = api.path.join(api.path.expanduser('~'),
132 UPDATE_SKPS_GITCOOKIES_FILE)
borenet1ed2ae42016-07-26 11:52:17 -0700133 cmd = ['python',
borenet1436a092016-08-03 08:23:10 -0700134 api.vars.skia_dir.join('infra', 'bots', 'upload_skps.py'),
Ravi Mistrybadc1372016-11-23 08:38:18 -0500135 '--target_dir', output_dir,
136 '--gitcookies', str(update_skps_gitcookies)]
borenet09732a62016-10-24 06:36:30 -0700137 env.update(api.infra.go_env)
Ravi Mistrybadc1372016-11-23 08:38:18 -0500138 with gitcookies_auth(api, UPDATE_SKPS_KEY):
borenet1ed2ae42016-07-26 11:52:17 -0700139 api.step('Upload SKPs',
140 cmd=cmd,
borenet1436a092016-08-03 08:23:10 -0700141 cwd=api.vars.skia_dir,
borenet1ed2ae42016-07-26 11:52:17 -0700142 env=env)
143
144
145def GenTests(api):
borenetb2cf2662016-10-24 08:40:26 -0700146 mastername = 'client.skia.compile'
147 slavename = 'skiabot-linux-swarm-000'
148 builder = 'Housekeeper-Nightly-RecreateSKPs_Canary'
149 yield (
150 api.test(builder) +
151 api.properties(buildername=builder,
152 mastername=mastername,
153 slavename=slavename,
Eric Borenad29aee2017-01-17 14:35:06 -0500154 repository='https://skia.googlesource.com/skia.git',
borenetb2cf2662016-10-24 08:40:26 -0700155 revision='abc123',
156 buildnumber=2,
157 path_config='kitchen',
158 swarm_out_dir='[SWARM_OUT_DIR]') +
Ravi Mistry9bcca6a2016-11-21 16:06:19 -0500159 api.path.exists(api.path['start_dir'].join('skp_output'))
borenetb2cf2662016-10-24 08:40:26 -0700160 )
161
162 builder = 'Housekeeper-Weekly-RecreateSKPs'
163 yield (
164 api.test(builder) +
165 api.properties(buildername=builder,
166 mastername=mastername,
167 slavename=slavename,
Eric Borenad29aee2017-01-17 14:35:06 -0500168 repository='https://skia.googlesource.com/skia.git',
borenetb2cf2662016-10-24 08:40:26 -0700169 revision='abc123',
170 buildnumber=2,
171 path_config='kitchen',
172 swarm_out_dir='[SWARM_OUT_DIR]') +
Ravi Mistry9bcca6a2016-11-21 16:06:19 -0500173 api.path.exists(api.path['start_dir'].join('skp_output'))
borenetb2cf2662016-10-24 08:40:26 -0700174 )
175
176 yield (
177 api.test('failed_upload') +
178 api.properties(buildername=builder,
179 mastername=mastername,
180 slavename=slavename,
Eric Borenad29aee2017-01-17 14:35:06 -0500181 repository='https://skia.googlesource.com/skia.git',
borenetb2cf2662016-10-24 08:40:26 -0700182 revision='abc123',
183 buildnumber=2,
184 path_config='kitchen',
185 swarm_out_dir='[SWARM_OUT_DIR]') +
Ravi Mistry9bcca6a2016-11-21 16:06:19 -0500186 api.path.exists(api.path['start_dir'].join('skp_output')) +
borenetb2cf2662016-10-24 08:40:26 -0700187 api.step_data('Upload SKPs', retcode=1)
188 )