• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
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',
17  'core',
18  'infra',
19  'vars',
20]
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
33UPDATE_SKPS_GITCOOKIES_FILE = 'update_skps.git_cookies'
34UPDATE_SKPS_KEY = 'update_skps_git_cookies'
35
36
37class gitcookies_auth(object):
38  """Download update-skps@skia.org's .gitcookies."""
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(
45        'download update-skps.gitcookies',
46        """
47import os
48import urllib2
49
50TOKEN_FILE = '%s'
51TOKEN_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)
58
59with open(token_file, 'w') as f:
60  f.write(contents)
61        """ % (UPDATE_SKPS_GITCOOKIES_FILE,
62               self._key),
63    )
64
65  def __exit__(self, t, v, tb):
66    self.m.python.inline(
67        'cleanup update-skps.gitcookies',
68        """
69import os
70
71
72TOKEN_FILE = '%s'
73
74
75home = os.path.expanduser('~')
76token_file = os.path.join(home, TOKEN_FILE)
77if os.path.isfile(token_file):
78  os.remove(token_file)
79        """ % (UPDATE_SKPS_GITCOOKIES_FILE),
80    )
81    return v is None
82
83
84def RunSteps(api):
85  # Check out Chrome.
86  api.core.setup()
87
88  src_dir = api.vars.checkout_root.join('src')
89  out_dir = src_dir.join('out', 'Release')
90
91  with api.step.context({'cwd': src_dir}):
92    # Call GN.
93    platform = 'linux64'  # This bot only runs on linux; don't bother checking.
94    gn = src_dir.join('buildtools', platform, 'gn')
95    gn_env = {'CPPFLAGS': '-DSK_ALLOW_CROSSPROCESS_PICTUREIMAGEFILTERS=1',
96              'GYP_GENERATORS': 'ninja'}
97    with api.step.context({'env': gn_env}):
98      api.step('GN', [gn, 'gen', out_dir])
99
100    # Build Chrome.
101    api.step('Build Chrome', ['ninja', '-C', out_dir, 'chrome'])
102
103  # Clean up the output dir.
104  output_dir = api.path['start_dir'].join('skp_output')
105  if api.path.exists(output_dir):
106    api.file.rmtree('skp_output', output_dir)
107  api.file.makedirs('skp_output', output_dir)
108
109  # Capture the SKPs.
110  path_var= api.path.pathsep.join([str(api.path['depot_tools']), '%(PATH)s'])
111  env = {
112      'CHROME_HEADLESS': '1',
113      'PATH': path_var,
114  }
115  asset_dir = api.vars.infrabots_dir.join('assets', 'skp')
116  cmd = ['python', asset_dir.join('create.py'),
117         '--chrome_src_path', src_dir,
118         '--browser_executable', src_dir.join('out', 'Release', 'chrome'),
119         '--target_dir', output_dir]
120  if 'Canary' not in api.properties['buildername']:
121    cmd.append('--upload_to_partner_bucket')
122  with api.step.context({'cwd': api.vars.skia_dir, 'env': env}):
123    api.step('Recreate SKPs', cmd=cmd)
124
125  # Upload the SKPs.
126  if 'Canary' not in api.properties['buildername']:
127    api.infra.update_go_deps()
128    update_skps_gitcookies = api.path.join(api.path.expanduser('~'),
129                                           UPDATE_SKPS_GITCOOKIES_FILE)
130    cmd = ['python',
131           api.vars.skia_dir.join('infra', 'bots', 'upload_skps.py'),
132           '--target_dir', output_dir,
133           '--gitcookies', str(update_skps_gitcookies)]
134    env.update(api.infra.go_env)
135    with gitcookies_auth(api, UPDATE_SKPS_KEY):
136      with api.step.context({'cwd': api.vars.skia_dir, 'env': env}):
137        api.step('Upload SKPs', cmd=cmd)
138
139
140def GenTests(api):
141  mastername = 'client.skia.compile'
142  slavename = 'skiabot-linux-swarm-000'
143  builder = 'Housekeeper-Nightly-RecreateSKPs_Canary'
144  yield (
145      api.test(builder) +
146      api.properties(buildername=builder,
147                     mastername=mastername,
148                     slavename=slavename,
149                     repository='https://skia.googlesource.com/skia.git',
150                     revision='abc123',
151                     buildnumber=2,
152                     path_config='kitchen',
153                     swarm_out_dir='[SWARM_OUT_DIR]') +
154      api.path.exists(api.path['start_dir'].join('skp_output'))
155  )
156
157  builder = 'Housekeeper-Weekly-RecreateSKPs'
158  yield (
159      api.test(builder) +
160      api.properties(buildername=builder,
161                     mastername=mastername,
162                     slavename=slavename,
163                     repository='https://skia.googlesource.com/skia.git',
164                     revision='abc123',
165                     buildnumber=2,
166                     path_config='kitchen',
167                     swarm_out_dir='[SWARM_OUT_DIR]') +
168      api.path.exists(api.path['start_dir'].join('skp_output'))
169  )
170
171  yield (
172      api.test('failed_upload') +
173      api.properties(buildername=builder,
174                     mastername=mastername,
175                     slavename=slavename,
176                     repository='https://skia.googlesource.com/skia.git',
177                     revision='abc123',
178                     buildnumber=2,
179                     path_config='kitchen',
180                     swarm_out_dir='[SWARM_OUT_DIR]') +
181      api.path.exists(api.path['start_dir'].join('skp_output')) +
182      api.step_data('Upload SKPs', retcode=1)
183  )
184