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 | 7e97dc0 | 2017-02-02 09:02:37 -0500 | [diff] [blame] | 17 | 'core', |
| 18 | 'infra', |
Eric Boren | 81340c6 | 2017-04-17 10:29:04 -0400 | [diff] [blame^] | 19 | 'run', |
Eric Boren | 7e97dc0 | 2017-02-02 09:02:37 -0500 | [diff] [blame] | 20 | 'vars', |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 21 | ] |
| 22 | |
| 23 | |
| 24 | TEST_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 Mistry | badc137 | 2016-11-23 08:38:18 -0500 | [diff] [blame] | 34 | UPDATE_SKPS_GITCOOKIES_FILE = 'update_skps.git_cookies' |
| 35 | UPDATE_SKPS_KEY = 'update_skps_git_cookies' |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 36 | |
| 37 | |
Ravi Mistry | badc137 | 2016-11-23 08:38:18 -0500 | [diff] [blame] | 38 | class gitcookies_auth(object): |
| 39 | """Download update-skps@skia.org's .gitcookies.""" |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 40 | 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 Mistry | badc137 | 2016-11-23 08:38:18 -0500 | [diff] [blame] | 46 | 'download update-skps.gitcookies', |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 47 | """ |
| 48 | import os |
| 49 | import urllib2 |
| 50 | |
| 51 | TOKEN_FILE = '%s' |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 52 | TOKEN_URL = 'http://metadata/computeMetadata/v1/project/attributes/%s' |
| 53 | |
| 54 | req = urllib2.Request(TOKEN_URL, headers={'Metadata-Flavor': 'Google'}) |
| 55 | contents = urllib2.urlopen(req).read() |
| 56 | |
| 57 | home = os.path.expanduser('~') |
| 58 | token_file = os.path.join(home, TOKEN_FILE) |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 59 | |
| 60 | with open(token_file, 'w') as f: |
| 61 | f.write(contents) |
Ravi Mistry | badc137 | 2016-11-23 08:38:18 -0500 | [diff] [blame] | 62 | """ % (UPDATE_SKPS_GITCOOKIES_FILE, |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 63 | self._key), |
| 64 | ) |
| 65 | |
| 66 | def __exit__(self, t, v, tb): |
borenet | b2cf266 | 2016-10-24 08:40:26 -0700 | [diff] [blame] | 67 | self.m.python.inline( |
Ravi Mistry | badc137 | 2016-11-23 08:38:18 -0500 | [diff] [blame] | 68 | 'cleanup update-skps.gitcookies', |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 69 | """ |
| 70 | import os |
| 71 | |
| 72 | |
| 73 | TOKEN_FILE = '%s' |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 74 | |
| 75 | |
| 76 | home = os.path.expanduser('~') |
| 77 | token_file = os.path.join(home, TOKEN_FILE) |
| 78 | if os.path.isfile(token_file): |
| 79 | os.remove(token_file) |
Ravi Mistry | badc137 | 2016-11-23 08:38:18 -0500 | [diff] [blame] | 80 | """ % (UPDATE_SKPS_GITCOOKIES_FILE), |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 81 | ) |
borenet | b2cf266 | 2016-10-24 08:40:26 -0700 | [diff] [blame] | 82 | return v is None |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 83 | |
| 84 | |
| 85 | def RunSteps(api): |
| 86 | # Check out Chrome. |
borenet | 1436a09 | 2016-08-03 08:23:10 -0700 | [diff] [blame] | 87 | api.core.setup() |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 88 | |
borenet | 1436a09 | 2016-08-03 08:23:10 -0700 | [diff] [blame] | 89 | src_dir = api.vars.checkout_root.join('src') |
borenet | b6aafe6 | 2016-08-02 07:02:52 -0700 | [diff] [blame] | 90 | out_dir = src_dir.join('out', 'Release') |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 91 | |
Eric Boren | e6b26ad | 2017-02-21 07:22:20 -0500 | [diff] [blame] | 92 | 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 Boren | 53262d0 | 2017-03-20 15:40:12 -0400 | [diff] [blame] | 96 | gn_env = {'CPPFLAGS': '-DSK_ALLOW_CROSSPROCESS_PICTUREIMAGEFILTERS=1', |
| 97 | 'GYP_GENERATORS': 'ninja'} |
| 98 | with api.step.context({'env': gn_env}): |
Eric Boren | 81340c6 | 2017-04-17 10:29:04 -0400 | [diff] [blame^] | 99 | api.run(api.step, 'GN', cmd=[gn, 'gen', out_dir]) |
Eric Boren | e6b26ad | 2017-02-21 07:22:20 -0500 | [diff] [blame] | 100 | |
| 101 | # Build Chrome. |
Eric Boren | 81340c6 | 2017-04-17 10:29:04 -0400 | [diff] [blame^] | 102 | api.run(api.step, 'Build Chrome', cmd=['ninja', '-C', out_dir, 'chrome']) |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 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. |
borenet | 1436a09 | 2016-08-03 08:23:10 -0700 | [diff] [blame] | 111 | asset_dir = api.vars.infrabots_dir.join('assets', 'skp') |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 112 | 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 Boren | 81340c6 | 2017-04-17 10:29:04 -0400 | [diff] [blame^] | 118 | with api.step.context({'cwd': api.vars.skia_dir}): |
| 119 | api.run(api.step, 'Recreate SKPs', cmd=cmd) |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 120 | |
| 121 | # Upload the SKPs. |
| 122 | if 'Canary' not in api.properties['buildername']: |
borenet | 09732a6 | 2016-10-24 06:36:30 -0700 | [diff] [blame] | 123 | api.infra.update_go_deps() |
Ravi Mistry | badc137 | 2016-11-23 08:38:18 -0500 | [diff] [blame] | 124 | update_skps_gitcookies = api.path.join(api.path.expanduser('~'), |
| 125 | UPDATE_SKPS_GITCOOKIES_FILE) |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 126 | cmd = ['python', |
borenet | 1436a09 | 2016-08-03 08:23:10 -0700 | [diff] [blame] | 127 | api.vars.skia_dir.join('infra', 'bots', 'upload_skps.py'), |
Ravi Mistry | badc137 | 2016-11-23 08:38:18 -0500 | [diff] [blame] | 128 | '--target_dir', output_dir, |
| 129 | '--gitcookies', str(update_skps_gitcookies)] |
Ravi Mistry | badc137 | 2016-11-23 08:38:18 -0500 | [diff] [blame] | 130 | with gitcookies_auth(api, UPDATE_SKPS_KEY): |
Eric Boren | 81340c6 | 2017-04-17 10:29:04 -0400 | [diff] [blame^] | 131 | with api.step.context({'cwd': api.vars.skia_dir, |
| 132 | 'env': api.infra.go_env}): |
| 133 | api.run(api.step, 'Upload SKPs', cmd=cmd) |
borenet | 1ed2ae4 | 2016-07-26 11:52:17 -0700 | [diff] [blame] | 134 | |
| 135 | |
| 136 | def GenTests(api): |
borenet | b2cf266 | 2016-10-24 08:40:26 -0700 | [diff] [blame] | 137 | builder = 'Housekeeper-Nightly-RecreateSKPs_Canary' |
| 138 | yield ( |
| 139 | api.test(builder) + |
| 140 | api.properties(buildername=builder, |
Eric Boren | ad29aee | 2017-01-17 14:35:06 -0500 | [diff] [blame] | 141 | repository='https://skia.googlesource.com/skia.git', |
borenet | b2cf266 | 2016-10-24 08:40:26 -0700 | [diff] [blame] | 142 | revision='abc123', |
borenet | b2cf266 | 2016-10-24 08:40:26 -0700 | [diff] [blame] | 143 | path_config='kitchen', |
| 144 | swarm_out_dir='[SWARM_OUT_DIR]') + |
Ravi Mistry | 9bcca6a | 2016-11-21 16:06:19 -0500 | [diff] [blame] | 145 | api.path.exists(api.path['start_dir'].join('skp_output')) |
borenet | b2cf266 | 2016-10-24 08:40:26 -0700 | [diff] [blame] | 146 | ) |
| 147 | |
| 148 | builder = 'Housekeeper-Weekly-RecreateSKPs' |
| 149 | yield ( |
| 150 | api.test(builder) + |
| 151 | api.properties(buildername=builder, |
Eric Boren | ad29aee | 2017-01-17 14:35:06 -0500 | [diff] [blame] | 152 | repository='https://skia.googlesource.com/skia.git', |
borenet | b2cf266 | 2016-10-24 08:40:26 -0700 | [diff] [blame] | 153 | revision='abc123', |
borenet | b2cf266 | 2016-10-24 08:40:26 -0700 | [diff] [blame] | 154 | path_config='kitchen', |
| 155 | swarm_out_dir='[SWARM_OUT_DIR]') + |
Ravi Mistry | 9bcca6a | 2016-11-21 16:06:19 -0500 | [diff] [blame] | 156 | api.path.exists(api.path['start_dir'].join('skp_output')) |
borenet | b2cf266 | 2016-10-24 08:40:26 -0700 | [diff] [blame] | 157 | ) |
| 158 | |
| 159 | yield ( |
| 160 | api.test('failed_upload') + |
| 161 | api.properties(buildername=builder, |
Eric Boren | ad29aee | 2017-01-17 14:35:06 -0500 | [diff] [blame] | 162 | repository='https://skia.googlesource.com/skia.git', |
borenet | b2cf266 | 2016-10-24 08:40:26 -0700 | [diff] [blame] | 163 | revision='abc123', |
borenet | b2cf266 | 2016-10-24 08:40:26 -0700 | [diff] [blame] | 164 | path_config='kitchen', |
| 165 | swarm_out_dir='[SWARM_OUT_DIR]') + |
Ravi Mistry | 9bcca6a | 2016-11-21 16:06:19 -0500 | [diff] [blame] | 166 | api.path.exists(api.path['start_dir'].join('skp_output')) + |
borenet | b2cf266 | 2016-10-24 08:40:26 -0700 | [diff] [blame] | 167 | api.step_data('Upload SKPs', retcode=1) |
| 168 | ) |