blob: f0f05873a72d6ba653dba5602476cdd9a95301b6 [file] [log] [blame]
Ravi Mistryedc4f3e2017-12-08 12:58:20 -05001# Copyright 2017 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# Recipe which:
6# 1) Extracts all fiddles out of markdown files.
7# 2) Forces fiddle.skia.org to compile all those fiddles and get output in JSON.
8# 3) Scans the output and reports any compiletime/runtime errors.
9# 4) Updates markdown in site/user/api/ using the new hashes (if any) from
10# fiddle.skia.org.
11
12import json
13
14
15DEPS = [
16 'recipe_engine/context',
17 'recipe_engine/file',
18 'recipe_engine/path',
19 'recipe_engine/properties',
20 'recipe_engine/step',
21 'core',
22 'infra',
23 'run',
24 'vars',
25]
26
27UPDATE_DOCS_GITCOOKIES_FILE = 'update_docs.git_cookies'
28UPDATE_DOCS_GITCOOKIES_GS_PATH = (
29 'gs://skia-buildbots/artifacts/server/.gitcookies_update-docs')
30
31
32def go_get_fiddlecli(api):
33 env = api.context.env
34 env.update(api.infra.go_env)
35 with api.context(env=env):
36 api.run.with_retry(
37 api.step,
38 'go get fiddlecli',
39 5, # Update attempts.
40 cmd=[api.infra.go_exe, 'get', '-u', '-t',
41 'go.skia.org/infra/fiddle/go/fiddlecli'])
42
43
44def RunSteps(api):
45 api.vars.setup()
Eric Boren86a11462018-02-22 10:03:56 -050046 api.core.checkout_bot_update()
Ravi Mistryedc4f3e2017-12-08 12:58:20 -050047 api.infra.go_version()
48 go_get_fiddlecli(api)
49
50 with api.context(cwd=api.vars.skia_dir, env=api.infra.go_env):
51 bookmaker_binary = api.path.join(api.vars.skia_out, api.vars.configuration,
52 'bookmaker')
Ravi Mistryd4731e92018-01-02 14:54:43 -050053 buildername = api.vars.builder_name
Ravi Mistryedc4f3e2017-12-08 12:58:20 -050054
Ravi Mistryd4731e92018-01-02 14:54:43 -050055 if 'PerCommit' in buildername:
56 # Check to see if docs matches include/core.
57 cmd = [bookmaker_binary,
58 '-a', 'docs/status.json', # File containing status of docs.
59 '-x', # Check bmh against includes.
60 ]
61 try:
62 api.run(api.step, 'Validate docs match include/core/*.h', cmd=cmd)
63 except api.step.StepFailure as e:
64 # Display what needs to be fixed.
65 e.reason += (
66 '\n\nView the output of the "Validate docs match include/core/*.h" '
67 'step to see how to get this bot green.'
68 '\n\nhttps://skia.org/user/api/usingBookmaker details how to build '
69 'and run the bookmaker utility locally if needed.')
70 raise e
Ravi Mistryedc4f3e2017-12-08 12:58:20 -050071
Ravi Mistryd4731e92018-01-02 14:54:43 -050072 elif 'Nightly' in buildername:
73 fiddlecli_binary = api.path.join(api.infra.gopath, 'bin', 'fiddlecli')
74 fiddlecli_input = api.path.join(api.path['start_dir'], 'fiddle.json')
75 fiddlecli_output = api.path.join(api.path['start_dir'], 'fiddleout.json')
Ravi Mistryedc4f3e2017-12-08 12:58:20 -050076
Ravi Mistryd4731e92018-01-02 14:54:43 -050077 # Step 1: Extract all fiddles out of markdown files.
78 cmd = [bookmaker_binary,
79 '-a', 'docs/status.json', # File containing status of docs.
80 '-e', fiddlecli_input, # Fiddle cli input.
81 ]
82 api.run(api.step, 'Extract all fiddles out of md files', cmd=cmd)
Ravi Mistry5ca94132017-12-11 16:40:48 -050083
Ravi Mistryd4731e92018-01-02 14:54:43 -050084 # Step 2: Forces fiddle.skia.org to compile all fiddles extracted out of
85 # markdown files and get output in JSON.
86 cmd = [fiddlecli_binary,
87 '--input', fiddlecli_input,
88 '--output', fiddlecli_output,
89 '--logtostderr',
90 '--force',
91 ]
92 api.run(api.step, 'Force fiddle to compile all examples', cmd=cmd)
Ravi Mistryedc4f3e2017-12-08 12:58:20 -050093
Ravi Mistryd4731e92018-01-02 14:54:43 -050094 # Step 3: Scan the output of fiddlecli for any compiletime/runtime errors.
95 # Fail the recipe is there are any errors and summarize results at
96 # the end.
97 if api.path.exists(fiddlecli_output):
98 test_data = api.properties.get('fiddleout_test_data', '{}')
99 content = api.file.read_text('Read fiddleout.json',
100 fiddlecli_output, test_data=test_data)
101 out = json.loads(content)
Ravi Mistryd4731e92018-01-02 14:54:43 -0500102
Ravi Mistrybcc00b22018-03-15 16:55:16 -0400103 # Output fiddleout.json for easy debugging.
104 api.run(api.step, 'Output fiddleout.json',
105 cmd=['cat', fiddlecli_output])
106
Ravi Mistry042b5e92018-02-08 14:54:52 -0500107 failing_fiddles_to_errors = {}
Ravi Mistryd4731e92018-01-02 14:54:43 -0500108 for fiddle_name in out:
109 props = out[fiddle_name]
110 if props['compile_errors'] or props['runtime_error']:
Ravi Mistry042b5e92018-02-08 14:54:52 -0500111 # Construct the error.
112 error = props['runtime_error']
113 if props['compile_errors']:
114 for e in props['compile_errors']:
115 error += '%s\n' % e['text']
116 failing_fiddles_to_errors[props['fiddleHash']] = error
117
118 if failing_fiddles_to_errors:
Ravi Mistryd4731e92018-01-02 14:54:43 -0500119 # create an eror message and fail the bot!
Ravi Mistry042b5e92018-02-08 14:54:52 -0500120 failure_msg = 'Failed fiddles with their errors:\n\n\n'
121 counter = 0
122 for fiddle_hash, error in failing_fiddles_to_errors.iteritems():
123 counter += 1
124 failure_msg += '%d. https://fiddle.skia.org/c/%s\n\n' % (
125 counter, fiddle_hash)
126 failure_msg += '%s\n\n' % error
Ravi Mistryd4731e92018-01-02 14:54:43 -0500127 raise api.step.StepFailure(failure_msg)
128
129 # Step 4: Update docs in site/user/api/ with the output of fiddlecli.
130 # If there are any new changes then upload and commit the changes.
131 update_docs_gitcookies = api.path['start_dir'].join(
132 UPDATE_DOCS_GITCOOKIES_FILE)
133 cmd = ['python',
134 api.vars.skia_dir.join('infra', 'bots', 'upload_md.py'),
135 '--bookmaker_binary', bookmaker_binary,
136 '--fiddlecli_output', fiddlecli_output,
137 '--gitcookies', str(update_docs_gitcookies)]
138 with api.infra.DownloadGitCookies(
139 UPDATE_DOCS_GITCOOKIES_GS_PATH, update_docs_gitcookies, api):
140 with api.context(cwd=api.vars.skia_dir, env=api.infra.go_env):
141 api.run(api.step, 'Generate and Upload Markdown files', cmd=cmd)
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500142
143
144def GenTests(api):
145 fiddleout_no_errors_test_data = """
146{"fiddle1": {"fiddleHash": "abc",
147 "compile_errors": [],
148 "runtime_error": ""}}
149"""
150 fiddleout_with_errors_test_data = """
151{"fiddle1": {"fiddleHash": "abc",
Ravi Mistry042b5e92018-02-08 14:54:52 -0500152 "compile_errors": [
153 {
154 "text": "ninja: Entering directory `out/Release'",
155 "line": 0,
156 "col": 0
157 },
158 {
159 "text": "[1/7] ACTION //:skia.h(//gn/toolchain:gcc_like)",
160 "line": 0,
161 "col": 0
162 },
163 {
164 "text": "[2/7] stamp obj/skia.h.stamp",
165 "line": 0,
166 "col": 0
167 },
168 {
169 "text": "[3/7] compile ../../tools/fiddle/draw.cpp",
170 "line": 0,
171 "col": 0
172 },
173 {
174 "text": "FAILED: obj/tools/fiddle/fiddle.draw.o ",
175 "line": 0,
176 "col": 0
177 },
178 {
179 "text": "c++ -MMD -MF obj/tools/fiddle/fiddle.draw.o.d -DNDEBUG -DSK_HAS_HEIF_LIBRARY -DSK_HAS_JPEG_LIBRARY -DSK_SUPPORT_PDF -DSK_PDF_USE_SFNTLY -DSK_HAS_PNG_LIBRARY -DSK_CODEC_DECODES_RAW -DSK_HAS_WEBP_LIBRARY -DSK_XML -DSK_GAMMA_APPLY_TO_A8 -DSK_ENABLE_DISCRETE_GPU -DGR_TEST_UTILS=1 -DSK_SAMPLES_FOR_X -DSK_SUPPORT_ATLAS_TEXT=1 -I../../tools/flags -I../../include/private -I../../src/c -I../../src/codec -I../../src/core -I../../src/effects -I../../src/fonts -I../../src/image -I../../src/images -I../../src/lazy -I../../src/opts -I../../src/pathops -I../../src/pdf -I../../src/ports -I../../src/sfnt -I../../src/shaders -I../../src/shaders/gradients -I../../src/sksl -I../../src/utils -I../../src/utils/win -I../../src/xml -I../../third_party/gif -I../../src/gpu -I../../tools/gpu -I../../include/android -I../../include/c -I../../include/codec -I../../include/config -I../../include/core -I../../include/effects -I../../include/encode -I../../include/gpu -I../../include/gpu/gl -I../../include/atlastext -I../../include/pathops -I../../include/ports -I../../include/svg -I../../include/utils -I../../include/utils/mac -I../../include/atlastext -Igen -fstrict-aliasing -fPIC -Werror -Wall -Wextra -Winit-self -Wpointer-arith -Wsign-compare -Wvla -Wno-deprecated-declarations -Wno-maybe-uninitialized -Wno-unused-parameter -O3 -fdata-sections -ffunction-sections -g -std=c++11 -fno-exceptions -fno-rtti -Wnon-virtual-dtor -Wno-error -c ../../tools/fiddle/draw.cpp -o obj/tools/fiddle/fiddle.draw.o",
180 "line": 0,
181 "col": 0
182 },
183 {
184 "text": "../../tools/fiddle/draw.cpp: In function 'void draw(SkCanvas*)':",
185 "line": 0,
186 "col": 0
187 },
188 {
189 "text": "draw.cpp:5:12: error: aggregate 'SkMask mask' has incomplete type and cannot be defined",
190 "line": 5,
191 "col": 12
192 },
193 {
194 "text": " }",
195 "line": 0,
196 "col": 0
197 },
198 {
199 "text": " ^ ",
200 "line": 0,
201 "col": 0
202 },
203 {
204 "text": "draw.cpp:6:28: error: incomplete type 'SkMask' used in nested name specifier",
205 "line": 6,
206 "col": 28
207 },
208 {
209 "text": " ",
210 "line": 0,
211 "col": 0
212 },
213 {
214 "text": " ^ ",
215 "line": 0,
216 "col": 0
217 },
218 {
219 "text": "draw.cpp:14:28: error: incomplete type 'SkMask' used in nested name specifier",
220 "line": 14,
221 "col": 28
222 },
223 {
224 "text": " uint8_t bytes[] = { 0, 1, 2, 3, 4, 5, 6, 7 };",
225 "line": 0,
226 "col": 0
227 },
228 {
229 "text": " ^~~~~~~~~~",
230 "line": 0,
231 "col": 0
232 },
233 {
234 "text": "[4/7] compile ../../tools/fiddle/egl_context.cpp",
235 "line": 0,
236 "col": 0
237 },
238 {
239 "text": "[5/7] compile ../../tools/fiddle/fiddle_main.cpp",
240 "line": 0,
241 "col": 0
242 },
243 {
244 "text": "[6/7] link libskia.a",
245 "line": 0,
246 "col": 0
247 },
248 {
249 "text": "ninja: build stopped: subcommand failed.",
250 "line": 0,
251 "col": 0
252 },
253 {
254 "text": "",
255 "line": 0,
256 "col": 0
257 }
258 ],
259 "runtime_error": ""}}
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500260"""
261 yield (
Ravi Mistryd4731e92018-01-02 14:54:43 -0500262 api.test('percommit_bookmaker') +
263 api.properties(buildername='Housekeeper-PerCommit-Bookmaker',
264 repository='https://skia.googlesource.com/skia.git',
265 revision='abc123',
266 path_config='kitchen',
267 swarm_out_dir='[SWARM_OUT_DIR]')
268 )
269
270 yield (
271 api.test('percommit_failed_validation') +
272 api.properties(buildername='Housekeeper-PerCommit-Bookmaker',
273 repository='https://skia.googlesource.com/skia.git',
274 revision='abc123',
275 path_config='kitchen',
276 swarm_out_dir='[SWARM_OUT_DIR]') +
277 api.step_data('Validate docs match include/core/*.h', retcode=1)
278 )
279
280 yield (
281 api.test('nightly_bookmaker') +
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500282 api.properties(buildername='Housekeeper-Nightly-Bookmaker',
283 repository='https://skia.googlesource.com/skia.git',
284 revision='abc123',
285 path_config='kitchen',
286 fiddleout_test_data=fiddleout_no_errors_test_data,
287 swarm_out_dir='[SWARM_OUT_DIR]') +
288 api.path.exists(api.path['start_dir'].join('fiddleout.json'),
289 api.path['start_dir'].join(UPDATE_DOCS_GITCOOKIES_FILE))
290 )
291
292 yield (
Ravi Mistryd4731e92018-01-02 14:54:43 -0500293 api.test('nightly_failed_fiddles') +
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500294 api.properties(buildername='Housekeeper-Nightly-Bookmaker',
295 repository='https://skia.googlesource.com/skia.git',
296 revision='abc123',
297 path_config='kitchen',
298 fiddleout_test_data=fiddleout_with_errors_test_data,
299 swarm_out_dir='[SWARM_OUT_DIR]') +
300 api.path.exists(api.path['start_dir'].join('fiddleout.json'))
301 )
302
303 yield (
Ravi Mistryd4731e92018-01-02 14:54:43 -0500304 api.test('nightly_failed_extract_fiddles') +
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500305 api.properties(buildername='Housekeeper-Nightly-Bookmaker',
306 repository='https://skia.googlesource.com/skia.git',
307 revision='abc123',
308 path_config='kitchen',
309 swarm_out_dir='[SWARM_OUT_DIR]') +
310 api.step_data('Extract all fiddles out of md files', retcode=1)
311 )
312
313 yield (
Ravi Mistryd4731e92018-01-02 14:54:43 -0500314 api.test('nightly_failed_fiddlecli') +
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500315 api.properties(buildername='Housekeeper-Nightly-Bookmaker',
316 repository='https://skia.googlesource.com/skia.git',
317 revision='abc123',
318 path_config='kitchen',
319 swarm_out_dir='[SWARM_OUT_DIR]') +
320 api.step_data('Force fiddle to compile all examples', retcode=1)
321 )
322
323 yield (
Ravi Mistryd4731e92018-01-02 14:54:43 -0500324 api.test('nightly_failed_upload') +
Ravi Mistryedc4f3e2017-12-08 12:58:20 -0500325 api.properties(buildername='Housekeeper-Nightly-Bookmaker',
326 repository='https://skia.googlesource.com/skia.git',
327 revision='abc123',
328 path_config='kitchen',
329 swarm_out_dir='[SWARM_OUT_DIR]') +
330 api.step_data('Generate and Upload Markdown files', retcode=1)
331 )