Debian Codegraph @

infra/bots/recipes/sync_and_compile.py

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