blob: c697bf19e621985372979d4103a35e50abcb424d [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 Boren7e97dc02017-02-02 09:02:37 -050017 'core',
18 'infra',
Eric Boren81340c62017-04-17 10:29:04 -040019 'run',
Eric Boren7e97dc02017-02-02 09:02:37 -050020 'vars',
borenet1ed2ae42016-07-26 11:52:17 -070021]
22
23
24TEST_BUILDERS = {
25 'client.skia.compile': {
26 'skiabot-linux-swarm-000': [
27 'Housekeeper-Nightly-RecreateSKPs_Canary',
28 'Housekeeper-Weekly-RecreateSKPs',
29 ],
30 },
31}
32
33
Ravi Mistrybadc1372016-11-23 08:38:18 -050034UPDATE_SKPS_GITCOOKIES_FILE = 'update_skps.git_cookies'
35UPDATE_SKPS_KEY = 'update_skps_git_cookies'
borenet1ed2ae42016-07-26 11:52:17 -070036
37
Ravi Mistrybadc1372016-11-23 08:38:18 -050038class gitcookies_auth(object):
39 """Download update-skps@skia.org's .gitcookies."""
borenet1ed2ae42016-07-26 11:52:17 -070040 def __init__(self, api, metadata_key):
41 self.m = api
42 self._key = metadata_key
43
44 def __enter__(self):
45 return self.m.python.inline(
Ravi Mistrybadc1372016-11-23 08:38:18 -050046 'download update-skps.gitcookies',
borenet1ed2ae42016-07-26 11:52:17 -070047 """
48import os
49import urllib2
50
51TOKEN_FILE = '%s'
borenet1ed2ae42016-07-26 11:52:17 -070052TOKEN_URL = 'http://metadata/computeMetadata/v1/project/attributes/%s'
53
54req = urllib2.Request(TOKEN_URL, headers={'Metadata-Flavor': 'Google'})
55contents = urllib2.urlopen(req).read()
56
57home = os.path.expanduser('~')
58token_file = os.path.join(home, TOKEN_FILE)
borenet1ed2ae42016-07-26 11:52:17 -070059
60with open(token_file, 'w') as f:
61 f.write(contents)
Ravi Mistrybadc1372016-11-23 08:38:18 -050062 """ % (UPDATE_SKPS_GITCOOKIES_FILE,
borenet1ed2ae42016-07-26 11:52:17 -070063 self._key),
64 )
65
66 def __exit__(self, t, v, tb):
borenetb2cf2662016-10-24 08:40:26 -070067 self.m.python.inline(
Ravi Mistrybadc1372016-11-23 08:38:18 -050068 'cleanup update-skps.gitcookies',
borenet1ed2ae42016-07-26 11:52:17 -070069 """
70import os
71
72
73TOKEN_FILE = '%s'
borenet1ed2ae42016-07-26 11:52:17 -070074
75
76home = os.path.expanduser('~')
77token_file = os.path.join(home, TOKEN_FILE)
78if os.path.isfile(token_file):
79 os.remove(token_file)
Ravi Mistrybadc1372016-11-23 08:38:18 -050080 """ % (UPDATE_SKPS_GITCOOKIES_FILE),
borenet1ed2ae42016-07-26 11:52:17 -070081 )
borenetb2cf2662016-10-24 08:40:26 -070082 return v is None
borenet1ed2ae42016-07-26 11:52:17 -070083
84
85def RunSteps(api):
86 # Check out Chrome.
borenet1436a092016-08-03 08:23:10 -070087 api.core.setup()
borenet1ed2ae42016-07-26 11:52:17 -070088
borenet1436a092016-08-03 08:23:10 -070089 src_dir = api.vars.checkout_root.join('src')
borenetb6aafe62016-08-02 07:02:52 -070090 out_dir = src_dir.join('out', 'Release')
borenet1ed2ae42016-07-26 11:52:17 -070091
Eric Borene6b26ad2017-02-21 07:22:20 -050092 with api.step.context({'cwd': src_dir}):
93 # Call GN.
94 platform = 'linux64' # This bot only runs on linux; don't bother checking.
95 gn = src_dir.join('buildtools', platform, 'gn')
Eric Boren53262d02017-03-20 15:40:12 -040096 gn_env = {'CPPFLAGS': '-DSK_ALLOW_CROSSPROCESS_PICTUREIMAGEFILTERS=1',
97 'GYP_GENERATORS': 'ninja'}
98 with api.step.context({'env': gn_env}):
Eric Boren81340c62017-04-17 10:29:04 -040099 api.run(api.step, 'GN', cmd=[gn, 'gen', out_dir])
Eric Borene6b26ad2017-02-21 07:22:20 -0500100
101 # Build Chrome.
Eric Boren81340c62017-04-17 10:29:04 -0400102 api.run(api.step, 'Build Chrome', cmd=['ninja', '-C', out_dir, 'chrome'])
borenet1ed2ae42016-07-26 11:52:17 -0700103
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.
borenet1436a092016-08-03 08:23:10 -0700111 asset_dir = api.vars.infrabots_dir.join('assets', 'skp')
borenet1ed2ae42016-07-26 11:52:17 -0700112 cmd = ['python', asset_dir.join('create.py'),
113 '--chrome_src_path', src_dir,
114 '--browser_executable', src_dir.join('out', 'Release', 'chrome'),
115 '--target_dir', output_dir]
116 if 'Canary' not in api.properties['buildername']:
117 cmd.append('--upload_to_partner_bucket')
Eric Boren81340c62017-04-17 10:29:04 -0400118 with api.step.context({'cwd': api.vars.skia_dir}):
119 api.run(api.step, 'Recreate SKPs', cmd=cmd)
borenet1ed2ae42016-07-26 11:52:17 -0700120
121 # Upload the SKPs.
122 if 'Canary' not in api.properties['buildername']:
borenet09732a62016-10-24 06:36:30 -0700123 api.infra.update_go_deps()
Ravi Mistrybadc1372016-11-23 08:38:18 -0500124 update_skps_gitcookies = api.path.join(api.path.expanduser('~'),
125 UPDATE_SKPS_GITCOOKIES_FILE)
borenet1ed2ae42016-07-26 11:52:17 -0700126 cmd = ['python',
borenet1436a092016-08-03 08:23:10 -0700127 api.vars.skia_dir.join('infra', 'bots', 'upload_skps.py'),
Ravi Mistrybadc1372016-11-23 08:38:18 -0500128 '--target_dir', output_dir,
129 '--gitcookies', str(update_skps_gitcookies)]
Ravi Mistrybadc1372016-11-23 08:38:18 -0500130 with gitcookies_auth(api, UPDATE_SKPS_KEY):
Eric Boren81340c62017-04-17 10:29:04 -0400131 with api.step.context({'cwd': api.vars.skia_dir,
132 'env': api.infra.go_env}):
133 api.run(api.step, 'Upload SKPs', cmd=cmd)
borenet1ed2ae42016-07-26 11:52:17 -0700134
135
136def GenTests(api):
borenetb2cf2662016-10-24 08:40:26 -0700137 builder = 'Housekeeper-Nightly-RecreateSKPs_Canary'
138 yield (
139 api.test(builder) +
140 api.properties(buildername=builder,
Eric Borenad29aee2017-01-17 14:35:06 -0500141 repository='https://skia.googlesource.com/skia.git',
borenetb2cf2662016-10-24 08:40:26 -0700142 revision='abc123',
borenetb2cf2662016-10-24 08:40:26 -0700143 path_config='kitchen',
144 swarm_out_dir='[SWARM_OUT_DIR]') +
Ravi Mistry9bcca6a2016-11-21 16:06:19 -0500145 api.path.exists(api.path['start_dir'].join('skp_output'))
borenetb2cf2662016-10-24 08:40:26 -0700146 )
147
148 builder = 'Housekeeper-Weekly-RecreateSKPs'
149 yield (
150 api.test(builder) +
151 api.properties(buildername=builder,
Eric Borenad29aee2017-01-17 14:35:06 -0500152 repository='https://skia.googlesource.com/skia.git',
borenetb2cf2662016-10-24 08:40:26 -0700153 revision='abc123',
borenetb2cf2662016-10-24 08:40:26 -0700154 path_config='kitchen',
155 swarm_out_dir='[SWARM_OUT_DIR]') +
Ravi Mistry9bcca6a2016-11-21 16:06:19 -0500156 api.path.exists(api.path['start_dir'].join('skp_output'))
borenetb2cf2662016-10-24 08:40:26 -0700157 )
158
159 yield (
160 api.test('failed_upload') +
161 api.properties(buildername=builder,
Eric Borenad29aee2017-01-17 14:35:06 -0500162 repository='https://skia.googlesource.com/skia.git',
borenetb2cf2662016-10-24 08:40:26 -0700163 revision='abc123',
borenetb2cf2662016-10-24 08:40:26 -0700164 path_config='kitchen',
165 swarm_out_dir='[SWARM_OUT_DIR]') +
Ravi Mistry9bcca6a2016-11-21 16:06:19 -0500166 api.path.exists(api.path['start_dir'].join('skp_output')) +
borenetb2cf2662016-10-24 08:40:26 -0700167 api.step_data('Upload SKPs', retcode=1)
168 )