borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 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', |
Eric Boren | 6441a46 | 2017-01-13 13:37:53 -0500 | [diff] [blame] | 17 | 'skia-recipes/core', |
| 18 | 'skia-recipes/infra', |
| 19 | 'skia-recipes/vars', |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 20 | ] |
| 21 | |
| 22 | |
| 23 | TEST_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 Mistry | badc137 | 2016-11-23 08:38:18 -0500 | [diff] [blame] | 33 | UPDATE_SKPS_GITCOOKIES_FILE = 'update_skps.git_cookies' |
| 34 | UPDATE_SKPS_KEY = 'update_skps_git_cookies' |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 35 | |
| 36 | |
Ravi Mistry | badc137 | 2016-11-23 08:38:18 -0500 | [diff] [blame] | 37 | class gitcookies_auth(object): |
| 38 | """Download update-skps@skia.org's .gitcookies.""" |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 39 | 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 Mistry | badc137 | 2016-11-23 08:38:18 -0500 | [diff] [blame] | 45 | 'download update-skps.gitcookies', |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 46 | """ |
| 47 | import os |
| 48 | import urllib2 |
| 49 | |
| 50 | TOKEN_FILE = '%s' |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 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) |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 58 | |
| 59 | with open(token_file, 'w') as f: |
| 60 | f.write(contents) |
Ravi Mistry | badc137 | 2016-11-23 08:38:18 -0500 | [diff] [blame] | 61 | """ % (UPDATE_SKPS_GITCOOKIES_FILE, |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 62 | self._key), |
| 63 | ) |
| 64 | |
| 65 | def __exit__(self, t, v, tb): |
borenet | b2cf266 | 2016-10-24 08:40:26 -0700 | [diff] [blame] | 66 | self.m.python.inline( |
Ravi Mistry | badc137 | 2016-11-23 08:38:18 -0500 | [diff] [blame] | 67 | 'cleanup update-skps.gitcookies', |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 68 | """ |
| 69 | import os |
| 70 | |
| 71 | |
| 72 | TOKEN_FILE = '%s' |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 73 | |
| 74 | |
| 75 | home = os.path.expanduser('~') |
| 76 | token_file = os.path.join(home, TOKEN_FILE) |
| 77 | if os.path.isfile(token_file): |
| 78 | os.remove(token_file) |
Ravi Mistry | badc137 | 2016-11-23 08:38:18 -0500 | [diff] [blame] | 79 | """ % (UPDATE_SKPS_GITCOOKIES_FILE), |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 80 | ) |
borenet | b2cf266 | 2016-10-24 08:40:26 -0700 | [diff] [blame] | 81 | return v is None |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 82 | |
| 83 | |
| 84 | def RunSteps(api): |
| 85 | # Check out Chrome. |
borenet | 1436a09 | 2016-08-03 08:23:10 -0700 | [diff] [blame] | 86 | api.core.setup() |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 87 | |
borenet | 1436a09 | 2016-08-03 08:23:10 -0700 | [diff] [blame] | 88 | src_dir = api.vars.checkout_root.join('src') |
borenet | b6aafe6 | 2016-08-02 07:02:52 -0700 | [diff] [blame] | 89 | out_dir = src_dir.join('out', 'Release') |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 90 | |
borenet | b6aafe6 | 2016-08-02 07:02:52 -0700 | [diff] [blame] | 91 | # 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], |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 96 | env={'CPPFLAGS': '-DSK_ALLOW_CROSSPROCESS_PICTUREIMAGEFILTERS=1', |
| 97 | 'GYP_GENERATORS': 'ninja'}, |
| 98 | cwd=src_dir) |
| 99 | # Build Chrome. |
| 100 | api.step('Build Chrome', |
borenet | b6aafe6 | 2016-08-02 07:02:52 -0700 | [diff] [blame] | 101 | ['ninja', '-C', out_dir, 'chrome'], |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 102 | cwd=src_dir) |
| 103 | |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 104 | # Clean up the output dir. |
Ravi Mistry | 9bcca6a | 2016-11-21 16:06:19 -0500 | [diff] [blame] | 105 | output_dir = api.path['start_dir'].join('skp_output') |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 106 | 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 | } |
borenet | 1436a09 | 2016-08-03 08:23:10 -0700 | [diff] [blame] | 116 | asset_dir = api.vars.infrabots_dir.join('assets', 'skp') |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 117 | 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, |
borenet | 1436a09 | 2016-08-03 08:23:10 -0700 | [diff] [blame] | 125 | cwd=api.vars.skia_dir, |
borenet | 76bcd4f | 2016-10-10 10:37:30 -0700 | [diff] [blame] | 126 | env=env) |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 127 | |
| 128 | # Upload the SKPs. |
| 129 | if 'Canary' not in api.properties['buildername']: |
borenet | 09732a6 | 2016-10-24 06:36:30 -0700 | [diff] [blame] | 130 | api.infra.update_go_deps() |
Ravi Mistry | badc137 | 2016-11-23 08:38:18 -0500 | [diff] [blame] | 131 | update_skps_gitcookies = api.path.join(api.path.expanduser('~'), |
| 132 | UPDATE_SKPS_GITCOOKIES_FILE) |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 133 | cmd = ['python', |
borenet | 1436a09 | 2016-08-03 08:23:10 -0700 | [diff] [blame] | 134 | api.vars.skia_dir.join('infra', 'bots', 'upload_skps.py'), |
Ravi Mistry | badc137 | 2016-11-23 08:38:18 -0500 | [diff] [blame] | 135 | '--target_dir', output_dir, |
| 136 | '--gitcookies', str(update_skps_gitcookies)] |
borenet | 09732a6 | 2016-10-24 06:36:30 -0700 | [diff] [blame] | 137 | env.update(api.infra.go_env) |
Ravi Mistry | badc137 | 2016-11-23 08:38:18 -0500 | [diff] [blame] | 138 | with gitcookies_auth(api, UPDATE_SKPS_KEY): |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 139 | api.step('Upload SKPs', |
| 140 | cmd=cmd, |
borenet | 1436a09 | 2016-08-03 08:23:10 -0700 | [diff] [blame] | 141 | cwd=api.vars.skia_dir, |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 142 | env=env) |
| 143 | |
| 144 | |
| 145 | def GenTests(api): |
borenet | b2cf266 | 2016-10-24 08:40:26 -0700 | [diff] [blame] | 146 | 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 Boren | ad29aee | 2017-01-17 14:35:06 -0500 | [diff] [blame^] | 154 | repository='https://skia.googlesource.com/skia.git', |
borenet | b2cf266 | 2016-10-24 08:40:26 -0700 | [diff] [blame] | 155 | revision='abc123', |
| 156 | buildnumber=2, |
| 157 | path_config='kitchen', |
| 158 | swarm_out_dir='[SWARM_OUT_DIR]') + |
Ravi Mistry | 9bcca6a | 2016-11-21 16:06:19 -0500 | [diff] [blame] | 159 | api.path.exists(api.path['start_dir'].join('skp_output')) |
borenet | b2cf266 | 2016-10-24 08:40:26 -0700 | [diff] [blame] | 160 | ) |
| 161 | |
| 162 | builder = 'Housekeeper-Weekly-RecreateSKPs' |
| 163 | yield ( |
| 164 | api.test(builder) + |
| 165 | api.properties(buildername=builder, |
| 166 | mastername=mastername, |
| 167 | slavename=slavename, |
Eric Boren | ad29aee | 2017-01-17 14:35:06 -0500 | [diff] [blame^] | 168 | repository='https://skia.googlesource.com/skia.git', |
borenet | b2cf266 | 2016-10-24 08:40:26 -0700 | [diff] [blame] | 169 | revision='abc123', |
| 170 | buildnumber=2, |
| 171 | path_config='kitchen', |
| 172 | swarm_out_dir='[SWARM_OUT_DIR]') + |
Ravi Mistry | 9bcca6a | 2016-11-21 16:06:19 -0500 | [diff] [blame] | 173 | api.path.exists(api.path['start_dir'].join('skp_output')) |
borenet | b2cf266 | 2016-10-24 08:40:26 -0700 | [diff] [blame] | 174 | ) |
| 175 | |
| 176 | yield ( |
| 177 | api.test('failed_upload') + |
| 178 | api.properties(buildername=builder, |
| 179 | mastername=mastername, |
| 180 | slavename=slavename, |
Eric Boren | ad29aee | 2017-01-17 14:35:06 -0500 | [diff] [blame^] | 181 | repository='https://skia.googlesource.com/skia.git', |
borenet | b2cf266 | 2016-10-24 08:40:26 -0700 | [diff] [blame] | 182 | revision='abc123', |
| 183 | buildnumber=2, |
| 184 | path_config='kitchen', |
| 185 | swarm_out_dir='[SWARM_OUT_DIR]') + |
Ravi Mistry | 9bcca6a | 2016-11-21 16:06:19 -0500 | [diff] [blame] | 186 | api.path.exists(api.path['start_dir'].join('skp_output')) + |
borenet | b2cf266 | 2016-10-24 08:40:26 -0700 | [diff] [blame] | 187 | api.step_data('Upload SKPs', retcode=1) |
| 188 | ) |