• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 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 module for Skia Swarming compile.
7
8PYTHON_VERSION_COMPATIBILITY = "PY3"
9
10DEPS = [
11  'build',
12  'checkout',
13  'recipe_engine/context',
14  'recipe_engine/file',
15  'recipe_engine/json',
16  'recipe_engine/path',
17  'recipe_engine/platform',
18  'recipe_engine/properties',
19  'recipe_engine/python',
20  'recipe_engine/step',
21  'depot_tools/gitiles',
22  'run',
23  'vars',
24]
25
26
27def RunSteps(api):
28  api.vars.setup()
29
30  # Check out code.
31  bot_update = True
32  checkout_root = api.checkout.default_checkout_root
33  skip_patch = False
34  revision = api.properties['revision']
35
36  if 'NoDEPS' in api.properties['buildername']:
37    bot_update = False
38    checkout_root = api.path['start_dir']
39  if 'NoPatch' in api.vars.builder_name:
40    skip_patch = True
41    checkout_root = api.path['start_dir']
42
43    # If we are running on the CI (post submit), we want to do a diff with the
44    # previous commit. To do this, we use gitiles to look up the current
45    # git revision, and find its parent. In the unlikely event of there being
46    # multiple parents, we pick the first one arbitrarily.
47    if not api.vars.is_trybot:
48      # Fetches something like
49      # https://skia.googlesource.com/skia.git/+log/b44572fbfeb669998053b023f473b9c274f2f2cf?format=JSON
50      #
51      # https://chromium.googlesource.com/chromium/tools/depot_tools/+/dca14bc463857bd2a0fee59c86ffa289b535d5d3/recipes/recipe_modules/gitiles/api.py#75
52      response, _ = api.gitiles.log(
53        url = api.properties['repository'],
54        ref = api.properties['revision'],
55        limit = 1)
56      # Response looks like:
57      #     [{
58      #        'parents': ['<githash>'],
59      #        ...
60      #     }]
61      revision  = response[0]['parents'][0]
62
63  if bot_update:
64    api.checkout.bot_update(
65        checkout_root=checkout_root,
66        skip_patch=skip_patch,
67        override_revision=revision)
68
69    if 'NoPatch' in api.vars.builder_name:
70      # The CodeSize-* family of tasks compute size diffs between the binaries produced by
71      # Build-<CONFIG>-NoPatch tasks and those produced by Build-<CONFIG> tasks. Some debug strings
72      # in said binaries might contain relative paths from the output directory to the sources
73      # directory (e.g. "../../../dm/DM.cpp"). In order to prevent spurious deltas, we must make
74      # the Build-<CONFIG>-NoPatch tasks match the paths used by Build-<CONFIG> tasks. For example,
75      # Build-<CONFIG> tasks place the Skia checkout at /mnt/pd0/s/w/ir/skia, so
76      # Build-<CONFIG>-NoPatch tasks must do the same.
77      #
78      # For some reason api.checkout.bot_update places the Skia checkout at /mnt/pd0/s/w/ir/k
79      # even though we specified /mnt/pd0/s/w/ir as the checkout root. As a workaround, we manually
80      # copy the Skia checkout to the intended location.
81      #
82      # An inline Python script is necessary here because api.file.copytree[1] does not pipe
83      # through the dirs_exist_ok argument to the underlying shutil.copytree[2] call.
84      #
85      # [1] https://chromium.googlesource.com/infra/luci/recipes-py.git/+/cfdb92cc6933d8f72c2340233ba03b602b447507/recipe_modules/file/api.py#146
86      # [2] https://docs.python.org/3/library/shutil.html#shutil.copytree
87      src = api.path['start_dir'].join('k', 'skia')
88      dst = api.path['start_dir'].join('skia')
89      api.python.inline(
90          name='copy Skia repository checkout from %s to %s' % (src, dst),
91          program='''
92import shutil
93import sys
94shutil.copytree(sys.argv[1], sys.argv[2], dirs_exist_ok=True)
95''',
96          args=[src, dst])
97      api.file.rmtree('remove %s' % src, src)
98
99  else:
100    api.checkout.git(checkout_root=checkout_root)
101
102  api.file.ensure_directory('makedirs tmp_dir', api.vars.tmp_dir)
103
104  out_dir = checkout_root.join(
105      'skia', 'out', api.vars.builder_name, api.vars.configuration)
106  if 'NoPatch' in api.vars.builder_name:
107    # Similarly as with the checkout root, we use the same output directory in
108    # Build-<CONFIG>-NoPatch tasks as we do on Build-<CONFIG> tasks to prevent spurious deltas.
109    out_dir = api.vars.cache_dir.join(
110      'work', 'skia', 'out', api.vars.builder_name, api.vars.configuration)
111
112  try:
113    api.build(checkout_root=checkout_root, out_dir=out_dir)
114
115    # TODO(borenet): Move this out of the try/finally.
116    dst = api.vars.swarming_out_dir
117    api.build.copy_build_products(out_dir=out_dir, dst=dst)
118  finally:
119    if 'Win' in api.vars.builder_cfg.get('os', ''):
120      api.python.inline(
121          name='cleanup',
122          program='''
123# [VPYTHON:BEGIN]
124# wheel: <
125#  name: "infra/python/wheels/psutil/${vpython_platform}"
126#  version: "version:5.4.7"
127# >
128# [VPYTHON:END]
129
130import psutil
131for p in psutil.process_iter():
132  try:
133    if p.name in ('mspdbsrv.exe', 'vctip.exe', 'cl.exe', 'link.exe'):
134      p.kill()
135  except psutil._error.AccessDenied:
136    pass
137''',
138          infra_step=True,
139          venv=True)
140
141  api.run.check_failure()
142
143
144def GenTests(api):
145  yield (
146      api.test('Build-Win10-Clang-x86_64-Release-NoDEPS') +
147      api.properties(buildername='Build-Win10-Clang-x86_64-Release-NoDEPS',
148                     repository='https://skia.googlesource.com/skia.git',
149                     revision='abc123',
150                     path_config='kitchen',
151                     swarm_out_dir='[SWARM_OUT_DIR]') +
152      api.platform('win', 64)
153  )
154
155  yield (
156      # git revisions based off of real data
157      api.test('Build-Debian10-Clang-arm-Release-NoPatch') +
158      api.properties(buildername='Build-Debian10-Clang-arm-Release-NoPatch',
159                     repository='https://skia.googlesource.com/skia.git',
160                     revision='b44572fbfeb669998053b023f473b9c274f2f2cf',
161                     path_config='kitchen',
162                     swarm_out_dir='[SWARM_OUT_DIR]') +
163      # This tells recipes to use this fake data for a step with the given
164      # name. Inspired by
165      # https://chromium.googlesource.com/chromium/tools/depot_tools/+/dca14bc463857bd2a0fee59c86ffa289b535d5d3/recipes/recipe_modules/gitiles/examples/full.py#62
166      # Even though we use the commit 6e0e0... as the "seed string", the actual
167      # commit (and parent commit) returned from make_log_test_data is
168      # different. Mocked commit is 188e23c7abc4b205f0f80fb345ff63ec5b716be8
169      # and parent commit is d2231a340fd47b47d61d0f99a188e46e6aabba0a
170      api.step_data(
171          'gitiles log: b44572fbfeb669998053b023f473b9c274f2f2cf',
172          api.gitiles.make_log_test_data('6e0e0a9f6cbf09078aa4730d1a0dc0aa722ddc11'),
173      )
174    )
175
176  yield (
177      api.test('Build-Debian10-Clang-arm-Release-NoPatch (tryjob)') +
178      api.properties(buildername='Build-Debian10-Clang-arm-Release-NoPatch',
179                     repository='https://skia.googlesource.com/skia.git',
180                     revision='abc123',
181                     path_config='kitchen',
182                     swarm_out_dir='[SWARM_OUT_DIR]',
183                     patch_issue=123,
184                     patch_set=123,
185                     patch_ref=123)
186    )
187
188